diff options
author | Alexey Edelev <alexey.edelev@qt.io> | 2022-11-03 16:38:51 +0100 |
---|---|---|
committer | Alexey Edelev <alexey.edelev@qt.io> | 2022-12-08 23:24:22 +0100 |
commit | 2e514f85111ec1ecd8b6f6a5c48edcf43647a006 (patch) | |
tree | 73d172146ca2d3b230e6a1c4fc5b4eab52a665c1 /cmake | |
parent | 050b849c9664ba15cbe4a6ec176fec217f276094 (diff) | |
download | qtbase-2e514f85111ec1ecd8b6f6a5c48edcf43647a006.tar.gz |
Add CONDITION_INDEPENDENT_SOURCES argument to qt_internal_extend_target
The argument allows to ignore the condition for source files if they
are used in the Qt code without corresponding guards. The header files
of this kind usually have internal guards, that suppress the error
at the location where they are used, so AUTOGEN is skipped for these
header files to suppress the warnings from CMake. If file belongs to
a module, it will display AUTHOR_WARNING which should urge Qt
maintainers to guard the use of the source file properly.
Task-number: QTBUG-103196
Change-Id: I7b4c12031a5d19ff15868d4782c0d396ef7aed8c
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/QtModuleHelpers.cmake | 21 | ||||
-rw-r--r-- | cmake/QtTargetHelpers.cmake | 15 |
2 files changed, 36 insertions, 0 deletions
diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake index 563482c378..59340222bb 100644 --- a/cmake/QtModuleHelpers.cmake +++ b/cmake/QtModuleHelpers.cmake @@ -1125,11 +1125,20 @@ function(qt_internal_collect_module_headers out_var target) get_target_property(private_filter ${target} _qt_module_private_headers_filter_regex) get_target_property(qpa_filter ${target} _qt_module_qpa_headers_filter_regex) + set(condition_independent_headers_warning "") foreach(file_path IN LISTS sources) get_filename_component(file_name "${file_path}" NAME) if(NOT file_name MATCHES ".+\\.h$") continue() endif() + get_source_file_property(condition ${file_path} _qt_extend_target_condition) + if(NOT condition STREQUAL "" AND NOT condition STREQUAL "NOTFOUND") + list(JOIN condition " " condition_string) + string(APPEND condition_independent_headers_warning + "\nFile:\n ${file_path}" + "\nCondition:\n ${condition_string}") + endif() + get_source_file_property(is_generated "${file_path}" GENERATED) get_filename_component(file_path "${file_path}" ABSOLUTE) get_filename_component(file_path "${file_path}" REALPATH) @@ -1146,6 +1155,18 @@ function(qt_internal_collect_module_headers out_var target) endif() endforeach() + if(NOT condition_independent_headers_warning STREQUAL "" AND QT_FEATURE_developer_build) + message(AUTHOR_WARNING "Condition is ignored when adding the following header file(s) to" + " the ${target} module:" + "${condition_independent_headers_warning}" + "\nThe usage of the file(s) is not properly isolated in this or other modules according" + " to the condition. This warning is for the Qt maintainers. Please make sure that file" + " include(s) are guarded with the appropriate macros in the Qt code. If files should be" + " added to the module unconditionally, please move them to the common SOURCES section" + " in the qt_internal_add_module call.") + endif() + + set(header_types public private qpa) set(has_header_types_properties "") foreach(header_type IN LISTS header_types) diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake index 4b0f176b36..cf101c1f85 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -9,6 +9,9 @@ # Multi-value Arguments: # CONDITION # The condition under which the target will be extended. +# CONDITION_INDEPENDENT_SOURCES +# Source files that should be added to the target unconditionally. Note that if target is Qt +# module, these files will raise a warning at configure time if the condition is not met. # COMPILE_FLAGS # Custom compilation flags. # NO_PCH_SOURCES @@ -37,6 +40,7 @@ function(qt_internal_extend_target target) ${__default_private_args} ${__default_private_module_args} CONDITION + CONDITION_INDEPENDENT_SOURCES COMPILE_FLAGS NO_PCH_SOURCES ) @@ -211,6 +215,17 @@ function(qt_internal_extend_target target) message("qt_extend_target(${target} CONDITION ${arg_CONDITION} ...): Skipped") endif() endif() + + if(arg_CONDITION_INDEPENDENT_SOURCES) + set_source_files_properties(${arg_CONDITION_INDEPENDENT_SOURCES} PROPERTIES + _qt_extend_target_condition "${arg_CONDITION}" + SKIP_AUTOGEN TRUE + ) + + qt_internal_get_target_sources_property(sources_property) + set_property(TARGET ${target} APPEND PROPERTY + ${sources_property} "${arg_CONDITION_INDEPENDENT_SOURCES}") + endif() endfunction() function(qt_is_imported_target target out_var) |