From 754512a64dffa20165e5b08b77e34b82c072f7f8 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 20 Jun 2022 19:20:34 +0200 Subject: [PATCH] CMake: Fix prl files not to contain hard-coded library paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure to convert absolute paths generated using the $ generator expressions into relative paths. Because prl files are generated for both modules and plugins, we need to pass both a list of qt module locations and qt plugin locations to QtFinishPrl.cmake, and then try to make the absolute path relative to each passed directory. A warning assertion is shown if we no relative path could be made, which will cause an absolute path to be embedded. This should not happen though. Amends f4e998125981038e5e50dab8cc56039faaa0b750 Pick-to: 6.2 6.3 6.4 Fixes: QTBUG-104396 Change-Id: Id68395c0dbb20aad5c510d77835cc931b9396556 Reviewed-by: Qt CI Bot Reviewed-by: Alexey Edelev Reviewed-by: Jörg Bornemann --- cmake/QtFinishPrlFile.cmake | 23 ++++++++++++++++++++++- cmake/QtPrlHelpers.cmake | 7 +++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cmake/QtFinishPrlFile.cmake b/cmake/QtFinishPrlFile.cmake index 78c7d15770..9c93bd49a1 100644 --- a/cmake/QtFinishPrlFile.cmake +++ b/cmake/QtFinishPrlFile.cmake @@ -89,7 +89,28 @@ foreach(line ${lines}) # qmake's UnixMakefileGenerator::findLibraries then takes care of deduplication, which # keeps the last occurrence of the library on the link line, the one after the object # files. - list(APPEND libs_to_prepend "${target_library_path}") + qt_internal_path_is_relative_to_qt_lib_path( + "${target_library_path}" "${QT_LIB_DIRS}" lib_is_a_qt_module relative_lib) + if(NOT lib_is_a_qt_module) + qt_internal_path_is_relative_to_qt_lib_path( + "${target_library_path}" "${QT_PLUGIN_DIRS}" lib_is_a_qt_plugin relative_lib) + endif() + if(NOT lib_is_a_qt_module AND NOT lib_is_a_qt_plugin) + message(AUTHOR_WARNING + "Could not determine relative path for library ${target_library_path} when " + "generating prl file contents. An absolute path will be embedded, which " + "will cause issues if the Qt installation is relocated.") + list(APPEND libs_to_prepend "${target_library_path}") + else() + set(qmake_lib_path_prefix "$$[QT_PRL_INVALID_QMAKE_VARIABLE]") + if(lib_is_a_qt_module) + set(qmake_lib_path_prefix "$$[QT_INSTALL_LIBS]") + elseif(lib_is_a_qt_plugin) + set(qmake_lib_path_prefix "$$[QT_INSTALL_PLUGINS]") + endif() + qt_strip_library_version_suffix(relative_lib "${relative_lib}") + list(APPEND libs_to_prepend "${qmake_lib_path_prefix}/${relative_lib}") + endif() list(PREPEND adjusted_libs ${libs_to_prepend}) endif() diff --git a/cmake/QtPrlHelpers.cmake b/cmake/QtPrlHelpers.cmake index c467e9a634..52f7854f16 100644 --- a/cmake/QtPrlHelpers.cmake +++ b/cmake/QtPrlHelpers.cmake @@ -139,6 +139,12 @@ ${prl_step1_content_libs} "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}/${INSTALL_LIBDIR}") endif() + set(qt_plugin_dirs "${QT_BUILD_DIR}/${INSTALL_PLUGINSDIR}") + if(QT_WILL_INSTALL) + list(APPEND qt_plugin_dirs + "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}/${INSTALL_PLUGINSDIR}") + endif() + foreach(config ${configs}) # Output file for dependency tracking, and which will contain the final content. qt_path_join(prl_step2_path @@ -173,6 +179,7 @@ ${prl_step1_content_libs} "-DLIBRARY_SUFFIXES=${library_suffixes}" "-DLINK_LIBRARY_FLAG=${link_library_flag}" "-DQT_LIB_DIRS=${qt_lib_dirs}" + "-DQT_PLUGIN_DIRS=${qt_plugin_dirs}" "-DIMPLICIT_LINK_DIRECTORIES=${implicit_link_directories}" -P "${QT_CMAKE_DIR}/QtFinishPrlFile.cmake" VERBATIM