diff options
author | Li Xinwei <1326710505@qq.com> | 2021-05-27 19:41:43 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-06-02 08:25:04 +0000 |
commit | 4428f078e71cf3ff35dd9a36b64a43bde630b590 (patch) | |
tree | 882e9e90e726c9014fc2b0188be813708a6e9f42 /cmake/QtPrlHelpers.cmake | |
parent | a3b1f4e463da2d80c0d08859b0b9879e83e24e2a (diff) |
CMake: Fix generated prl and pri files for MSVC
In MSVC static build, if we build Qt with 3rdparty library (e.g. zstd),
cmake will add"zstd" (without "-l" prefix) to Qt6Core.prl. Then we
use this Qt to build a qmake project, compilation will fail due to
missing zstd.obj. Without "-l" prefix, qmake will treat "zstd" as an
object file instead of a library.
Library names in qt_module.pri and qt_lib_*_private.pri are also
missing "-l" prefix.
This is because on most compilers, CMAKE_LINK_LIBRARY_FLAG equals
"-l". But on MSVC, it is an empty string. So we should pass
"-DLINK_LIBRARY_FLAG=-l" for MSVC.
Also add "-L/path/to/library" if the library path is not in default
linker search directories. This will write un-relocatable paths to prl
files only when using 3rdparty libraries to build Qt statically. Usually
it's not a problem.
In addition, CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES is also empty on
MSVC. So The third argument of "$<FILTER>" is empty, it is an invalid
generator expression. This means no include dir will be written to
qt_module.pri and qt_lib_*_private.pri on MSVC. So only use "$<FILTER>"
when CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES is not empty.
Change-Id: Ib66f95dc09cf920363a4b9338fb97747dd2f8ab7
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit 2c49f85380d7ad79d9473e0f42e7afaa36d31af9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'cmake/QtPrlHelpers.cmake')
-rw-r--r-- | cmake/QtPrlHelpers.cmake | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/cmake/QtPrlHelpers.cmake b/cmake/QtPrlHelpers.cmake index 0aab301053..9e830827a0 100644 --- a/cmake/QtPrlHelpers.cmake +++ b/cmake/QtPrlHelpers.cmake @@ -379,6 +379,11 @@ ${prl_step1_content_libs} qt_path_join(prl_meta_info_path "${CMAKE_CURRENT_BINARY_DIR}" "${prl_meta_info_name_prefix}${config}${prl_meta_info_name_suffix}") + if(MSVC) + set(link_library_flag "-l") + else() + set(link_library_flag ${CMAKE_LINK_LIBRARY_FLAG}) + endif() add_custom_command( OUTPUT "${prl_step2_path}" DEPENDS "${prl_step1_path}" @@ -391,8 +396,9 @@ ${prl_step1_content_libs} "-DOUT_FILE=${prl_step2_path}" "-DLIBRARY_PREFIXES=${library_prefixes}" "-DLIBRARY_SUFFIXES=${library_suffixes}" - "-DLINK_LIBRARY_FLAG=${CMAKE_LINK_LIBRARY_FLAG}" + "-DLINK_LIBRARY_FLAG=${link_library_flag}" "-DQT_LIB_DIRS=${qt_lib_dirs}" + "-DIMPLICIT_LINK_DIRECTORIES=${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}" -P "${QT_CMAKE_DIR}/QtFinishPrlFile.cmake" VERBATIM COMMENT "Generating prl file for target ${target}" |