qt5base-lts/cmake/QtHeadersClean.cmake

283 lines
12 KiB
CMake
Raw Normal View History

# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
# Add a custom ${module_target}_headersclean_check target that builds each header in
# ${module_headers} with a custom set of defines. This makes sure our public headers
# are self-contained, and also compile with more strict compiler options.
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
function(qt_internal_add_headersclean_target module_target module_headers)
get_target_property(no_headersclean_check ${module_target} _qt_no_headersclean_check)
if(no_headersclean_check)
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
return()
endif()
set(hclean_headers "")
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
foreach(header IN LISTS module_headers)
get_filename_component(header_name "${header}" NAME)
if(header_name MATCHES "^q[^_]+\\.h$" AND NOT header_name MATCHES ".*(global|exports)\\.h")
list(APPEND hclean_headers "${header}")
endif()
endforeach()
# Make sure that the header compiles with our strict options
set(hcleanDEFS -DQT_NO_CAST_TO_ASCII
-DQT_NO_CAST_FROM_ASCII
-DQT_NO_URL_CAST_FROM_STRING
-DQT_NO_CAST_FROM_BYTEARRAY
-DQT_NO_KEYWORDS
-DQT_TYPESAFE_FLAGS
-DQT_USE_QSTRINGBUILDER
-DQT_USE_FAST_OPERATOR_PLUS)
set(compiler_to_run "${CMAKE_CXX_COMPILER}")
if(CMAKE_CXX_COMPILER_LAUNCHER)
list(PREPEND compiler_to_run "${CMAKE_CXX_COMPILER_LAUNCHER}")
endif()
CMake: Fix headersclean interaction with header only modules Before CMake 3.19, we are not allowed to query non INTERFACE_ prefixed property names from INTERFACE libraries. And it was the wrong thing to do as well. Prefix the properties with INTERFACE_ as appropriate. Don't try to add INTERFACE_COMPILE_DEFINITIONS from header only modules to the headerclean compile commands. This causes configuration issues with UiPlugin in qttools. Fortunately it seems that qmake doesn't do that for 'header_module's either. Finally don't query for the FRAMEWORK property on the passed target (INTERFACE libs can't be frameworks). Instead just query if the whole Qt build itself is a framework build. An issue was discovered regarding QT_NO_ENTRYPOINT genexes breaking headersclean add_custom_commands for UiPlugin in qttools. To avoid this the property was renamed to all lower case in 6ca66de9120537134b63d42de6c53c6e5834e8f3. This avoided the immediate issue, but it's possible it might resurface in the future with a different property name that wasn't renamed. In particular I thought it might happen with QT_NO_UTF8_SOURCE but it didn't. In case something like that happens again, the two possible solutions are to bump minimum CMake version requirement to 3.19 (where upper case property names are allowed to be queried from INTERFACE libs) or to implement recursive include directory fetching similar to our qt_internal_walk_libs implementation. Pick-to: 6.0 Task-number: QTBUG-86053 Task-number: QTBUG-82615 Change-Id: I7815d555ec9ea049a8fd40f2a2f072dcb9f5e9c3 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-11-06 15:14:46 +00:00
set(prop_prefix "")
get_target_property(target_type "${module_target}" TYPE)
CMake: Fix headersclean interaction with header only modules Before CMake 3.19, we are not allowed to query non INTERFACE_ prefixed property names from INTERFACE libraries. And it was the wrong thing to do as well. Prefix the properties with INTERFACE_ as appropriate. Don't try to add INTERFACE_COMPILE_DEFINITIONS from header only modules to the headerclean compile commands. This causes configuration issues with UiPlugin in qttools. Fortunately it seems that qmake doesn't do that for 'header_module's either. Finally don't query for the FRAMEWORK property on the passed target (INTERFACE libs can't be frameworks). Instead just query if the whole Qt build itself is a framework build. An issue was discovered regarding QT_NO_ENTRYPOINT genexes breaking headersclean add_custom_commands for UiPlugin in qttools. To avoid this the property was renamed to all lower case in 6ca66de9120537134b63d42de6c53c6e5834e8f3. This avoided the immediate issue, but it's possible it might resurface in the future with a different property name that wasn't renamed. In particular I thought it might happen with QT_NO_UTF8_SOURCE but it didn't. In case something like that happens again, the two possible solutions are to bump minimum CMake version requirement to 3.19 (where upper case property names are allowed to be queried from INTERFACE libs) or to implement recursive include directory fetching similar to our qt_internal_walk_libs implementation. Pick-to: 6.0 Task-number: QTBUG-86053 Task-number: QTBUG-82615 Change-Id: I7815d555ec9ea049a8fd40f2a2f072dcb9f5e9c3 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-11-06 15:14:46 +00:00
if(target_type STREQUAL "INTERFACE_LIBRARY")
set(prop_prefix "INTERFACE_")
endif()
set(target_includes_genex
"$<TARGET_PROPERTY:${module_target},${prop_prefix}INCLUDE_DIRECTORIES>")
set(includes_exist_genex "$<BOOL:${target_includes_genex}>")
set(target_includes_joined_genex
"$<${includes_exist_genex}:-I$<JOIN:${target_includes_genex},;-I>>")
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
if(is_multi_config)
list(GET CMAKE_CONFIGURATION_TYPES 0 first_config_type)
set(config_suffix "$<$<NOT:$<CONFIG:${first_config_type}>>:-$<CONFIG>>")
endif()
CMake: Fix headersclean interaction with header only modules Before CMake 3.19, we are not allowed to query non INTERFACE_ prefixed property names from INTERFACE libraries. And it was the wrong thing to do as well. Prefix the properties with INTERFACE_ as appropriate. Don't try to add INTERFACE_COMPILE_DEFINITIONS from header only modules to the headerclean compile commands. This causes configuration issues with UiPlugin in qttools. Fortunately it seems that qmake doesn't do that for 'header_module's either. Finally don't query for the FRAMEWORK property on the passed target (INTERFACE libs can't be frameworks). Instead just query if the whole Qt build itself is a framework build. An issue was discovered regarding QT_NO_ENTRYPOINT genexes breaking headersclean add_custom_commands for UiPlugin in qttools. To avoid this the property was renamed to all lower case in 6ca66de9120537134b63d42de6c53c6e5834e8f3. This avoided the immediate issue, but it's possible it might resurface in the future with a different property name that wasn't renamed. In particular I thought it might happen with QT_NO_UTF8_SOURCE but it didn't. In case something like that happens again, the two possible solutions are to bump minimum CMake version requirement to 3.19 (where upper case property names are allowed to be queried from INTERFACE libs) or to implement recursive include directory fetching similar to our qt_internal_walk_libs implementation. Pick-to: 6.0 Task-number: QTBUG-86053 Task-number: QTBUG-82615 Change-Id: I7815d555ec9ea049a8fd40f2a2f072dcb9f5e9c3 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-11-06 15:14:46 +00:00
# qmake doesn't seem to add the defines that are set by the header_only_module when checking the
# the cleanliness of the module's header files.
# This allows us to bypass an error with CMake 3.18 and lower when trying to evaluate
# genex-enhanced compile definitions. An example of that is in
# qttools/src/designer/src/uiplugin/CMakeLists.txt which ends up causing the following error
# message:
# CMake Error at qtbase/cmake/QtModuleHelpers.cmake:35 (add_library):
# INTERFACE_LIBRARY targets may only have whitelisted properties. The
# property "QT_PLUGIN_CLASS_NAME" is not allowed.
# Call Stack (most recent call first):
# src/designer/src/uiplugin/CMakeLists.txt:7 (qt_internal_add_module)
if(NOT target_type STREQUAL "INTERFACE_LIBRARY")
set(target_defines_genex
"$<TARGET_PROPERTY:${module_target},${prop_prefix}COMPILE_DEFINITIONS>")
set(defines_exist_genex "$<BOOL:${target_defines_genex}>")
set(target_defines_joined_genex
"$<${defines_exist_genex}:-D$<JOIN:${target_defines_genex},;-D>>")
endif()
# TODO: FIXME
# Passing COMPILE_OPTIONS can break add_custom_command() if the values contain genexes
# that add_custom_command does not support.
#
# Such a case happens on Linux where libraries linking against Threads::Threads bring in a
# '<$<COMPILE_LANG_AND_ID:CUDA,NVIDIA>' genex.
#
# If this is really required for headersclean (and qmake's headerclean implementation does
# actually pass all flags of the associated target), we'll have to replace the genex usage
# with an implementation that recursively processes a target's dependencies property
# to compile an expanded list of values for COMPILE_OPTIONS, and then filter out any genexes.
#
# This is similar to the proposed workaround at
# https://gitlab.kitware.com/cmake/cmake/-/issues/21074#note_814979
#
# See also https://gitlab.kitware.com/cmake/cmake/-/issues/21336
#
#set(target_compile_options_genex "$<TARGET_PROPERTY:${module_target},COMPILE_OPTIONS>")
#set(compile_options_exist_genex "$<BOOL:${target_compile_options_genex}>")
#set(target_compile_options_joined_genex
# "$<${compile_options_exist_genex}:$<JOIN:${target_compile_options_genex},;>>")
CMake: Fix headersclean interaction with header only modules Before CMake 3.19, we are not allowed to query non INTERFACE_ prefixed property names from INTERFACE libraries. And it was the wrong thing to do as well. Prefix the properties with INTERFACE_ as appropriate. Don't try to add INTERFACE_COMPILE_DEFINITIONS from header only modules to the headerclean compile commands. This causes configuration issues with UiPlugin in qttools. Fortunately it seems that qmake doesn't do that for 'header_module's either. Finally don't query for the FRAMEWORK property on the passed target (INTERFACE libs can't be frameworks). Instead just query if the whole Qt build itself is a framework build. An issue was discovered regarding QT_NO_ENTRYPOINT genexes breaking headersclean add_custom_commands for UiPlugin in qttools. To avoid this the property was renamed to all lower case in 6ca66de9120537134b63d42de6c53c6e5834e8f3. This avoided the immediate issue, but it's possible it might resurface in the future with a different property name that wasn't renamed. In particular I thought it might happen with QT_NO_UTF8_SOURCE but it didn't. In case something like that happens again, the two possible solutions are to bump minimum CMake version requirement to 3.19 (where upper case property names are allowed to be queried from INTERFACE libs) or to implement recursive include directory fetching similar to our qt_internal_walk_libs implementation. Pick-to: 6.0 Task-number: QTBUG-86053 Task-number: QTBUG-82615 Change-Id: I7815d555ec9ea049a8fd40f2a2f072dcb9f5e9c3 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-11-06 15:14:46 +00:00
set(target_compile_flags_genex
"$<TARGET_PROPERTY:${module_target},${prop_prefix}COMPILE_FLAGS>")
set(compile_flags_exist_genex "$<BOOL:${target_compile_flags_genex}>")
set(target_compile_flags_joined_genex
"$<${compile_flags_exist_genex}:$<JOIN:${target_compile_flags_genex},;>>")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU"
OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang|IntelLLVM")
# Turn on some extra warnings not found in -Wall -Wextra.
set(hcleanFLAGS -Wall -Wextra -Werror -Woverloaded-virtual -Wshadow -Wundef -Wfloat-equal
-Wnon-virtual-dtor -Wpointer-arith -Wformat-security -Wno-long-long -Wno-variadic-macros
-fno-operator-names
-pedantic-errors)
if(QT_FEATURE_reduce_relocations AND UNIX)
list(APPEND hcleanFLAGS -fPIC)
endif()
# options accepted by GCC and Clang
list(APPEND hcleanFLAGS -Wchar-subscripts -Wold-style-cast)
if (NOT ((TEST_architecture_arch STREQUAL arm)
OR (TEST_architecture_arch STREQUAL mips)))
list(APPEND hcleanFLAGS -Wcast-align)
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
list(APPEND hcleanFLAGS -Wzero-as-null-pointer-constant)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.5)
list(APPEND hcleanFLAGS -Wdouble-promotion)
endif()
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9)
list(APPEND hcleanFLAGS -Wfloat-conversion)
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang|IntelLLVM")
list(APPEND hcleanFLAGS -Wshorten-64-to-32)
endif()
# Use strict mode C++20, with no GNU extensions (see -pedantic-errors above).
list(APPEND hcleanFLAGS -std=c++2a)
separate_arguments(cxx_flags NATIVE_COMMAND ${CMAKE_CXX_FLAGS})
if(APPLE AND CMAKE_OSX_SYSROOT)
list(APPEND cxx_flags "${CMAKE_CXX_SYSROOT_FLAG}" "${CMAKE_OSX_SYSROOT}")
endif()
CMake: Fix headersclean interaction with header only modules Before CMake 3.19, we are not allowed to query non INTERFACE_ prefixed property names from INTERFACE libraries. And it was the wrong thing to do as well. Prefix the properties with INTERFACE_ as appropriate. Don't try to add INTERFACE_COMPILE_DEFINITIONS from header only modules to the headerclean compile commands. This causes configuration issues with UiPlugin in qttools. Fortunately it seems that qmake doesn't do that for 'header_module's either. Finally don't query for the FRAMEWORK property on the passed target (INTERFACE libs can't be frameworks). Instead just query if the whole Qt build itself is a framework build. An issue was discovered regarding QT_NO_ENTRYPOINT genexes breaking headersclean add_custom_commands for UiPlugin in qttools. To avoid this the property was renamed to all lower case in 6ca66de9120537134b63d42de6c53c6e5834e8f3. This avoided the immediate issue, but it's possible it might resurface in the future with a different property name that wasn't renamed. In particular I thought it might happen with QT_NO_UTF8_SOURCE but it didn't. In case something like that happens again, the two possible solutions are to bump minimum CMake version requirement to 3.19 (where upper case property names are allowed to be queried from INTERFACE libs) or to implement recursive include directory fetching similar to our qt_internal_walk_libs implementation. Pick-to: 6.0 Task-number: QTBUG-86053 Task-number: QTBUG-82615 Change-Id: I7815d555ec9ea049a8fd40f2a2f072dcb9f5e9c3 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-11-06 15:14:46 +00:00
if(APPLE AND QT_FEATURE_framework)
# For some reason CMake doesn't generate -iframework flags from the INCLUDE_DIRECTORIES
# generator expression we provide, so pass it explicitly and hope for the best.
CMake: Fix headersclean interaction with header only modules Before CMake 3.19, we are not allowed to query non INTERFACE_ prefixed property names from INTERFACE libraries. And it was the wrong thing to do as well. Prefix the properties with INTERFACE_ as appropriate. Don't try to add INTERFACE_COMPILE_DEFINITIONS from header only modules to the headerclean compile commands. This causes configuration issues with UiPlugin in qttools. Fortunately it seems that qmake doesn't do that for 'header_module's either. Finally don't query for the FRAMEWORK property on the passed target (INTERFACE libs can't be frameworks). Instead just query if the whole Qt build itself is a framework build. An issue was discovered regarding QT_NO_ENTRYPOINT genexes breaking headersclean add_custom_commands for UiPlugin in qttools. To avoid this the property was renamed to all lower case in 6ca66de9120537134b63d42de6c53c6e5834e8f3. This avoided the immediate issue, but it's possible it might resurface in the future with a different property name that wasn't renamed. In particular I thought it might happen with QT_NO_UTF8_SOURCE but it didn't. In case something like that happens again, the two possible solutions are to bump minimum CMake version requirement to 3.19 (where upper case property names are allowed to be queried from INTERFACE libs) or to implement recursive include directory fetching similar to our qt_internal_walk_libs implementation. Pick-to: 6.0 Task-number: QTBUG-86053 Task-number: QTBUG-82615 Change-Id: I7815d555ec9ea049a8fd40f2a2f072dcb9f5e9c3 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2020-11-06 15:14:46 +00:00
list(APPEND framework_includes
"-iframework" "${QT_BUILD_INTERNALS_RELOCATABLE_INSTALL_PREFIX}/${INSTALL_LIBDIR}")
# If additional package prefixes are provided, we consider they can contain frameworks
# as well.
foreach(prefix IN LISTS _qt_additional_packages_prefix_paths)
if(prefix MATCHES "/lib/cmake$") # Cut CMake files path
string(APPEND prefix "/../..")
endif()
get_filename_component(prefix "${prefix}" ABSOLUTE)
set(libdir "${prefix}/${INSTALL_LIBDIR}")
if(EXISTS "${libdir}")
list(APPEND framework_includes
"-iframework" "${libdir}")
endif()
endforeach()
endif()
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
set(compiler_command_line
"${compiler_to_run}" "-c" "${cxx_flags}"
"${target_compile_flags_joined_genex}"
"${target_defines_joined_genex}"
"${hcleanFLAGS}"
"${target_includes_joined_genex}"
"${framework_includes}"
"${hcleanDEFS}"
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
)
string(JOIN " " compiler_command_line_variables
"-xc++"
"\${INPUT_HEADER_FILE}"
"-o"
"\${OUTPUT_ARTIFACT}"
)
set(input_header_path_type ABSOLUTE)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(hcleanFLAGS -std:c++latest -Zc:__cplusplus -Za -WX -W3 -EHsc)
# cl.exe needs a source path
get_filename_component(source_path "${QT_MKSPECS_DIR}/features/data/dummy.cpp" REALPATH)
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
set(compiler_command_line
"${compiler_to_run}" "-nologo" "-c" "${CMAKE_CXX_FLAGS}"
"${target_compile_flags_joined_genex}"
"${target_defines_joined_genex}"
"${hcleanFLAGS}"
"${target_includes_joined_genex}"
"${hcleanDEFS}"
)
string(JOIN " " compiler_command_line_variables
"-FI"
"\${INPUT_HEADER_FILE}"
"-Fo\${OUTPUT_ARTIFACT}"
"${source_path}"
)
set(input_header_path_type REALPATH)
else()
message(FATAL_ERROR "CMAKE_CXX_COMPILER_ID \"${CMAKE_CXX_COMPILER_ID}\" is not supported"
" for the headersclean check.")
endif()
qt_internal_module_info(module ${module_target})
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
unset(header_check_exceptions)
set(header_check_exceptions
"${CMAKE_CURRENT_BINARY_DIR}/${module}_header_check_exceptions")
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
set(headers_check_parameters
"${CMAKE_CURRENT_BINARY_DIR}/${module_target}HeadersCheckParameters${config_suffix}.cmake")
string(JOIN "\n" headers_check_parameters_content
"set(HEADER_CHECK_EXCEPTIONS"
" \"${header_check_exceptions}\")"
"set(HEADER_CHECK_COMPILER_COMMAND_LINE"
" \[\[$<JOIN:${compiler_command_line},\]\]\n \[\[>\]\]\n"
" ${compiler_command_line_variables}"
")"
)
file(GENERATE OUTPUT "${headers_check_parameters}"
CONTENT "${headers_check_parameters_content}")
set(sync_headers_dep "${module_target}_sync_headers")
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
foreach(header ${hclean_headers})
# We need realpath here to make sure path starts with drive letter
get_filename_component(input_path "${header}" ${input_header_path_type})
get_filename_component(input_file_name ${input_path} NAME)
set(artifact_path "${CMAKE_CURRENT_BINARY_DIR}/header_check/${input_file_name}.o")
unset(input_base_dir)
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
if(input_path MATCHES "${CMAKE_BINARY_DIR}")
set(input_base_dir "${CMAKE_BINARY_DIR}")
elseif(input_path MATCHES "${CMAKE_SOURCE_DIR}")
set(input_base_dir "${CMAKE_SOURCE_DIR}")
endif()
if(input_base_dir AND IS_ABSOLUTE "${input_base_dir}" AND IS_ABSOLUTE "${input_path}")
file(RELATIVE_PATH comment_header_path "${input_base_dir}" "${input_path}")
else()
set(comment_header_path "${input_path}")
endif()
Replace the syncqt.pl script with syncqt tool syncqt.pl adds an extra dependency on perl when building Qt. Modern C++ provides the convenient cross-platform way to access a filesystem and to use regular expressions, so we may replace the perl script with C++ application. The syncqt executable is built at configure time and installed as QtCore tool. It's running at configure time to deliver the required header files for IDE to build a consistent code model and at the build time to keep tracking changes in header files and generate the missing aliases without reconfiguring. 'syncqt' only parses header files from a CMake build tree, so the resulting Qt installation only contains interfacing headers that belong to the platform that Qt is built for. 'sync.profile' files are not used as the 'source of truth' for sync qt procedure anymore, all the necessary information is taken from either CMake files at configure time or from the module header files while parsing them. syncqt.pl is still in place since it's required as fallback solution for a smooth transition to the new syncqt implementation for all qt repositories. This patchset only enables the C++ based syncqt for 'qtbase' repository. From the performance perspective C++ version works faster then perl script, also the configure time is reduced significally on subsequent reconfigurations - up x2 times faster when re-configuring repository, but it also takes time to compile the tool itself the first time. Numbers for qtbase: syncqt.pl syncqt.cpp initial: 0m16,035s 0m20,413s reconfig: 0m6,819s 0m3,725s The syncing procedure can be run separately for each module using <ModuleName>_sync_headers targets. The 'sync_headers' target can be used to sync all the modules at once. Task-number: QTBUG-87480 Task-number: QTBUG-103196 Change-Id: I8c938bcaf88a8713b39bbfd66d9e7ef12b2c3523 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-08-15 16:29:41 +00:00
add_custom_command(
OUTPUT "${artifact_path}"
COMMENT "headersclean: Checking header ${comment_header_path}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/header_check"
COMMAND ${CMAKE_COMMAND}
-DINPUT_HEADER_FILE=${input_path}
-DOUTPUT_ARTIFACT=${artifact_path}
-DPARAMETERS=${headers_check_parameters}
-P "${QT_CMAKE_DIR}/QtModuleHeadersCheck.cmake"
IMPLICIT_DEPENDS CXX
VERBATIM
COMMAND_EXPAND_LISTS
DEPENDS
${headers_check_parameters}
${sync_headers_dep}
${input_path}
${header_check_exceptions}
)
list(APPEND hclean_artifacts "${artifact_path}")
endforeach()
add_custom_target(${module_target}_headersclean_check
COMMENT "headersclean: Checking headers in ${module}"
DEPENDS ${hclean_artifacts}
VERBATIM)
if(NOT TARGET headersclean_check)
add_custom_target(headersclean_check ALL)
endif()
add_dependencies(headersclean_check ${module_target}_headersclean_check)
endfunction()