CMake: Dynamically include and install Helpers and other files

Instead of duplicating file names that need to be include()'ed
in two different places if the files are meant to be used
in both Qt builds and public user projects and then also mention the
name when installing, extract the file names into lists returned by
functions.

Call these functions where needed to iteratively include() the files
as well as install them, without having to remember updating multiple
code locations.

The new functions return the following list of file names:
- upstream cmake modules that need to be included during a Qt build
- public (Qt build and user project) cmake helpers that need to be
  included and installed
- private (Qt build only) cmake helpers that need to be included and
  installed
- public files that need to be installed, but not included
- private files that need to be installed, but not included

We also generate the list of public files to include in
Qt6Config.cmake.

Task-number: QTBUG-86035
Change-Id: I1e7287f4e1d041c723f144ba9626b34f873c4891
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit 8c14b0c02f3e4b06a9aa4ea7608360149be4a50f)
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Alexandru Croitor 2023-11-17 17:47:04 +01:00
parent a57412878c
commit 1b86f3c348
4 changed files with 210 additions and 190 deletions

View File

@ -169,6 +169,11 @@ qt_internal_get_computed_min_cmake_version_for_using_qt(computed_min_version_for
qt_internal_get_min_new_policy_cmake_version(min_new_policy_version)
qt_internal_get_max_new_policy_cmake_version(max_new_policy_version)
# Get the list of public helper files that should be automatically included in Qt6Config.cmake.
# Used in QtConfig.cmake.in template and further down for installation purposes.
qt_internal_get_qt_build_public_helpers(__qt_cmake_public_helpers)
list(JOIN __qt_cmake_public_helpers "\n " QT_PUBLIC_FILES_TO_INCLUDE)
# Generate and install Qt6 config file. Make sure it happens after the global feature evaluation so
# they can be accessed in the Config file if needed.
configure_package_config_file(
@ -202,99 +207,22 @@ qt_install(FILES
COMPONENT Devel
)
qt_internal_get_qt_build_private_helpers(__qt_cmake_private_helpers)
list(TRANSFORM __qt_cmake_private_helpers PREPEND "cmake/")
list(TRANSFORM __qt_cmake_private_helpers APPEND ".cmake")
qt_internal_get_qt_build_private_files_to_install(__qt_private_files_to_install)
list(TRANSFORM __qt_private_files_to_install PREPEND "cmake/")
# Install internal CMake files.
# The functions defined inside can not be used in public projects.
# They can only be used while building Qt itself.
set(__private_files
${__qt_cmake_private_helpers}
${__qt_private_files_to_install}
)
qt_copy_or_install(FILES
cmake/ModuleDescription.json.in
cmake/PkgConfigLibrary.pc.in
cmake/Qt3rdPartyLibraryConfig.cmake.in
cmake/Qt3rdPartyLibraryHelpers.cmake
cmake/QtAndroidHelpers.cmake
cmake/QtAppHelpers.cmake
cmake/QtAutogenHelpers.cmake
cmake/QtBaseTopLevelHelpers.cmake
cmake/QtBuild.cmake
cmake/QtBuildHelpers.cmake
cmake/QtBuildOptionsHelpers.cmake
cmake/QtBuildPathsHelpers.cmake
cmake/QtBuildInformation.cmake
cmake/QtBuildRepoExamplesHelpers.cmake
cmake/QtBuildRepoHelpers.cmake
cmake/QtCMakeHelpers.cmake
cmake/QtCMakeVersionHelpers.cmake
cmake/QtCMakePackageVersionFile.cmake.in
cmake/QtCompilerFlags.cmake
cmake/QtCompilerOptimization.cmake
cmake/QtConfigDependencies.cmake.in
cmake/QtConfigureTimeExecutableCMakeLists.txt.in
cmake/QtDeferredDependenciesHelpers.cmake
cmake/QtDbusHelpers.cmake
cmake/QtDocsHelpers.cmake
cmake/QtExecutableHelpers.cmake
cmake/QtFileConfigure.txt.in
cmake/QtFindPackageHelpers.cmake
cmake/QtFindWrapConfigExtra.cmake.in
cmake/QtFindWrapHelper.cmake
cmake/QtFinishPkgConfigFile.cmake
cmake/QtFinishPrlFile.cmake
cmake/QtFlagHandlingHelpers.cmake
cmake/QtFrameworkHelpers.cmake
cmake/QtGenerateExtPri.cmake
cmake/QtGenerateLibHelpers.cmake
cmake/QtGenerateLibPri.cmake
cmake/QtGenerateVersionScript.cmake
cmake/QtGlobalStateHelpers.cmake
cmake/QtHeadersClean.cmake
cmake/QtInstallHelpers.cmake
cmake/QtJavaHelpers.cmake
cmake/QtLalrHelpers.cmake
cmake/QtMkspecHelpers.cmake
cmake/QtModuleConfig.cmake.in
cmake/QtModuleDependencies.cmake.in
cmake/QtModuleHeadersCheck.cmake
cmake/QtModuleHelpers.cmake
cmake/QtModuleToolsConfig.cmake.in
cmake/QtModuleToolsDependencies.cmake.in
cmake/QtModuleToolsVersionlessTargets.cmake.in
cmake/QtNoLinkTargetHelpers.cmake
cmake/QtPkgConfigHelpers.cmake
cmake/QtPlatformAndroid.cmake
cmake/QtPlatformSupport.cmake
cmake/QtPluginConfig.cmake.in
cmake/QtPluginDependencies.cmake.in
cmake/QtPluginHelpers.cmake
cmake/QtPlugins.cmake.in
cmake/QtPostProcess.cmake
cmake/QtPostProcessHelpers.cmake
cmake/QtPrecompiledHeadersHelpers.cmake
cmake/QtUnityBuildHelpers.cmake
cmake/QtPriHelpers.cmake
cmake/QtPrlHelpers.cmake
cmake/QtPlatformTargetHelpers.cmake
cmake/QtProcessConfigureArgs.cmake
cmake/QtQmakeHelpers.cmake
cmake/QtResourceHelpers.cmake
cmake/QtRpathHelpers.cmake
cmake/QtSanitizerHelpers.cmake
cmake/QtScopeFinalizerHelpers.cmake
cmake/QtSeparateDebugInfo.Info.plist.in
cmake/QtSeparateDebugInfo.cmake
cmake/QtSetup.cmake
cmake/QtSimdHelpers.cmake
cmake/QtSingleRepoTargetSetBuildHelpers.cmake
cmake/QtStandaloneTestsConfig.cmake.in
cmake/QtSyncQtHelpers.cmake
cmake/QtTargetHelpers.cmake
cmake/QtTestHelpers.cmake
cmake/QtToolchainHelpers.cmake
cmake/QtToolHelpers.cmake
cmake/QtWasmHelpers.cmake
cmake/QtWrapperScriptHelpers.cmake
cmake/QtWriteArgsFile.cmake
cmake/modulecppexports.h.in
cmake/modulecppexports_p.h.in
cmake/qbatchedtestrunner.in.cpp
${__private_files}
DESTINATION "${__GlobalConfig_install_dir}"
)
@ -328,40 +256,29 @@ if(QT_WILL_INSTALL)
endforeach()
endif()
# Wrap previously queried helpers file.
list(TRANSFORM __qt_cmake_public_helpers PREPEND "cmake/")
list(TRANSFORM __qt_cmake_public_helpers APPEND ".cmake")
qt_internal_get_qt_build_public_files_to_install(__qt_public_files_to_install)
list(TRANSFORM __qt_public_files_to_install PREPEND "cmake/")
# Install public CMake files.
# The functions defined inside can be used in both public projects and while building Qt.
# Usually we put such functions into Qt6CoreMacros.cmake, but that's getting bloated.
# These files will be included by Qt6Config.cmake.
set(__public_cmake_helpers
cmake/QtCopyFileIfDifferent.cmake
cmake/QtFeature.cmake
cmake/QtFeatureCommon.cmake
cmake/QtInitProject.cmake
cmake/QtPublicAppleHelpers.cmake
cmake/QtPublicCMakeHelpers.cmake
cmake/QtPublicCMakeVersionHelpers.cmake
cmake/QtPublicExternalProjectHelpers.cmake
cmake/QtPublicFinalizerHelpers.cmake
cmake/QtPublicPluginHelpers.cmake
cmake/QtPublicTargetHelpers.cmake
cmake/QtPublicTestHelpers.cmake
cmake/QtPublicToolHelpers.cmake
cmake/QtPublicWalkLibsHelpers.cmake
cmake/QtPublicFindPackageHelpers.cmake
cmake/QtPublicDependencyHelpers.cmake
# Public CMake files that are installed next Qt6Config.cmake, but are NOT included by it.
# Instead they are included by the generated CMake toolchain file.
cmake/QtPublicWasmToolchainHelpers.cmake
set(__public_files
${__qt_cmake_public_helpers}
${__qt_public_files_to_install}
)
qt_copy_or_install(FILES ${__public_cmake_helpers} DESTINATION "${__GlobalConfig_install_dir}")
qt_copy_or_install(FILES ${__public_files} DESTINATION "${__GlobalConfig_install_dir}")
# In prefix builds we also need to copy the files into the build config directory, so that the
# build-dir Qt6Config.cmake finds the files when building examples in-tree.
if(QT_WILL_INSTALL)
foreach(_public_cmake_helper ${__public_cmake_helpers})
file(COPY "${_public_cmake_helper}" DESTINATION "${__GlobalConfig_build_dir}")
foreach(_public_file ${__public_files})
file(COPY "${_public_file}" DESTINATION "${__GlobalConfig_build_dir}")
endforeach()
endif()

View File

@ -120,76 +120,186 @@ macro(qt_internal_set_debug_extend_target)
option(QT_CMAKE_DEBUG_EXTEND_TARGET "Debug extend_target calls in Qt's build system" OFF)
endmacro()
# These upstream CMake modules will be automatically include()'d when doing
# find_package(Qt6 COMPONENTS BuildInternals).
function(qt_internal_get_qt_build_upstream_cmake_modules out_var)
set(${out_var}
CMakeFindBinUtils
CMakePackageConfigHelpers
CheckCXXSourceCompiles
FeatureSummary
PARENT_SCOPE
)
endfunction()
# These helpers will be installed when building qtbase, and they will be automatically include()'d
# when doing find_package(Qt6 COMPONENTS BuildInternals).
# The helpers are expected to exist under the qtbase/cmake sub-directory and their file name
# extension should be '.cmake'.
function(qt_internal_get_qt_build_private_helpers out_var)
set(${out_var}
Qt3rdPartyLibraryHelpers
QtAndroidHelpers
QtAppHelpers
QtAutogenHelpers
QtBuildInformation
QtBuildOptionsHelpers
QtBuildPathsHelpers
QtBuildRepoExamplesHelpers
QtBuildRepoHelpers
QtCMakeHelpers
QtCMakeVersionHelpers
QtDbusHelpers
QtDeferredDependenciesHelpers
QtDocsHelpers
QtExecutableHelpers
QtFindPackageHelpers
QtFlagHandlingHelpers
QtFrameworkHelpers
QtGlobalStateHelpers
QtHeadersClean
QtInstallHelpers
QtJavaHelpers
QtLalrHelpers
QtMkspecHelpers
QtModuleHelpers
QtNoLinkTargetHelpers
QtPkgConfigHelpers
QtPlatformTargetHelpers
QtPluginHelpers
QtPostProcessHelpers
QtPrecompiledHeadersHelpers
QtPriHelpers
QtPrlHelpers
QtQmakeHelpers
QtResourceHelpers
QtRpathHelpers
QtSanitizerHelpers
QtScopeFinalizerHelpers
QtSeparateDebugInfo
QtSimdHelpers
QtSingleRepoTargetSetBuildHelpers
QtSyncQtHelpers
QtTargetHelpers
QtTestHelpers
QtToolHelpers
QtToolchainHelpers
QtUnityBuildHelpers
QtWasmHelpers
QtWrapperScriptHelpers
PARENT_SCOPE
)
endfunction()
# These files will be installed when building qtbase, but will NOT be automatically include()d
# when doing find_package(Qt6 COMPONENTS BuildInternals).
# The files are expected to exist under the qtbase/cmake sub-directory.
function(qt_internal_get_qt_build_private_files_to_install out_var)
set(${out_var}
ModuleDescription.json.in
PkgConfigLibrary.pc.in
Qt3rdPartyLibraryConfig.cmake.in
QtBaseTopLevelHelpers.cmake
QtBuild.cmake
QtBuildHelpers.cmake
QtCMakePackageVersionFile.cmake.in
QtCompilerFlags.cmake
QtCompilerOptimization.cmake
QtConfigDependencies.cmake.in
QtConfigureTimeExecutableCMakeLists.txt.in
QtFileConfigure.txt.in
QtFindWrapConfigExtra.cmake.in
QtFindWrapHelper.cmake
QtFinishPkgConfigFile.cmake
QtFinishPrlFile.cmake
QtGenerateExtPri.cmake
QtGenerateLibHelpers.cmake
QtGenerateLibPri.cmake
QtGenerateVersionScript.cmake
QtModuleConfig.cmake.in
QtModuleDependencies.cmake.in
QtModuleHeadersCheck.cmake
QtModuleToolsConfig.cmake.in
QtModuleToolsDependencies.cmake.in
QtModuleToolsVersionlessTargets.cmake.in
QtPlatformAndroid.cmake
QtPlatformSupport.cmake
QtPluginConfig.cmake.in
QtPluginDependencies.cmake.in
QtPlugins.cmake.in
QtPostProcess.cmake
QtProcessConfigureArgs.cmake
QtSeparateDebugInfo.Info.plist.in
QtSetup.cmake
QtStandaloneTestsConfig.cmake.in
QtWriteArgsFile.cmake
modulecppexports.h.in
modulecppexports_p.h.in
qbatchedtestrunner.in.cpp
PARENT_SCOPE
)
endfunction()
# These helpers will be installed when building qtbase, and they will be automatically include()'d
# when doing find_package(Qt6 COMPONENTS BuildInternals).
# The helpers are expected to exist under the qtbase/cmake sub-directory and their file name
# extension should be '.cmake'.
# In addition, they are meant to be included when doing find_package(Qt6) as well.
function(qt_internal_get_qt_build_public_helpers out_var)
set(${out_var}
QtFeature
QtFeatureCommon
QtPublicAppleHelpers
QtPublicCMakeHelpers
QtPublicCMakeVersionHelpers
QtPublicDependencyHelpers
QtPublicExternalProjectHelpers
QtPublicFinalizerHelpers
QtPublicFindPackageHelpers
QtPublicPluginHelpers
QtPublicTargetHelpers
QtPublicTestHelpers
QtPublicToolHelpers
QtPublicWalkLibsHelpers
PARENT_SCOPE
)
endfunction()
# These files will be installed when building qtbase, but will NOT be automatically include()d
# when doing find_package(Qt6) nor find_package(Qt6 COMPONENTS BuildInternals).
# The files are expected to exist under the qtbase/cmake sub-directory.
function(qt_internal_get_qt_build_public_files_to_install out_var)
set(${out_var}
QtCopyFileIfDifferent.cmake
QtInitProject.cmake
# Public CMake files that are installed next Qt6Config.cmake, but are NOT included by it.
# Instead they are included by the generated CMake toolchain file.
QtPublicWasmToolchainHelpers.cmake
PARENT_SCOPE
)
endfunction()
# Includes all Qt CMake helper files that define functions and macros.
macro(qt_internal_include_all_helpers)
# Upstream cmake modules.
include(CheckCXXSourceCompiles)
include(CMakeFindBinUtils)
include(CMakePackageConfigHelpers)
include(FeatureSummary)
qt_internal_get_qt_build_upstream_cmake_modules(__qt_upstream_helpers)
foreach(__qt_file_name IN LISTS __qt_upstream_helpers)
include("${__qt_file_name}")
endforeach()
# Internal helpers available only while building Qt itself.
include(Qt3rdPartyLibraryHelpers)
include(QtAndroidHelpers)
include(QtAppHelpers)
include(QtAutogenHelpers)
include(QtBuildInformation)
include(QtBuildOptionsHelpers)
include(QtBuildPathsHelpers)
include(QtBuildRepoExamplesHelpers)
include(QtBuildRepoHelpers)
include(QtCMakeHelpers)
include(QtCMakeVersionHelpers)
include(QtDbusHelpers)
include(QtDeferredDependenciesHelpers)
include(QtDocsHelpers)
include(QtExecutableHelpers)
include(QtFeature)
include(QtFindPackageHelpers)
include(QtFlagHandlingHelpers)
include(QtFrameworkHelpers)
include(QtGlobalStateHelpers)
include(QtHeadersClean)
include(QtInstallHelpers)
include(QtJavaHelpers)
include(QtLalrHelpers)
include(QtMkspecHelpers)
include(QtModuleHelpers)
include(QtNoLinkTargetHelpers)
include(QtPkgConfigHelpers)
include(QtPlatformTargetHelpers)
include(QtPluginHelpers)
include(QtPostProcessHelpers)
include(QtPrecompiledHeadersHelpers)
include(QtPriHelpers)
include(QtPrlHelpers)
include(QtQmakeHelpers)
include(QtResourceHelpers)
include(QtRpathHelpers)
include(QtSanitizerHelpers)
include(QtScopeFinalizerHelpers)
include(QtSeparateDebugInfo)
include(QtSimdHelpers)
include(QtSingleRepoTargetSetBuildHelpers)
include(QtSyncQtHelpers)
include(QtTargetHelpers)
include(QtTestHelpers)
include(QtToolchainHelpers)
include(QtToolHelpers)
include(QtUnityBuildHelpers)
include(QtWasmHelpers)
include(QtWrapperScriptHelpers)
qt_internal_get_qt_build_private_helpers(__qt_private_helpers)
foreach(__qt_file_name IN LISTS __qt_private_helpers)
include("${__qt_file_name}")
endforeach()
# Helpers that are available in public projects and while building Qt itself.
include(QtPublicAppleHelpers)
include(QtPublicCMakeHelpers)
include(QtPublicDependencyHelpers)
include(QtPublicExternalProjectHelpers)
include(QtPublicFindPackageHelpers)
include(QtPublicPluginHelpers)
include(QtPublicTargetHelpers)
include(QtPublicTestHelpers)
include(QtPublicToolHelpers)
include(QtPublicWalkLibsHelpers)
qt_internal_get_qt_build_public_helpers(__qt_public_helpers)
foreach(__qt_file_name IN LISTS __qt_public_helpers)
include("${__qt_file_name}")
endforeach()
endmacro()
function(qt_internal_check_host_path_set_for_cross_compiling)

View File

@ -38,18 +38,12 @@ if(APPLE)
endif()
# Public helpers available to all Qt packages.
include("${CMAKE_CURRENT_LIST_DIR}/QtFeature.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicAppleHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicExternalProjectHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicFinalizerHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicPluginHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicTargetHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicWalkLibsHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicFindPackageHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicDependencyHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicTestHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicToolHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicCMakeHelpers.cmake")
set(__qt_public_files_to_include
@QT_PUBLIC_FILES_TO_INCLUDE@
)
foreach(__qt_public_file_to_include IN LISTS __qt_public_files_to_include)
include("${__qt_public_file_to_include}")
endforeach()
set(QT_ADDITIONAL_PACKAGES_PREFIX_PATH "" CACHE STRING
"Additional directories where find(Qt6 ...) components are searched")

View File

@ -1,7 +1,6 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
include(QtFeatureCommon)
include(CheckCXXCompilerFlag)
function(qt_feature_module_begin)