diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-06-24 12:30:32 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2021-06-25 12:33:58 +0200 |
commit | 19816826873ebb3a89b2173f8685a8d448410680 (patch) | |
tree | 15a7b4f158f4736b43ac10b0a881d80b3d8d7dcf /cmake/QtBaseGlobalTargets.cmake | |
parent | 9a9da3aad2e59ed9f1f7e8210a6bd5de741d9e7c (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/QtBaseGlobalTargets.cmake')
-rw-r--r-- | cmake/QtBaseGlobalTargets.cmake | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index 79e9518233..aab7646b25 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -21,28 +21,6 @@ file(RELATIVE_PATH __GlobalConfig_relative_path_from_bin_dir_to_cmake_config_dir ${__qt_bin_dir_absolute} ${__GlobalConfig_install_dir_absolute}) -# Generate and install Qt6 config file. -qt_internal_get_min_new_policy_cmake_version(min_new_policy_version) -qt_internal_get_max_new_policy_cmake_version(max_new_policy_version) -configure_package_config_file( - "${PROJECT_SOURCE_DIR}/cmake/QtConfig.cmake.in" - "${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}Config.cmake" - INSTALL_DESTINATION "${__GlobalConfig_install_dir}" -) - -write_basic_package_version_file( - ${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}ConfigVersion.cmake - VERSION ${PROJECT_VERSION} - COMPATIBILITY AnyNewerVersion -) - -qt_install(FILES - "${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}Config.cmake" - "${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}ConfigVersion.cmake" - DESTINATION "${__GlobalConfig_install_dir}" - COMPONENT Devel -) - # Configure and install the QtBuildInternals package. set(__build_internals_path_suffix "${INSTALL_CMAKE_NAMESPACE}BuildInternals") qt_path_join(__build_internals_build_dir ${QT_CONFIG_BUILD_DIR} ${__build_internals_path_suffix}) @@ -141,6 +119,10 @@ qt_internal_setup_public_platform_target() include(QtInternalTargets) qt_internal_run_common_config_tests() +# Setup sanitizer options for qtbase directory scope based on features computed above. +qt_internal_set_up_sanitizer_options() +include("${CMAKE_CURRENT_LIST_DIR}/3rdparty/extra-cmake-modules/modules/ECMEnableSanitizers.cmake") + set(__export_targets Platform GlobalConfig GlobalConfigPrivate @@ -160,6 +142,29 @@ qt_internal_export_modern_cmake_config_targets_file(TARGETS ${__export_targets} CONFIG_INSTALL_DIR ${__GlobalConfig_install_dir}) +# Generate and install Qt6 config file. Make sure it happens after the global feature evaluation so +# they can be accessed in the Config file if needed. +qt_internal_get_min_new_policy_cmake_version(min_new_policy_version) +qt_internal_get_max_new_policy_cmake_version(max_new_policy_version) +configure_package_config_file( + "${PROJECT_SOURCE_DIR}/cmake/QtConfig.cmake.in" + "${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}Config.cmake" + INSTALL_DESTINATION "${__GlobalConfig_install_dir}" +) + +write_basic_package_version_file( + "${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}ConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion +) + +qt_install(FILES + "${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}Config.cmake" + "${__GlobalConfig_build_dir}/${INSTALL_CMAKE_NAMESPACE}ConfigVersion.cmake" + DESTINATION "${__GlobalConfig_install_dir}" + COMPONENT Devel +) + # Install internal CMake files. # The functions defined inside can not be used in public projects. # They can only be used while building Qt itself. @@ -271,7 +276,13 @@ if(QT_WILL_INSTALL) endif() # TODO: Check whether this is the right place to install these -qt_copy_or_install(DIRECTORY cmake/3rdparty DESTINATION "${__GlobalConfig_install_dir}") +qt_copy_or_install(DIRECTORY "cmake/3rdparty" DESTINATION "${__GlobalConfig_install_dir}") + +# In prefix builds we also need to copy the files into the build config directory, so that the +# build-dir Qt6Config.cmake finds the files when building other repos in a top-level build. +if(QT_WILL_INSTALL) + file(COPY "cmake/3rdparty" DESTINATION "${__GlobalConfig_build_dir}") +endif() # Install our custom Find modules, which will be used by the find_dependency() calls # inside the generated ModuleDependencies cmake files. |