diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index a80dfdd020..6784232ca9 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -139,8 +139,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 370ff607c4..dbe736c438 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 + # $ in file(GENERATE). And given that .pc files don't support dynamic + # evaluation like the $ 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)