From 57c1e8d5339979cf124f28c58adc87c3d91a7fc2 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Fri, 11 Mar 2022 12:41:36 +0100 Subject: [PATCH] build system: support module local definitions This introduces a new helper function, qt_internal_add_repo_local_defines and makes use of it in qt_internal_add_{module,test,executable,benchmark,plugin}. That function checks whether QT_EXTRA_INTERNAL_TARGET_DEFINES is set. If it is, the defines listed in there will be aded to all targets passed to the functions mentioned above. The intended usage is that QT_EXTRA_INTERNAL_TARGET_DEFINES gets set in the repository local .cmake.conf. This allows e.g. opting in to source incompatible changes in leaf modules (as long as those are guarded by some define). Pick-to: 6.2 6.3 Fixes: QTBUG-101640 Change-Id: I06c3693ee69f46e95a48de724621f0c97e7cc3a8 Reviewed-by: Alexandru Croitor --- cmake/QtExecutableHelpers.cmake | 3 +++ cmake/QtModuleHelpers.cmake | 2 ++ cmake/QtPluginHelpers.cmake | 2 ++ cmake/QtTargetHelpers.cmake | 16 ++++++++++++++++ cmake/QtTestHelpers.cmake | 5 +++++ 5 files changed, 28 insertions(+) diff --git a/cmake/QtExecutableHelpers.cmake b/cmake/QtExecutableHelpers.cmake index f70adad11a5..3c6a1462eb0 100644 --- a/cmake/QtExecutableHelpers.cmake +++ b/cmake/QtExecutableHelpers.cmake @@ -70,6 +70,9 @@ function(qt_internal_add_executable name) endif() qt_set_common_target_properties(${name}) + + qt_internal_add_repo_local_defines(${name}) + if(ANDROID) # The above call to qt_set_common_target_properties() sets the symbol # visibility to hidden, but for Android, we need main() to not be hidden diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake index d72cd545644..fdbd5cbc9e6 100644 --- a/cmake/QtModuleHelpers.cmake +++ b/cmake/QtModuleHelpers.cmake @@ -510,6 +510,8 @@ function(qt_internal_add_module target) list(APPEND arg_LIBRARIES Qt::PlatformModuleInternal) endif() + qt_internal_add_repo_local_defines("${target}") + qt_internal_extend_target("${target}" ${header_module} SOURCES ${arg_SOURCES} diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake index fe90a33b85f..7023e705e87 100644 --- a/cmake/QtPluginHelpers.cmake +++ b/cmake/QtPluginHelpers.cmake @@ -329,6 +329,8 @@ function(qt_internal_add_plugin target) DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS} ) + qt_internal_add_repo_local_defines("${target}") + qt_internal_set_exceptions_flags("${target}" ${arg_EXCEPTIONS}) diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake index d26e84ce16c..9640287ea90 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -874,3 +874,19 @@ function(qt_internal_undefine_global_definition target) set_target_properties(${target} PROPERTIES "${undef_property_name}" TRUE) endforeach() endfunction() + +# This function adds any defines which are local to the current repository (e.g. qtbase, +# qtmultimedia). Those can be defined in the corresponding .cmake.conf file via +# QT_EXTRA_INTERNAL_TARGET_DEFINES. QT_EXTRA_INTERNAL_TARGET_DEFINES accepts a list of definitions. +# The definitions are passed to target_compile_definitions, which means that values can be provided +# via the FOO=Bar syntax +# This does nothing for interface targets +function(qt_internal_add_repo_local_defines target) + get_target_property(type "${target}" TYPE) + if (${type} STREQUAL "INTERFACE_LIBRARY") + return() + endif() + if(DEFINED QT_EXTRA_INTERNAL_TARGET_DEFINES) + target_compile_definitions("${target}" PRIVATE ${QT_EXTRA_INTERNAL_TARGET_DEFINES}) + endif() +endfunction() diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake index c8a8d91fd78..149780ca291 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -33,6 +33,9 @@ function(qt_internal_add_benchmark target) ${exec_args} ) + + qt_internal_add_repo_local_defines(${target}) + # Disable the QT_NO_NARROWING_CONVERSIONS_IN_CONNECT define for benchmarks qt_internal_undefine_global_definition(${target} QT_NO_NARROWING_CONVERSIONS_IN_CONNECT) @@ -264,6 +267,8 @@ function(qt_internal_add_test name) DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS} ) + qt_internal_add_repo_local_defines(${name}) + # Disable the QT_NO_NARROWING_CONVERSIONS_IN_CONNECT define for tests qt_internal_undefine_global_definition(${name} QT_NO_NARROWING_CONVERSIONS_IN_CONNECT)