diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index 251a356df0e..3cfab2abf61 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -235,6 +235,7 @@ function(qt_internal_apply_gc_binaries target visibility) endif() endfunction() +# Only applied to Bootstrap and BundledPCRE2. function(qt_internal_apply_intel_cet target visibility) if(NOT QT_FEATURE_intelcet) return() @@ -254,10 +255,36 @@ function(qt_internal_apply_intel_cet target visibility) ">:-mshstk>") endif() if(flags) + set(opt_out_condition "$>>") + set(flags "$<${opt_out_condition}:${flags}>") target_compile_options("${target}" ${visibility} "${flags}") endif() endfunction() +# Meant to be applied to PlatformCommonInternal. +function(qt_internal_apply_intel_cet_harderning target) + if(NOT QT_FEATURE_intelcet) + return() + endif() + + set(opt_out_condition "$>>") + + if(MSVC) + set(intel_cet_flag "-CETCOMPAT") + set(condition "$<${opt_out_condition}:${intel_cet_flag}>") + qt_internal_platform_link_options("${target}" INTERFACE "${condition}") + else() + set(intel_cet_flag "-fcf-protection=full") + set(condition "$<${opt_out_condition}:${intel_cet_flag}>") + target_compile_options("${target}" INTERFACE "${condition}") + endif() +endfunction() + +# Allow opting out of the Intel CET hardening on a per-target basis. +function(qt_internal_skip_intel_cet_hardening target) + set_target_properties("${target}" PROPERTIES _qt_no_intel_cet_harderning TRUE) +endfunction() + # Sets the exceptions flags for the given target according to exceptions_on function(qt_internal_set_exceptions_flags target exceptions_on) set(_defs "") diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index f7b32d18f23..79f7fd9c57f 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -311,13 +311,8 @@ if (GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL "9.2") endif() # Hardening options -if(QT_FEATURE_intelcet) - if(MSVC) - qt_internal_platform_link_options(PlatformCommonInternal INTERFACE -CETCOMPAT) - else() - target_compile_options(PlatformCommonInternal INTERFACE -fcf-protection=full) - endif() -endif() + +qt_internal_apply_intel_cet_harderning(PlatformCommonInternal) if(QT_FEATURE_glibc_fortify_source) set(is_optimized_build "$>,$>")