From 58be29388d54f198beeaf17bbec90d9b329244cc Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 12 Mar 2025 09:28:35 +0100 Subject: [PATCH] CMake: Warn on creation of private modules without private headers Private modules without private headers don't make much sense and needlessly create CMake packages and QMake module pri files. In qt_finalize_module we check whether the module has any private headers. But the private module was already created before in qt_internal_add_module. Moving the creation of the private module or the CMake package files to the finalization phase would be a bigger refactoring that's probably not worth the hassle. An easier way to avoid the package creation issue is to mandate that a Qt module must be created with NO_PRIVATE_MODULE if it doesn't have any private headers. Add a warning if a Qt module without private headers is created without NO_PRIVATE_MODULE. Also warn if a Qt module with private headers is created with NO_PRIVATE_MODULE. This allows us to easily spot the places where NO_PRIVATE_MODULE is missing. Task-number: QTBUG-132526 Change-Id: I897f25790a99eaa320c39cd8c2728f26bceb824e Reviewed-by: Alexandru Croitor --- cmake/QtModuleHelpers.cmake | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake index d4c368e36b3..a5ab9ec2bff 100644 --- a/cmake/QtModuleHelpers.cmake +++ b/cmake/QtModuleHelpers.cmake @@ -1147,8 +1147,37 @@ function(qt_internal_apply_apple_privacy_manifest target) endfunction() function(qt_finalize_module target) + set(no_value_options + INTERNAL_MODULE + NO_PRIVATE_MODULE + ) + set(single_value_options "") + set(multi_value_options "") + cmake_parse_arguments(PARSE_ARGV 1 arg + "${no_value_options}" "${single_value_options}" "${multi_value_options}" + ) + _qt_internal_validate_all_args_are_parsed(arg) + qt_internal_collect_module_headers(module_headers ${target}) + # Issue a warning if we + # - suppressed creation of the private module but have private headers + # - created a private module but don't have any private headers + if(NOT arg_INTERNAL_MODULE) + get_target_property(has_private_headers ${target} _qt_module_has_private_headers) + if(arg_NO_PRIVATE_MODULE AND has_private_headers) + message(AUTHOR_WARNING + "Module ${target} has private headers. " + "Please remove NO_PRIVATE_MODULE from its creation flags." + ) + elseif(NOT arg_NO_PRIVATE_MODULE AND NOT has_private_headers) + message(AUTHOR_WARNING + "Module ${target} does not have private headers. " + "Please add NO_PRIVATE_MODULE to its creation flags." + ) + endif() + endif() + # qt_internal_install_module_headers needs to be called before # qt_finalize_framework_headers_copy, because the last uses the QT_COPIED_FRAMEWORK_HEADERS # property which supposed to be updated inside every qt_internal_install_module_headers