From 2915921ad2a79a4ce1651dc7297f6571788d1413 Mon Sep 17 00:00:00 2001 From: Li Xinwei <1326710505@qq.com> Date: Fri, 16 Jul 2021 16:28:32 +0800 Subject: [PATCH] Fix generated pri and prl files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quote the paths after "-L". Get MSVC’s implicit link directories from $ENV{LIB}. Fix some issues cause by Inconsistent case. Amends 2c49f85380d7ad79d9473e0f42e7afaa36d31af9 Fixes: QTBUG-95198 Pick-to: 6.2 6.1 Change-Id: Ie82f10b088e2764396377726340509f24a4ae8e7 Reviewed-by: Alexandru Croitor --- cmake/QtFinishPrlFile.cmake | 1 + cmake/QtGenerateLibHelpers.cmake | 9 ++++++--- cmake/QtGenerateLibPri.cmake | 1 + cmake/QtPriHelpers.cmake | 8 ++++++-- cmake/QtPrlHelpers.cmake | 4 +++- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cmake/QtFinishPrlFile.cmake b/cmake/QtFinishPrlFile.cmake index a932f2f988..04ae2c9a43 100644 --- a/cmake/QtFinishPrlFile.cmake +++ b/cmake/QtFinishPrlFile.cmake @@ -23,6 +23,7 @@ # 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 +cmake_policy(SET CMP0007 NEW) include("${CMAKE_CURRENT_LIST_DIR}/QtGenerateLibHelpers.cmake") file(STRINGS "${IN_FILE}" lines) diff --git a/cmake/QtGenerateLibHelpers.cmake b/cmake/QtGenerateLibHelpers.cmake index 913b0ed90a..e3f4bbf881 100644 --- a/cmake/QtGenerateLibHelpers.cmake +++ b/cmake/QtGenerateLibHelpers.cmake @@ -6,11 +6,12 @@ function(qt_get_library_name_without_prefix_and_suffix out_var file_path) if(IS_ABSOLUTE "${file_path}") get_filename_component(basename "${file_path}" NAME_WE) get_filename_component(ext "${file_path}" EXT) + string(TOLOWER "${ext}" ext_lower) foreach(libsuffix ${LIBRARY_SUFFIXES}) # Handle weird prefix extensions like in the case of # "/usr/lib/x86_64-linux-gnu/libglib-2.0.so" # it's ".0.so". - if(ext MATCHES "^(\\.[0-9]+)*${libsuffix}(\\.[0-9]+)*") + if(ext_lower MATCHES "^(\\.[0-9]+)*${libsuffix}(\\.[0-9]+)*") set(is_linkable_library TRUE) set(weird_numbered_extension "${CMAKE_MATCH_1}") break() @@ -64,11 +65,13 @@ function(qt_transform_absolute_library_paths_to_link_flags out_var library_path_ foreach(library_path ${library_path_list}) qt_get_library_with_link_flag(lib_name_with_link_flag "${library_path}") if(lib_name_with_link_flag) + string(TOLOWER "${IMPLICIT_LINK_DIRECTORIES}" IMPLICIT_LINK_DIRECTORIES_LOWER) get_filename_component(dir "${library_path}" DIRECTORY) + string(TOLOWER "${dir}" dir_lower) # If library_path isn't in default link directories, we should add it to link flags. - list(FIND IMPLICIT_LINK_DIRECTORIES ${dir} index) + list(FIND IMPLICIT_LINK_DIRECTORIES_LOWER "${dir_lower}" index) if(${index} EQUAL -1) - list(APPEND out_list "-L${dir} ") + list(APPEND out_list "-L\"${dir}\"") endif() list(APPEND out_list "${lib_name_with_link_flag}") else() diff --git a/cmake/QtGenerateLibPri.cmake b/cmake/QtGenerateLibPri.cmake index 3c5e860e16..127d859189 100644 --- a/cmake/QtGenerateLibPri.cmake +++ b/cmake/QtGenerateLibPri.cmake @@ -16,6 +16,7 @@ # The library values are transformed from an absolute path into link flags # aka from "/usr/lib/x86_64-linux-gnu/libcups.so" to "-lcups". +cmake_policy(SET CMP0007 NEW) cmake_policy(SET CMP0057 NEW) # Create a qmake-style list from the passed arguments and store it in ${out_var}. diff --git a/cmake/QtPriHelpers.cmake b/cmake/QtPriHelpers.cmake index cfb5e85dc6..233f7ea4a4 100644 --- a/cmake/QtPriHelpers.cmake +++ b/cmake/QtPriHelpers.cmake @@ -378,8 +378,10 @@ QT.${config_module_name}_private.disabled_features = ${disabled_private_features ${CMAKE_STATIC_LIBRARY_SUFFIX}) if(MSVC) set(link_library_flag "-l") + file(TO_CMAKE_PATH "$ENV{LIB};${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}" implicit_link_directories) else() set(link_library_flag ${CMAKE_LINK_LIBRARY_FLAG}) + set(implicit_link_directories ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}) endif() add_custom_command( OUTPUT "${private_pri_file_path}" @@ -391,7 +393,7 @@ QT.${config_module_name}_private.disabled_features = ${disabled_private_features "-DLIBRARY_SUFFIXES=${library_suffixes}" "-DLINK_LIBRARY_FLAG=${link_library_flag}" "-DCONFIGS=${configs}" - "-DIMPLICIT_LINK_DIRECTORIES=${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}" + "-DIMPLICIT_LINK_DIRECTORIES=${implicit_link_directories}" -P "${QT_CMAKE_DIR}/QtGenerateLibPri.cmake" VERBATIM) add_custom_target(${target}_lib_pri DEPENDS "${private_pri_file_path}") @@ -801,8 +803,10 @@ CONFIG += ${private_config_joined} ${CMAKE_STATIC_LIBRARY_SUFFIX}) if(MSVC) set(link_library_flag "-l") + file(TO_CMAKE_PATH "$ENV{LIB};${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}" implicit_link_directories) else() set(link_library_flag ${CMAKE_LINK_LIBRARY_FLAG}) + set(implicit_link_directories ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}) endif() add_custom_command( OUTPUT "${qmodule_pri_target_path}" @@ -814,7 +818,7 @@ CONFIG += ${private_config_joined} "-DLIBRARY_SUFFIXES=${library_suffixes}" "-DLINK_LIBRARY_FLAG=${link_library_flag}" "-DCONFIGS=${configs}" - "-DIMPLICIT_LINK_DIRECTORIES=${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}" + "-DIMPLICIT_LINK_DIRECTORIES=${implicit_link_directories}" -P "${QT_CMAKE_DIR}/QtGenerateLibPri.cmake" VERBATIM) add_custom_target(qmodule_pri DEPENDS "${qmodule_pri_target_path}") diff --git a/cmake/QtPrlHelpers.cmake b/cmake/QtPrlHelpers.cmake index a74a2cf6fd..18b230deb1 100644 --- a/cmake/QtPrlHelpers.cmake +++ b/cmake/QtPrlHelpers.cmake @@ -153,8 +153,10 @@ ${prl_step1_content_libs} "${prl_meta_info_name_prefix}${config}${prl_meta_info_name_suffix}") if(MSVC) set(link_library_flag "-l") + file(TO_CMAKE_PATH "$ENV{LIB};${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}" implicit_link_directories) else() set(link_library_flag ${CMAKE_LINK_LIBRARY_FLAG}) + set(implicit_link_directories ${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}) endif() add_custom_command( OUTPUT "${prl_step2_path}" @@ -170,7 +172,7 @@ ${prl_step1_content_libs} "-DLIBRARY_SUFFIXES=${library_suffixes}" "-DLINK_LIBRARY_FLAG=${link_library_flag}" "-DQT_LIB_DIRS=${qt_lib_dirs}" - "-DIMPLICIT_LINK_DIRECTORIES=${CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES}" + "-DIMPLICIT_LINK_DIRECTORIES=${implicit_link_directories}" -P "${QT_CMAKE_DIR}/QtFinishPrlFile.cmake" VERBATIM COMMENT "Generating prl file for target ${target}"