Ensure that Qt user projects build with sanitizer flags if Qt was configured with any of the sanitizers enabled. To compile Qt with sanitizer support enable any of Qt sanitizer features. Passing -DECM_ENABLE_SANITIZERS=address to CMake is NOT supported anymore. When configuring Qt using CMake directly, pass -DFEATURE_sanitizer_address=ON -DFEATURE_sanitizer_undefined=ON instead of -DECM_ENABLE_SANITIZERS=address;undefined When configuring Qt with the configure script pass -sanitize address -sanitize undefined as usual. QtConfig.cmake now records the sanitizer options that should be enabled for all consuming projects based on the enabled Qt features. This applies to internal Qt builds as well as well as tests an examples. The recorded sanitizer options are assigned to the ECM_ENABLE_SANITIZERS variable in the directory scope where find_package(Qt6) is called. The ECMEnableSanitizers module is included to add the necessary flags to all targets in that directory scope or its children. This behavior can be opted out by setting the QT_NO_ADD_SANITIZER_OPTIONS variable in projects that use Qt and might be handling sanitizer options differently. Amends 7e03bc39b8bcdaa4e83e72ac99e117561c124951 Pick-to: 6.2 Fixes: QTBUG-87989 Task-number: QTBUG-92083 Change-Id: I2e3371147277bdf8f55a39abaa34478dea4853a6 Reviewed-by: Robert Löhning <robert.loehning@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
26 lines
1.1 KiB
CMake
26 lines
1.1 KiB
CMake
# Computes which sanitizer options should be set based on features evaluated in qtbase.
|
|
# Sets ECM_ENABLE_SANITIZERS with those options in the function calling scope.
|
|
function(qt_internal_set_up_sanitizer_options)
|
|
set(ECM_ENABLE_SANITIZERS "" CACHE STRING "Enable sanitizers")
|
|
set_property(CACHE ECM_ENABLE_SANITIZERS PROPERTY STRINGS
|
|
"address;memory;thread;undefined;fuzzer;fuzzer-no-link")
|
|
|
|
# If QT_FEATURE_sanitize_foo was enabled, make sure to set the appropriate
|
|
# ECM_ENABLE_SANITIZERS value.
|
|
set(enabled_sanitizer_features "")
|
|
foreach(sanitizer_type address memory thread undefined)
|
|
if(QT_FEATURE_sanitize_${sanitizer_type})
|
|
list(APPEND enabled_sanitizer_features "${sanitizer_type}")
|
|
endif()
|
|
endforeach()
|
|
|
|
# There's a mismatch between fuzzer-no-link ECM option and fuzzer_no_link Qt feature.
|
|
if(QT_FEATURE_sanitize_fuzzer_no_link)
|
|
list(APPEND enabled_sanitizer_features "fuzzer-no-link")
|
|
endif()
|
|
|
|
if(enabled_sanitizer_features)
|
|
set(ECM_ENABLE_SANITIZERS "${enabled_sanitizer_features}" PARENT_SCOPE)
|
|
endif()
|
|
endfunction()
|