summaryrefslogtreecommitdiffstats
path: root/cmake/QtPriHelpers.cmake
diff options
context:
space:
mode:
authorLi Xinwei <1326710505@qq.com>2021-05-27 19:41:43 +0800
committerLi Xinwei <1326710505@qq.com>2021-06-02 13:32:06 +0800
commit2c49f85380d7ad79d9473e0f42e7afaa36d31af9 (patch)
treebb4a601432cfdf9fb8fb89fceeeed2feadac2b0c /cmake/QtPriHelpers.cmake
parent350902f1cd631ae2387e4c9308c905abf618085d (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. Pick-to: 6.1 Change-Id: Ib66f95dc09cf920363a4b9338fb97747dd2f8ab7 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake/QtPriHelpers.cmake')
-rw-r--r--cmake/QtPriHelpers.cmake22
1 files changed, 18 insertions, 4 deletions
diff --git a/cmake/QtPriHelpers.cmake b/cmake/QtPriHelpers.cmake
index 9c5a955259..e00bccbb55 100644
--- a/cmake/QtPriHelpers.cmake
+++ b/cmake/QtPriHelpers.cmake
@@ -55,8 +55,10 @@ function(qt_generate_qmake_libraries_pri_content module_name output_root_dir out
endforeach()
# Filter out implicit include directories
- string(PREPEND lib_incdir "$<FILTER:")
- string(APPEND lib_incdir ",EXCLUDE,${implicit_include_dirs_regex}>")
+ if(implicit_include_dirs_regex)
+ string(PREPEND lib_incdir "$<FILTER:")
+ string(APPEND lib_incdir ",EXCLUDE,${implicit_include_dirs_regex}>")
+ endif()
set(uccfg $<UPPER_CASE:$<CONFIG>>)
string(APPEND content "list(APPEND known_libs ${uclib})
@@ -377,6 +379,11 @@ QT.${config_module_name}_private.disabled_features = ${disabled_private_features
${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES}
${CMAKE_STATIC_LIBRARY_SUFFIX})
+ if(MSVC)
+ set(link_library_flag "-l")
+ else()
+ set(link_library_flag ${CMAKE_LINK_LIBRARY_FLAG})
+ endif()
add_custom_command(
OUTPUT "${private_pri_file_path}"
DEPENDS ${inputs}
@@ -385,8 +392,9 @@ QT.${config_module_name}_private.disabled_features = ${disabled_private_features
COMMAND ${CMAKE_COMMAND} "-DIN_FILES=${inputs}" "-DOUT_FILE=${private_pri_file_path}"
"-DLIBRARY_PREFIXES=${library_prefixes}"
"-DLIBRARY_SUFFIXES=${library_suffixes}"
- "-DLINK_LIBRARY_FLAG=${CMAKE_LINK_LIBRARY_FLAG}"
+ "-DLINK_LIBRARY_FLAG=${link_library_flag}"
"-DCONFIGS=${configs}"
+ "-DIMPLICIT_LINK_DIRECTORIES=${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}"
-P "${QT_CMAKE_DIR}/QtGenerateLibPri.cmake"
VERBATIM)
add_custom_target(${target}_lib_pri DEPENDS "${private_pri_file_path}")
@@ -794,6 +802,11 @@ CONFIG += ${private_config_joined}
${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES}
${CMAKE_STATIC_LIBRARY_SUFFIX})
+ if(MSVC)
+ set(link_library_flag "-l")
+ else()
+ set(link_library_flag ${CMAKE_LINK_LIBRARY_FLAG})
+ endif()
add_custom_command(
OUTPUT "${qmodule_pri_target_path}"
DEPENDS ${inputs}
@@ -802,8 +815,9 @@ CONFIG += ${private_config_joined}
COMMAND ${CMAKE_COMMAND} "-DIN_FILES=${inputs}" "-DOUT_FILE=${qmodule_pri_target_path}"
"-DLIBRARY_PREFIXES=${library_prefixes}"
"-DLIBRARY_SUFFIXES=${library_suffixes}"
- "-DLINK_LIBRARY_FLAG=${CMAKE_LINK_LIBRARY_FLAG}"
+ "-DLINK_LIBRARY_FLAG=${link_library_flag}"
"-DCONFIGS=${configs}"
+ "-DIMPLICIT_LINK_DIRECTORIES=${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}"
-P "${QT_CMAKE_DIR}/QtGenerateLibPri.cmake"
VERBATIM)
add_custom_target(qmodule_pri DEPENDS "${qmodule_pri_target_path}")