summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <[email protected]>2023-07-14 15:24:19 +0200
committerQt Cherry-pick Bot <[email protected]>2023-07-14 17:03:53 +0000
commitdae4bde604ecb8a19852793b5745bc9628210bbd (patch)
treefa5dfd6c8f1f6b8886b253e2a6fda4f46defec12
parentbe16b95dcd545610711918615b39871a3e8374bf (diff)
CMake: Fix gc_sections genex evaluation in pkgconfig file creation
The gc_sections linker flag was recently wrapped in a $<CXX_COMPILER_ID> genex to prevent adding it the command line when using an incompatible compiler. This causes an issue when generating .pc pkg-config files because $<CXX_COMPILER_ID> can't be used in the output of a file(GENERATE) call. Record the flag in a global property, both the genex-wrapped and bare forms, so that we can perform a string replacement when generating the pkg-config file to remove the genex wrapping. This is not perfect, in the sense that consumers of the .pc file might get the wrong flag if using an incompatible compiler, but it's better than outright failing the Qt build. Distros will be expected to patch the .pc files if necessary. Note the issue does not usually happen for regular Qt builds because gc_sections is only enabled automatically for static builds, but for static builds we don't currently generate .pc files. So the issue only happens in shared Qt builds where the gc_sections feature is enabled manually. Amends a2b6c2f3437bf1779da787e719bea08bc6f28622 Fixes: QTBUG-115243 Change-Id: I3f6bdf86c24ee90b6da04994e458b438cc41fc7a Reviewed-by: Amir Masoud Abdol <[email protected]> (cherry picked from commit 53b6c88a2529a5767b2f4c6ff91680b93dc5e357) Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r--cmake/QtFlagHandlingHelpers.cmake7
-rw-r--r--cmake/QtPkgConfigHelpers.cmake11
2 files changed, 18 insertions, 0 deletions
diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake
index 3ce54181469..edc1080d5f9 100644
--- a/cmake/QtFlagHandlingHelpers.cmake
+++ b/cmake/QtFlagHandlingHelpers.cmake
@@ -146,8 +146,15 @@ function(qt_internal_apply_gc_binaries target visibility)
elseif(LINUX OR BSD OR WIN32 OR ANDROID)
set(gc_sections_flag "-Wl,--gc-sections")
endif()
+
+ # Save the flag value with and without genex wrapping, so we can remove the wrapping
+ # when generating .pc pkgconfig files.
+ set_property(GLOBAL PROPERTY _qt_internal_gc_sections_without_genex "${gc_sections_flag}")
+
set(gc_sections_flag
"${clang_or_gcc_begin}${gc_sections_flag}${clang_or_gcc_end}")
+
+ set_property(GLOBAL PROPERTY _qt_internal_gc_sections_with_genex "${gc_sections_flag}")
endif()
if(gc_sections_flag)
target_link_options("${target}" ${visibility} "${gc_sections_flag}")
diff --git a/cmake/QtPkgConfigHelpers.cmake b/cmake/QtPkgConfigHelpers.cmake
index 370ff607c4f..dbe736c438d 100644
--- a/cmake/QtPkgConfigHelpers.cmake
+++ b/cmake/QtPkgConfigHelpers.cmake
@@ -51,6 +51,17 @@ function(qt_internal_generate_pkg_config_file module)
list(TRANSFORM loose_include_dirs REPLACE "${INSTALL_INCLUDEDIR}" "\${includedir}")
list(TRANSFORM loose_include_dirs REPLACE "${INSTALL_MKSPECSDIR}" "\${mkspecsdir}")
+ # Remove genex wrapping around gc_sections flag because we can't evaluate genexes like
+ # $<CXX_COMPILER_ID> in file(GENERATE). And given that .pc files don't support dynamic
+ # evaluation like the $<CXX_COMPILER_ID> genex, distros will be expected to patch the .pc
+ # files according to which compiler they intend to be used with.
+ get_property(gc_sections_with_genex GLOBAL PROPERTY _qt_internal_gc_sections_with_genex)
+ get_property(gc_sections_without_genex GLOBAL PROPERTY _qt_internal_gc_sections_without_genex)
+ if(loose_link_options AND gc_sections_with_genex AND gc_sections_without_genex)
+ string(REPLACE "${gc_sections_with_genex}" "${gc_sections_without_genex}"
+ loose_link_options "${loose_link_options}")
+ endif()
+
qt_internal_set_pkg_config_cpp_flags(link_options "${loose_link_options}" "")
qt_internal_set_pkg_config_cpp_flags(compile_defs "${loose_compile_defs}" -D)
qt_internal_set_pkg_config_cpp_flags(include_dirs "${loose_include_dirs}" -I)