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>
This commit is contained in:
parent
a3b1f4e463
commit
4428f078e7
@ -19,6 +19,7 @@
|
|||||||
# LIBRARY_SUFFIXES: list of known library extensions, e.g. .so;.a on Linux
|
# LIBRARY_SUFFIXES: list of known library extensions, e.g. .so;.a on Linux
|
||||||
# LIBRARY_PREFIXES: list of known library prefies, e.g. the "lib" in "libz" on on Linux
|
# LIBRARY_PREFIXES: list of known library prefies, e.g. the "lib" in "libz" on on Linux
|
||||||
# LINK_LIBRARY_FLAG: flag used to link a shared library to an executable, e.g. -l on UNIX
|
# LINK_LIBRARY_FLAG: flag used to link a shared library to an executable, e.g. -l on UNIX
|
||||||
|
# IMPLICIT_LINK_DIRECTORIES: list of implicit linker search paths
|
||||||
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/QtGenerateLibHelpers.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/QtGenerateLibHelpers.cmake")
|
||||||
|
|
||||||
|
@ -64,6 +64,12 @@ function(qt_transform_absolute_library_paths_to_link_flags out_var library_path_
|
|||||||
foreach(library_path ${library_path_list})
|
foreach(library_path ${library_path_list})
|
||||||
qt_get_library_with_link_flag(lib_name_with_link_flag "${library_path}")
|
qt_get_library_with_link_flag(lib_name_with_link_flag "${library_path}")
|
||||||
if(lib_name_with_link_flag)
|
if(lib_name_with_link_flag)
|
||||||
|
get_filename_component(dir "${library_path}" DIRECTORY)
|
||||||
|
# If library_path isn't in default link directories, we should add it to link flags.
|
||||||
|
list(FIND IMPLICIT_LINK_DIRECTORIES ${dir} index)
|
||||||
|
if(${index} EQUAL -1)
|
||||||
|
list(APPEND out_list "-L${dir} ")
|
||||||
|
endif()
|
||||||
list(APPEND out_list "${lib_name_with_link_flag}")
|
list(APPEND out_list "${lib_name_with_link_flag}")
|
||||||
else()
|
else()
|
||||||
list(APPEND out_list "${library_path}")
|
list(APPEND out_list "${library_path}")
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
# LIBRARY_SUFFIXES: list of known library extensions, e.g. .so;.a on Linux
|
# LIBRARY_SUFFIXES: list of known library extensions, e.g. .so;.a on Linux
|
||||||
# LIBRARY_PREFIXES: list of known library prefies, e.g. the "lib" in "libz" on on Linux
|
# LIBRARY_PREFIXES: list of known library prefies, e.g. the "lib" in "libz" on on Linux
|
||||||
# LINK_LIBRARY_FLAG: flag used to link a shared library to an executable, e.g. -l on UNIX
|
# LINK_LIBRARY_FLAG: flag used to link a shared library to an executable, e.g. -l on UNIX
|
||||||
|
# IMPLICIT_LINK_DIRECTORIES: list of implicit linker search paths
|
||||||
#
|
#
|
||||||
# QMAKE_LIBS_XXX values are split into QMAKE_LIBS_XXX_DEBUG and QMAKE_LIBS_XXX_RELEASE if
|
# QMAKE_LIBS_XXX values are split into QMAKE_LIBS_XXX_DEBUG and QMAKE_LIBS_XXX_RELEASE if
|
||||||
# debug_and_release was detected. The CMake configuration "Debug" is considered for the _DEBUG
|
# debug_and_release was detected. The CMake configuration "Debug" is considered for the _DEBUG
|
||||||
|
@ -55,8 +55,10 @@ function(qt_generate_qmake_libraries_pri_content module_name output_root_dir out
|
|||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
# Filter out implicit include directories
|
# Filter out implicit include directories
|
||||||
string(PREPEND lib_incdir "$<FILTER:")
|
if(implicit_include_dirs_regex)
|
||||||
string(APPEND lib_incdir ",EXCLUDE,${implicit_include_dirs_regex}>")
|
string(PREPEND lib_incdir "$<FILTER:")
|
||||||
|
string(APPEND lib_incdir ",EXCLUDE,${implicit_include_dirs_regex}>")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(uccfg $<UPPER_CASE:$<CONFIG>>)
|
set(uccfg $<UPPER_CASE:$<CONFIG>>)
|
||||||
string(APPEND content "list(APPEND known_libs ${uclib})
|
string(APPEND content "list(APPEND known_libs ${uclib})
|
||||||
@ -375,6 +377,11 @@ QT.${config_module_name}_private.disabled_features = ${disabled_private_features
|
|||||||
${CMAKE_SHARED_LIBRARY_SUFFIX}
|
${CMAKE_SHARED_LIBRARY_SUFFIX}
|
||||||
${CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES}
|
${CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES}
|
||||||
${CMAKE_STATIC_LIBRARY_SUFFIX})
|
${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||||
|
if(MSVC)
|
||||||
|
set(link_library_flag "-l")
|
||||||
|
else()
|
||||||
|
set(link_library_flag ${CMAKE_LINK_LIBRARY_FLAG})
|
||||||
|
endif()
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${private_pri_file_path}"
|
OUTPUT "${private_pri_file_path}"
|
||||||
DEPENDS ${inputs}
|
DEPENDS ${inputs}
|
||||||
@ -383,8 +390,9 @@ QT.${config_module_name}_private.disabled_features = ${disabled_private_features
|
|||||||
COMMAND ${CMAKE_COMMAND} "-DIN_FILES=${inputs}" "-DOUT_FILE=${private_pri_file_path}"
|
COMMAND ${CMAKE_COMMAND} "-DIN_FILES=${inputs}" "-DOUT_FILE=${private_pri_file_path}"
|
||||||
"-DLIBRARY_PREFIXES=${library_prefixes}"
|
"-DLIBRARY_PREFIXES=${library_prefixes}"
|
||||||
"-DLIBRARY_SUFFIXES=${library_suffixes}"
|
"-DLIBRARY_SUFFIXES=${library_suffixes}"
|
||||||
"-DLINK_LIBRARY_FLAG=${CMAKE_LINK_LIBRARY_FLAG}"
|
"-DLINK_LIBRARY_FLAG=${link_library_flag}"
|
||||||
"-DCONFIGS=${configs}"
|
"-DCONFIGS=${configs}"
|
||||||
|
"-DIMPLICIT_LINK_DIRECTORIES=${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}"
|
||||||
-P "${QT_CMAKE_DIR}/QtGenerateLibPri.cmake"
|
-P "${QT_CMAKE_DIR}/QtGenerateLibPri.cmake"
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
add_custom_target(${target}_lib_pri DEPENDS "${private_pri_file_path}")
|
add_custom_target(${target}_lib_pri DEPENDS "${private_pri_file_path}")
|
||||||
@ -782,6 +790,11 @@ CONFIG += ${private_config_joined}
|
|||||||
${CMAKE_SHARED_LIBRARY_SUFFIX}
|
${CMAKE_SHARED_LIBRARY_SUFFIX}
|
||||||
${CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES}
|
${CMAKE_EXTRA_SHARED_LIBRARY_SUFFIXES}
|
||||||
${CMAKE_STATIC_LIBRARY_SUFFIX})
|
${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||||
|
if(MSVC)
|
||||||
|
set(link_library_flag "-l")
|
||||||
|
else()
|
||||||
|
set(link_library_flag ${CMAKE_LINK_LIBRARY_FLAG})
|
||||||
|
endif()
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${qmodule_pri_target_path}"
|
OUTPUT "${qmodule_pri_target_path}"
|
||||||
DEPENDS ${inputs}
|
DEPENDS ${inputs}
|
||||||
@ -790,8 +803,9 @@ CONFIG += ${private_config_joined}
|
|||||||
COMMAND ${CMAKE_COMMAND} "-DIN_FILES=${inputs}" "-DOUT_FILE=${qmodule_pri_target_path}"
|
COMMAND ${CMAKE_COMMAND} "-DIN_FILES=${inputs}" "-DOUT_FILE=${qmodule_pri_target_path}"
|
||||||
"-DLIBRARY_PREFIXES=${library_prefixes}"
|
"-DLIBRARY_PREFIXES=${library_prefixes}"
|
||||||
"-DLIBRARY_SUFFIXES=${library_suffixes}"
|
"-DLIBRARY_SUFFIXES=${library_suffixes}"
|
||||||
"-DLINK_LIBRARY_FLAG=${CMAKE_LINK_LIBRARY_FLAG}"
|
"-DLINK_LIBRARY_FLAG=${link_library_flag}"
|
||||||
"-DCONFIGS=${configs}"
|
"-DCONFIGS=${configs}"
|
||||||
|
"-DIMPLICIT_LINK_DIRECTORIES=${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}"
|
||||||
-P "${QT_CMAKE_DIR}/QtGenerateLibPri.cmake"
|
-P "${QT_CMAKE_DIR}/QtGenerateLibPri.cmake"
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
add_custom_target(qmodule_pri DEPENDS "${qmodule_pri_target_path}")
|
add_custom_target(qmodule_pri DEPENDS "${qmodule_pri_target_path}")
|
||||||
|
@ -379,6 +379,11 @@ ${prl_step1_content_libs}
|
|||||||
qt_path_join(prl_meta_info_path
|
qt_path_join(prl_meta_info_path
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
"${prl_meta_info_name_prefix}${config}${prl_meta_info_name_suffix}")
|
"${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(
|
add_custom_command(
|
||||||
OUTPUT "${prl_step2_path}"
|
OUTPUT "${prl_step2_path}"
|
||||||
DEPENDS "${prl_step1_path}"
|
DEPENDS "${prl_step1_path}"
|
||||||
@ -391,8 +396,9 @@ ${prl_step1_content_libs}
|
|||||||
"-DOUT_FILE=${prl_step2_path}"
|
"-DOUT_FILE=${prl_step2_path}"
|
||||||
"-DLIBRARY_PREFIXES=${library_prefixes}"
|
"-DLIBRARY_PREFIXES=${library_prefixes}"
|
||||||
"-DLIBRARY_SUFFIXES=${library_suffixes}"
|
"-DLIBRARY_SUFFIXES=${library_suffixes}"
|
||||||
"-DLINK_LIBRARY_FLAG=${CMAKE_LINK_LIBRARY_FLAG}"
|
"-DLINK_LIBRARY_FLAG=${link_library_flag}"
|
||||||
"-DQT_LIB_DIRS=${qt_lib_dirs}"
|
"-DQT_LIB_DIRS=${qt_lib_dirs}"
|
||||||
|
"-DIMPLICIT_LINK_DIRECTORIES=${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}"
|
||||||
-P "${QT_CMAKE_DIR}/QtFinishPrlFile.cmake"
|
-P "${QT_CMAKE_DIR}/QtFinishPrlFile.cmake"
|
||||||
VERBATIM
|
VERBATIM
|
||||||
COMMENT "Generating prl file for target ${target}"
|
COMMENT "Generating prl file for target ${target}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user