From 28c9625d00d084cfc226c979be52231df7f5d3e3 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Mon, 22 May 2023 16:02:44 +0200 Subject: [PATCH] Fix CMP0099 impact - disallow propagating internal linker options CMP0099 changes the way of LINK_ONLY genex works. With CMP0099 set to OLD LINK_ONLY genex only links the exact library binary/archive without propagating other interface options from the target. This feature was exploited by PlatformXInternal targets to avoid propagating of their linker options. Nowadays when CMP0099 is forced to NEW by Qt scripts, including user-facing, we cannot rely on LINK_ONLY genex. Introduce _qt_is_internal_target property that is set for all Qt executables and explicitly limits the propagation of the linker options from PlatformXInternal targets. Pick-to: 6.5 6.6 Fixes: QTBUG-113641 Change-Id: I3a0ecddb65886e435073feb24c1b47035130ba70 Reviewed-by: Alexandru Croitor (OOO) Reviewed-by: Qt CI Bot --- cmake/QtExecutableHelpers.cmake | 1 + cmake/QtInternalTargets.cmake | 21 +++++++++++++++------ cmake/QtTargetHelpers.cmake | 9 +++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cmake/QtExecutableHelpers.cmake b/cmake/QtExecutableHelpers.cmake index 15410102951..768e1f15623 100644 --- a/cmake/QtExecutableHelpers.cmake +++ b/cmake/QtExecutableHelpers.cmake @@ -30,6 +30,7 @@ function(qt_internal_add_executable name) endif() _qt_internal_create_executable(${name}) + qt_internal_mark_as_internal_target(${name}) if(ANDROID) _qt_internal_android_executable_finalizer(${name}) endif() diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index d7a276cc174..faa724e68f5 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -209,6 +209,14 @@ function(qt_internal_apply_bitcode_flags target) target_compile_options("${target}" INTERFACE ${bitcode_flags}) endfunction() +# Function guards linker options that are applicable for internal Qt targets only from propagating +# them to user projects. +function(qt_internal_platform_link_options target scope) + set(options ${ARGN}) + set(is_internal_target_genex "$>") + target_link_options(${target} ${scope} "$<${is_internal_target_genex}:${options}>") +endfunction() + # Apple deprecated the entire OpenGL API in favor of Metal, which # we are aware of, so silence the deprecation warnings in code. # This does not apply to user-code, which will need to silence @@ -287,7 +295,7 @@ if (MSVC) $<$>:-guard:cf -Gw> ) - target_link_options(PlatformCommonInternal INTERFACE + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE -DYNAMICBASE -NXCOMPAT -LARGEADDRESSAWARE $<$>:-OPT:REF -OPT:ICF -GUARD:CF> ) @@ -303,7 +311,7 @@ endif() if(QT_FEATURE_intelcet) if(MSVC) - target_link_options(PlatformCommonInternal INTERFACE + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE -CETCOMPAT ) else() @@ -332,22 +340,23 @@ endif() if(DEFINED QT_EXTRA_FRAMEWORKPATHS AND APPLE) list(TRANSFORM QT_EXTRA_FRAMEWORKPATHS PREPEND "-F" OUTPUT_VARIABLE __qt_fw_flags) target_compile_options(PlatformCommonInternal INTERFACE ${__qt_fw_flags}) - target_link_options(PlatformCommonInternal INTERFACE ${__qt_fw_flags}) + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE ${__qt_fw_flags}) unset(__qt_fw_flags) endif() qt_internal_get_active_linker_flags(__qt_internal_active_linker_flags) if(__qt_internal_active_linker_flags) - target_link_options(PlatformCommonInternal INTERFACE "${__qt_internal_active_linker_flags}") + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE + "${__qt_internal_active_linker_flags}") endif() unset(__qt_internal_active_linker_flags) if(QT_FEATURE_enable_gdb_index) - target_link_options(PlatformCommonInternal INTERFACE "-Wl,--gdb-index") + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE "-Wl,--gdb-index") endif() if(QT_FEATURE_enable_new_dtags) - target_link_options(PlatformCommonInternal INTERFACE "-Wl,--enable-new-dtags") + qt_internal_platform_link_options(PlatformCommonInternal INTERFACE "-Wl,--enable-new-dtags") endif() function(qt_get_implicit_sse2_genex_condition out_var) diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake index 2c2b324182a..63a4f4686f9 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -1021,6 +1021,15 @@ endfunction() # Needed to allow selectively applying certain flags via PlatformXInternal targets. function(qt_internal_mark_as_internal_library target) set_target_properties(${target} PROPERTIES _qt_is_internal_library TRUE) + qt_internal_mark_as_internal_target(${target}) +endfunction() + +# Marks a target with a property that it was built using the internal Qt API (qt_internal_*) as +# opposed to it being a user project library or executable(qt_add_*, etc). +# +# Needed to allow selectively applying certain flags via PlatformXInternal targets. +function(qt_internal_mark_as_internal_target target) + set_target_properties(${target} PROPERTIES _qt_is_internal_target TRUE) endfunction() # Marks a target with a property to skip it adding it as a dependency when building examples as