From b23f915fe4269fd3a100176c09928c96210ff47b Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Tue, 24 Sep 2024 15:20:00 +0200 Subject: [PATCH] Attempt checking the CMAKE_GENERATOR when passing hardening flags Use the _qt_internal_cmake_generator of the PlatformCommonInternal to store the current CMake generator is used. The property allows checking the CMake generator as part of transitively propagated properties, like those we use in PlatformCommonInternal. Wrap the compile definisions belonging to libcpp_hardening feature with CMake generator check, since Xcode sets own definitions which lead to the macro 'redefinition' compilation warning. Change-Id: I5f6131245746afbe413efc831a9447ba40142a4e Reviewed-by: Alexandru Croitor --- cmake/QtConfig.cmake.in | 13 +++++++++++++ cmake/QtInternalTargets.cmake | 20 +++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in index b5a21e391d1..5c3e79a5b7c 100644 --- a/cmake/QtConfig.cmake.in +++ b/cmake/QtConfig.cmake.in @@ -33,6 +33,19 @@ else() QT_VERSION_PATCH @PROJECT_VERSION_PATCH@) endif() +if(TARGET @INSTALL_CMAKE_NAMESPACE@::PlatformCommonInternal) + get_target_property(_qt_platform_internal_common_target + @INSTALL_CMAKE_NAMESPACE@::PlatformCommonInternal ALIASED_TARGET) + if(NOT _qt_platform_internal_common_target) + set(_qt_platform_internal_common_target @INSTALL_CMAKE_NAMESPACE@::PlatformCommonInternal) + endif() + set_target_properties(${_qt_platform_internal_common_target} + PROPERTIES + _qt_internal_cmake_generator "${CMAKE_GENERATOR}" + ) + unset(_qt_platform_internal_common_target) +endif() + get_filename_component(_qt_import_prefix "${CMAKE_CURRENT_LIST_FILE}" PATH) get_filename_component(_qt_import_prefix "${_qt_import_prefix}" REALPATH) list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}") diff --git a/cmake/QtInternalTargets.cmake b/cmake/QtInternalTargets.cmake index 012c355c015..3eb534293c2 100644 --- a/cmake/QtInternalTargets.cmake +++ b/cmake/QtInternalTargets.cmake @@ -347,7 +347,25 @@ if(QT_FEATURE_libstdcpp_assertions) endif() if(QT_FEATURE_libcpp_hardening) - target_compile_definitions(PlatformCommonInternal INTERFACE -D_LIBCPP_HARDENING_MODE=$,_LIBCPP_HARDENING_MODE_EXTENSIVE,_LIBCPP_HARDENING_MODE_FAST>) + string(JOIN "" hardening_flags + "$<$," + "Xcode" + ">>:" + "_LIBCPP_HARDENING_MODE=$," + "_LIBCPP_HARDENING_MODE_EXTENSIVE," + "_LIBCPP_HARDENING_MODE_FAST" + ">" + ">" + ) + set_target_properties(PlatformCommonInternal + PROPERTIES + _qt_internal_cmake_generator "${CMAKE_GENERATOR}" + ) + target_compile_definitions(PlatformCommonInternal INTERFACE "${hardening_flags}") endif() if(QT_FEATURE_relro_now_linker)