diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index 57743067af..a80dfdd020 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -121,6 +121,16 @@ function(qt_internal_apply_gc_binaries target visibility) message(FATAL_ERROR "Visibitily setting must be one of PRIVATE, INTERFACE or PUBLIC.") endif() + string(JOIN "" clang_or_gcc_begin + "$<$," + "$," + "$," + "$" + ">:" + ) + set(clang_or_gcc_end ">") + if ((GCC OR CLANG) AND NOT WASM AND NOT UIKIT AND NOT MSVC) if(APPLE) set(gc_sections_flag "-Wl,-dead_strip") @@ -129,16 +139,19 @@ function(qt_internal_apply_gc_binaries target visibility) elseif(LINUX OR BSD OR WIN32 OR ANDROID) set(gc_sections_flag "-Wl,--gc-sections") endif() + set(gc_sections_flag + "${clang_or_gcc_begin}${gc_sections_flag}${clang_or_gcc_end}") endif() if(gc_sections_flag) target_link_options("${target}" ${visibility} "${gc_sections_flag}") endif() if((GCC OR CLANG) AND NOT WASM AND NOT UIKIT AND NOT MSVC) - set(split_sections_flags "-ffunction-sections" "-fdata-sections") + set(split_sections_flags + "${clang_or_gcc_begin}-ffunction-sections;-fdata-sections${clang_or_gcc_end}") endif() if(split_sections_flags) - target_compile_options("${target}" ${visibility} ${split_sections_flags}) + target_compile_options("${target}" ${visibility} "${split_sections_flags}") endif() endfunction() @@ -153,7 +166,12 @@ function(qt_internal_apply_intel_cet target visibility) endif() if(GCC) - set(flags "-mshstk") + string(JOIN "" flags + "$<$," + "$," + "$" + ">:-mshstk>") endif() if(flags) target_compile_options("${target}" ${visibility} "${flags}")