summaryrefslogtreecommitdiffstats
path: root/cmake/QtSanitizerHelpers.cmake
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2021-06-24 12:30:32 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2021-06-25 12:33:58 +0200
commit19816826873ebb3a89b2173f8685a8d448410680 (patch)
tree15a7b4f158f4736b43ac10b0a881d80b3d8d7dcf /cmake/QtSanitizerHelpers.cmake
parent9a9da3aad2e59ed9f1f7e8210a6bd5de741d9e7c (diff)
CMake: Propagate sanitizer flags to public projects
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>
Diffstat (limited to 'cmake/QtSanitizerHelpers.cmake')
-rw-r--r--cmake/QtSanitizerHelpers.cmake33
1 files changed, 8 insertions, 25 deletions
diff --git a/cmake/QtSanitizerHelpers.cmake b/cmake/QtSanitizerHelpers.cmake
index 90a1f738cb..ff74792058 100644
--- a/cmake/QtSanitizerHelpers.cmake
+++ b/cmake/QtSanitizerHelpers.cmake
@@ -1,42 +1,25 @@
-function(qt_internal_set_up_sanitizer_features)
+# 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 FEATURE_sanitize_foo is set on the command line, make sure to set the appropriate
- # ECM_ENABLE_SANITIZERS value. Also the other way around. This basically allows setting either
- # the feature or ECM_ENABLE_SANITIZERS directly.
- #
- # TODO: Decide which one of these should be the source of truth, because reconfiguration with
- # different options might not work as expected when ECM_ENABLE_SANITIZERS is provided instead of
- # the features.
+ # 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(FEATURE_sanitize_${sanitizer_type})
+ 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(FEATURE_sanitize_fuzzer_no_link)
+ 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}" CACHE STRING "Enable sanitizers" FORCE)
- endif()
-
- if(ECM_ENABLE_SANITIZERS)
- foreach(sanitizer_type ${ECM_ENABLE_SANITIZERS})
- message(STATUS "Enabling sanitizer: ${sanitizer_type}")
- set(feature_name "FEATURE_sanitize_${sanitizer_type}")
-
- # Transform fuzzer-no-link dashes to underscores.
- string(REGEX REPLACE "-" "_" feature_name "${feature_name}")
-
- set(${feature_name} "ON" CACHE BOOL "Enable ${sanitizer_type} sanitizer" FORCE)
- set(QT_${feature_name} "ON" CACHE BOOL "Enable ${sanitizer_type} sanitizer" FORCE)
- endforeach()
+ set(ECM_ENABLE_SANITIZERS "${enabled_sanitizer_features}" PARENT_SCOPE)
endif()
endfunction()