diff options
| author | Alexandru Croitor <[email protected]> | 2025-11-17 19:07:03 +0100 |
|---|---|---|
| committer | Alexandru Croitor <[email protected]> | 2025-11-27 15:22:48 +0100 |
| commit | 7e36a23467e3572a282a76cb1e2319f53499fed9 (patch) | |
| tree | 2ddd8a0c887367a8b9998fe46df54ea28a422702 /cmake | |
| parent | b0f25bc6a7c40b36b6cab4f53d2ef44f1b6d4632 (diff) | |
CMake: Allow creating a standalone Tools package without a module
Add a new qt_internal_add_tools_package function to allow creating a
standalone Tools cmake package.
It can be useful for a repo which might build e.g. an arch-independent
java tool exposed by an IMPORTED executable, but has no associated
C++ Qt module.
Also add a
qt_internal_record_tools_package_extra_third_party_dependency function
to allow looking up additional third party cmake packages when finding
the tool package.
Change-Id: I46f5fb9f7a361ecf4018f0fc1ed0a1f8ecf12df3
Reviewed-by: Joerg Bornemann <[email protected]>
Diffstat (limited to 'cmake')
| -rw-r--r-- | cmake/QtBuildHelpers.cmake | 1 | ||||
| -rw-r--r-- | cmake/QtBuildRepoHelpers.cmake | 30 | ||||
| -rw-r--r-- | cmake/QtFindPackageHelpers.cmake | 46 | ||||
| -rw-r--r-- | cmake/QtModuleToolsConfig.cmake.in | 14 | ||||
| -rw-r--r-- | cmake/QtPostProcessHelpers.cmake | 34 | ||||
| -rw-r--r-- | cmake/QtStandaloneTestsConfig.cmake.in | 4 | ||||
| -rw-r--r-- | cmake/QtTargetHelpers.cmake | 6 | ||||
| -rw-r--r-- | cmake/QtToolHelpers.cmake | 336 |
8 files changed, 406 insertions, 65 deletions
diff --git a/cmake/QtBuildHelpers.cmake b/cmake/QtBuildHelpers.cmake index 7205bad5253..84ab04db43d 100644 --- a/cmake/QtBuildHelpers.cmake +++ b/cmake/QtBuildHelpers.cmake @@ -96,6 +96,7 @@ macro(qt_internal_reset_global_state) qt_internal_set_qt_known_plugins("") set(QT_KNOWN_MODULES_WITH_TOOLS "" CACHE INTERNAL "Known Qt modules with tools" FORCE) + set_property(GLOBAL PROPERTY _qt_standalone_tool_packages "") endmacro() macro(qt_internal_set_qt_path_separator) diff --git a/cmake/QtBuildRepoHelpers.cmake b/cmake/QtBuildRepoHelpers.cmake index 5961424c38b..05876c1ad6d 100644 --- a/cmake/QtBuildRepoHelpers.cmake +++ b/cmake/QtBuildRepoHelpers.cmake @@ -732,6 +732,7 @@ macro(qt_internal_find_standalone_parts_qt_packages standalone_parts_args_var_na set(__standalone_parts_single_args "") set(__standalone_parts_multi_args QT_MODULE_PACKAGES + QT_TOOL_PACKAGES ) cmake_parse_arguments(__standalone_parts "${__standalone_parts_opt_args}" @@ -743,6 +744,32 @@ macro(qt_internal_find_standalone_parts_qt_packages standalone_parts_args_var_na # the one recorded on the Platform target. qt_internal_get_package_version_of_target(Platform __standalone_parts_main_qt_package_version) + if(__standalone_parts_QT_TOOL_PACKAGES) + # Set up QT_HOST_PATH as an extra root path to look for the Tools packages when + # cross-compiling. + if(NOT "${QT_HOST_PATH}" STREQUAL "") + set(__standalone_parts_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}) + set(__standalone_parts_CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH}) + list(PREPEND CMAKE_PREFIX_PATH "${QT_HOST_PATH_CMAKE_DIR}") + list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}") + endif() + + foreach(__standalone_parts_package_name IN LISTS __standalone_parts_QT_TOOL_PACKAGES) + find_package(${QT_CMAKE_EXPORT_NAMESPACE}${__standalone_parts_package_name} + "${__standalone_parts_main_qt_package_version}" + PATHS + # These come from Qt6Config.cmake + ${_qt_additional_packages_prefix_path} + ${_qt_additional_packages_prefix_path_env} + ) + endforeach() + + if(NOT "${QT_HOST_PATH}" STREQUAL "") + set(CMAKE_PREFIX_PATH ${__standalone_parts_CMAKE_PREFIX_PATH}) + set(CMAKE_FIND_ROOT_PATH ${__standalone_parts_CMAKE_FIND_ROOT_PATH}) + endif() + endif() + if(__standalone_parts_QT_MODULE_PACKAGES) foreach(__standalone_parts_package_name IN LISTS __standalone_parts_QT_MODULE_PACKAGES) find_package(${QT_CMAKE_EXPORT_NAMESPACE} @@ -755,8 +782,11 @@ macro(qt_internal_find_standalone_parts_qt_packages standalone_parts_args_var_na unset(__standalone_parts_single_args) unset(__standalone_parts_multi_args) unset(__standalone_parts_QT_MODULE_PACKAGES) + unset(__standalone_parts_QT_TOOL_PACKAGES) unset(__standalone_parts_main_qt_package_version) unset(__standalone_parts_package_name) + unset(__standalone_parts_CMAKE_PREFIX_PATH) + unset(__standalone_parts_CMAKE_FIND_ROOT_PATH) endmacro() # Used by standalone tests and standalone non-ExternalProject examples to find all installed qt diff --git a/cmake/QtFindPackageHelpers.cmake b/cmake/QtFindPackageHelpers.cmake index 29c12dcd826..e30cd82c90a 100644 --- a/cmake/QtFindPackageHelpers.cmake +++ b/cmake/QtFindPackageHelpers.cmake @@ -457,6 +457,52 @@ function(qt_record_extra_third_party_dependency main_target_name dep_target) endif() endfunction() +# Record a third party dependency for a standalone tools package. +# +# This function records a dependency between the standalone pacakge PACKAGE_BASE_NAME and third +# party dependency DEPENDENCY_PACKAGE_NAME and DEPENDENCY_PACKAGE_VERSION +# at the CMake package level. +# +# E.g. A Qt6GarageTools package with the PACKAGE_BASE_NAME 'Garage', +# needs to call find_package(ZLIB 1.2) (non-qt-package). +function(qt_internal_record_tools_package_extra_third_party_dependency) + set(opt_args "") + set(single_args + PACKAGE_BASE_NAME + ) + set(multi_args + DEPENDENCY_PACKAGE_NAME + DEPENDENCY_PACKAGE_VERSION + ) + cmake_parse_arguments(PARSE_ARGV 0 arg "${opt_args}" "${single_args}" "${multi_args}") + _qt_internal_validate_all_args_are_parsed(arg) + + if(NOT arg_PACKAGE_BASE_NAME) + message(FATAL_ERROR "PACKAGE_BASE_NAME is required.") + endif() + set(id "${arg_PACKAGE_BASE_NAME}") + + if(NOT arg_DEPENDENCY_PACKAGE_NAME) + message(FATAL_ERROR "DEPENDENCY_PACKAGE_NAME is required.") + endif() + set(dep_package_name "${arg_DEPENDENCY_PACKAGE_NAME}") + + if(arg_DEPENDENCY_PACKAGE_VERSION) + set(dep_package_version "${arg_DEPENDENCY_PACKAGE_VERSION}") + else() + set(dep_package_version "") + endif() + + get_cmake_property(extra_deps _qt_standalone_tool_package_${id}_third_party_dependencies) + if(NOT extra_deps) + set(extra_deps "") + endif() + + list(APPEND extra_deps "${dep_package_name}\;${dep_package_version}") + set_property(GLOBAL PROPERTY _qt_standalone_tool_package_${id}_third_party_dependencies + "${extra_deps}") +endfunction() + # Sets out_var to TRUE if the non-namespaced ${lib} target is exported as part of Qt6Targets.cmake. function(qt_internal_is_lib_part_of_qt6_package lib out_var) if (lib STREQUAL "Platform" diff --git a/cmake/QtModuleToolsConfig.cmake.in b/cmake/QtModuleToolsConfig.cmake.in index 43b826c2060..1bd54239edf 100644 --- a/cmake/QtModuleToolsConfig.cmake.in +++ b/cmake/QtModuleToolsConfig.cmake.in @@ -18,10 +18,17 @@ if(NOT DEFINED "@INSTALL_CMAKE_NAMESPACE@@target@_FOUND") set("@INSTALL_CMAKE_NAMESPACE@@target@_FOUND" TRUE) endif() +set(__qt_@target@_should_include_targets_code "@QT_SHOULD_INCLUDE_TARGETS_CODE@") + # Do the checks inside Targets.cmake even when the file is still being generated -include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@[email protected]") +if(__qt_@target@_should_include_targets_code) + include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@[email protected]") +endif() -if(NOT __qt_@target@_skip_include_targets_file AND @INSTALL_CMAKE_NAMESPACE@@target@_FOUND) +if(NOT __qt_@target@_skip_include_targets_file + AND @INSTALL_CMAKE_NAMESPACE@@target@_FOUND + AND __qt_@target@_should_include_targets_code + ) include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@[email protected]") include("${CMAKE_CURRENT_LIST_DIR}/@INSTALL_CMAKE_NAMESPACE@@[email protected]") if(NOT QT_NO_CREATE_VERSIONLESS_TARGETS) @@ -30,7 +37,8 @@ if(NOT __qt_@target@_skip_include_targets_file AND @INSTALL_CMAKE_NAMESPACE@@tar set(__qt_@target@_targets_file_included ON) endif() -foreach(extra_cmake_include @extra_cmake_includes@) +set(__qt_@target@_extra_cmake_includes "@extra_cmake_includes@") +foreach(extra_cmake_include IN LISTS __qt_@target@_extra_cmake_includes) include("${CMAKE_CURRENT_LIST_DIR}/${extra_cmake_include}") endforeach() diff --git a/cmake/QtPostProcessHelpers.cmake b/cmake/QtPostProcessHelpers.cmake index b8e46085a98..f0ac617bff9 100644 --- a/cmake/QtPostProcessHelpers.cmake +++ b/cmake/QtPostProcessHelpers.cmake @@ -801,8 +801,15 @@ endfunction() function(qt_create_tools_config_files) # Create packages like Qt6CoreTools/Qt6CoreToolsConfig.cmake. foreach(module_name ${QT_KNOWN_MODULES_WITH_TOOLS}) - qt_export_tools("${module_name}") + qt_export_tools(MODULE_NAME "${module_name}") endforeach() + + get_cmake_property(standalone_packages _qt_standalone_tool_packages) + if(standalone_packages) + foreach(package_name IN LISTS standalone_packages) + qt_export_tools(PACKAGE_BASE_NAME "${package_name}") + endforeach() + endif() endfunction() function(qt_internal_create_config_file_for_standalone_tests) @@ -835,9 +842,11 @@ function(qt_internal_create_config_file_for_standalone_tests) endif() endforeach() - # Skip generating and installing file if no modules were built. This make sure not to install - # anything when build qtx11extras on macOS for example. - if(NOT modules) + get_cmake_property(tool_package_base_names _qt_standalone_tool_packages) + + # Skip generating and installing file if no modules or tools were built. This makes sure not + # to install anything when building qtx11extras on macOS for example. + if(NOT modules AND NOT tool_package_base_names) return() endif() @@ -846,7 +855,22 @@ function(qt_internal_create_config_file_for_standalone_tests) qt_internal_get_standalone_parts_config_file_name(tests_config_file_name) # Substitution variables. - list(JOIN modules "\n " QT_MODULE_PACKAGES) + if(modules) + list(JOIN modules "\n " module_string) + set(QT_MODULE_PACKAGES " QT_MODULE_PACKAGES + ${module_string}") + endif() + + if(tool_package_base_names) + # We only have the base package names, so we need to append Tools to each of the package + # names + set(tool_packages "${tool_package_base_names}") + list(TRANSFORM tool_packages APPEND Tools) + + list(JOIN tool_packages "\n " tool_packages_string) + set(QT_TOOL_PACKAGES " QT_TOOL_PACKAGES + ${tool_packages_string}") + endif() configure_file( "${QT_CMAKE_DIR}/QtStandaloneTestsConfig.cmake.in" diff --git a/cmake/QtStandaloneTestsConfig.cmake.in b/cmake/QtStandaloneTestsConfig.cmake.in index 9d548d14699..47ee7e8353a 100644 --- a/cmake/QtStandaloneTestsConfig.cmake.in +++ b/cmake/QtStandaloneTestsConfig.cmake.in @@ -2,7 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause set(__standalone_parts_qt_packages_args - QT_MODULE_PACKAGES - @QT_MODULE_PACKAGES@ +@QT_MODULE_PACKAGES@ +@QT_TOOL_PACKAGES@ ) qt_internal_find_standalone_parts_qt_packages(__standalone_parts_qt_packages_args) diff --git a/cmake/QtTargetHelpers.cmake b/cmake/QtTargetHelpers.cmake index 397628ba11a..da210820bb2 100644 --- a/cmake/QtTargetHelpers.cmake +++ b/cmake/QtTargetHelpers.cmake @@ -925,6 +925,12 @@ function(qt_internal_export_additional_targets_file_finalizer id) list(LENGTH arg_TARGETS num_TARGETS) + if(num_TARGETS EQUAL 0) + # Return early without creating and installing the additional file if there are no targets + # to process. + return() + endif() + # Determine the release configurations we're currently building if(QT_GENERATOR_IS_MULTI_CONFIG) set(active_configurations ${CMAKE_CONFIGURATION_TYPES}) diff --git a/cmake/QtToolHelpers.cmake b/cmake/QtToolHelpers.cmake index fe568d09ee6..5d531818ebd 100644 --- a/cmake/QtToolHelpers.cmake +++ b/cmake/QtToolHelpers.cmake @@ -360,21 +360,181 @@ echo. > ${target_bin_dir}/${target}_try_run_passed" DEPENDS ${target_bin_dir}/${target}_try_run_passed) endfunction() +# Create a standalone FooTools package, similar to the ones automatically generated by +# qt_internal_add_module, e.g. Core -> CoreTools. +# +# A standalone tools package can be useful when one wants to associate some special targets and +# cmake scripts to a package that is not associated with any Qt module, and is not architecture +# dependent (e.g. java binaries). +# +# Arguments +# PACKAGE_BASE_NAME - base name of the package, e.g. for a value of Foo, it will create a +# Qt6FooToolsConfig.cmake file. +# +# PACKAGE_VERSION - version to use for the package, defaults to PROJECT_VERSION. +# +# EXTRA_CMAKE_FILES - list of additional cmake files to install alongside the package +# +# EXTRA_CMAKE_INCLUDES - list of cmake files to include in the package config file +# +# EXTRA_CMAKE_STATEMENTS - list of additional cmake statements (strings) to append to the end of +# the package config file. +# +# TOOL_TARGETS - list of add_executable targets that should be install(EXPORT)ed for this package. +# It can NOT take imported targets or custom targets. +# +# TOOL_PACKAGE_DEPENDENCIES - list of other Qt Tools package dependencies that should be +# find_package'd when using this Tools package. +function(qt_internal_add_tools_package) + set(opt_args "") + set(single_args + PACKAGE_BASE_NAME + PACKAGE_VERSION + ) + set(multi_args + EXTRA_CMAKE_FILES + EXTRA_CMAKE_INCLUDES + EXTRA_CMAKE_STATEMENTS + TOOL_TARGETS + TOOL_PACKAGE_DEPENDENCIES + ) + cmake_parse_arguments(PARSE_ARGV 0 arg "${opt_args}" "${single_args}" "${multi_args}") + _qt_internal_validate_all_args_are_parsed(arg) + + if(NOT arg_PACKAGE_BASE_NAME) + message(FATAL_ERROR "Missing PACKAGE_BASE_NAME value") + endif() + + if(arg_PACKAGE_VERSION) + set(tools_package_version "${arg_PACKAGE_VERSION}") + else() + set(tools_package_version "${PROJECT_VERSION}") + endif() + + set(id "${arg_PACKAGE_BASE_NAME}") + _qt_internal_append_to_cmake_property_without_duplicates(_qt_standalone_tool_packages "${id}") + + set_property(GLOBAL PROPERTY _qt_standalone_tool_package_${id}_package_base_name "${id}") + + set_property(GLOBAL PROPERTY _qt_standalone_tool_package_${id}_version + "${tools_package_version}") + + set_property(GLOBAL PROPERTY _qt_standalone_tool_package_${id}_list_dir + "${CMAKE_CURRENT_LIST_DIR}") + + set_property(GLOBAL PROPERTY _qt_standalone_tool_package_${id}_extra_cmake_files + "${arg_EXTRA_CMAKE_FILES}") + + set_property(GLOBAL PROPERTY _qt_standalone_tool_package_${id}_extra_cmake_includes + "${arg_EXTRA_CMAKE_INCLUDES}") + + set_property(GLOBAL PROPERTY _qt_standalone_tool_package_${id}_extra_cmake_statements + "${arg_EXTRA_CMAKE_STATEMENTS}") + + set_property(GLOBAL PROPERTY _qt_standalone_tool_package_${id}_tool_targets + "${arg_TOOL_TARGETS}") + + set_property(GLOBAL PROPERTY _qt_standalone_tool_package_${id}_tool_package_dependencies + "${arg_TOOL_PACKAGE_DEPENDENCIES}") +endfunction() + +# Creates a FooTools package with information about tool targets. +# The source of information for the created package is taken either from a Qt module and its +# tool targets, or from global properties associated with a standalone tools package. function(qt_export_tools module_name) + set(opt_args "") + set(single_args + MODULE_NAME + PACKAGE_BASE_NAME + ) + set(multi_args "") + cmake_parse_arguments(PARSE_ARGV 0 arg "${opt_args}" "${single_args}" "${multi_args}") + _qt_internal_validate_all_args_are_parsed(arg) + # Bail out when not building tools. if(NOT QT_WILL_BUILD_TOOLS) return() endif() - # If no tools were defined belonging to this module, don't create a config and targets file. - if(NOT "${module_name}" IN_LIST QT_KNOWN_MODULES_WITH_TOOLS) - return() + if(NOT arg_MODULE_NAME AND NOT arg_PACKAGE_BASE_NAME) + message(FATAL_ERROR "Either MODULE_NAME or PACKAGE_BASE_NAME must be specified") endif() - # The tools target name. For example: CoreTools - set(target "${module_name}Tools") + # Qt module case. + if(arg_MODULE_NAME) + # The tools package name. For example: CoreTools + set(module_name "${arg_MODULE_NAME}") + + # If no tools were defined belonging to this module, don't create a config and targets file. + if(NOT "${module_name}" IN_LIST QT_KNOWN_MODULES_WITH_TOOLS) + return() + endif() + + set(package_name "${module_name}Tools") + set(known_tools ${QT_KNOWN_MODULE_${module_name}_TOOLS}) + endif() + + # Standalone package case. + if(arg_PACKAGE_BASE_NAME) + set(package_name "${arg_PACKAGE_BASE_NAME}Tools") + + set(id "${arg_PACKAGE_BASE_NAME}") + + get_cmake_property(standalone_tools_package_version + _qt_standalone_tool_package_${id}_version) + if(NOT standalone_tools_package_version) + message(FATAL_ERROR "Missing version for standalone tools package ${id}") + endif() + + get_cmake_property(standalone_tools_list_dir + _qt_standalone_tool_package_${id}_list_dir) + if(NOT standalone_tools_list_dir) + set(standalone_tools_list_dir "") + endif() + + get_cmake_property(package_extra_cmake_files + _qt_standalone_tool_package_${id}_extra_cmake_files) + if(NOT package_extra_cmake_files) + set(package_extra_cmake_files "") + endif() - set(path_suffix "${INSTALL_CMAKE_NAMESPACE}${target}") + get_cmake_property(package_extra_cmake_includes + _qt_standalone_tool_package_${id}_extra_cmake_includes) + if(NOT package_extra_cmake_includes) + set(package_extra_cmake_includes "") + endif() + + get_cmake_property(package_extra_cmake_statements + _qt_standalone_tool_package_${id}_extra_cmake_statements) + if(NOT package_extra_cmake_statements) + set(package_extra_cmake_statements "") + endif() + + get_cmake_property(known_tools _qt_standalone_tool_package_${id}_tool_targets) + if(NOT known_tools) + set(known_tools "") + endif() + + get_cmake_property(tool_package_dependencies + _qt_standalone_tool_package_${id}_tool_package_dependencies) + if(NOT tool_package_dependencies) + set(tool_package_dependencies "") + endif() + + get_cmake_property(third_party_package_dependencies + _qt_standalone_tool_package_${id}_third_party_dependencies) + if(NOT third_party_package_dependencies) + set(third_party_package_dependencies "") + endif() + + unset(id) + endif() + + # This is used as a substitution variable, ala @target@ in the config / dependencies / + # etc files. + set(target ${package_name}) + + set(path_suffix "${INSTALL_CMAKE_NAMESPACE}${package_name}") qt_path_join(config_build_dir ${QT_CONFIG_BUILD_DIR} ${path_suffix}) qt_path_join(config_install_dir ${QT_CONFIG_INSTALL_DIR} ${path_suffix}) @@ -395,7 +555,16 @@ function(qt_export_tools module_name) set(first_tool_package_version "") - set(known_tools ${QT_KNOWN_MODULE_${module_name}_TOOLS}) + if(package_extra_cmake_files) + list(APPEND extra_cmake_files ${package_extra_cmake_files}) + foreach(cmake_file ${package_extra_cmake_files}) + file(COPY "${cmake_file}" DESTINATION "${config_build_dir}") + endforeach() + endif() + + if(package_extra_cmake_includes) + list(APPEND extra_cmake_includes ${package_extra_cmake_includes}) + endif() foreach(tool_name IN LISTS known_tools) # Specific tools can have package dependencies. @@ -429,9 +598,10 @@ function(qt_export_tools module_name) if (QT_WILL_RENAME_TOOL_TARGETS) string(REGEX REPLACE "_native$" "" tool_name ${tool_name}) endif() - # `__qt_${target}_targets_file_included` is defined in the QtModuleToolsConfig.cmake.in + # `__qt_${package_name}_targets_file_included` is defined in the + # QtModuleToolsConfig.cmake.in set(extra_cmake_statements "${extra_cmake_statements} -if(__qt_${target}_targets_file_included AND ${INSTALL_CMAKE_NAMESPACE}${target}_FOUND) +if(__qt_${package_name}_targets_file_included AND ${INSTALL_CMAKE_NAMESPACE}${package_name}_FOUND) __qt_internal_promote_target_to_global(${INSTALL_CMAKE_NAMESPACE}::${tool_name}) endif() ") @@ -446,29 +616,64 @@ endif() endif() endforeach() - string(APPEND extra_cmake_statements -"set(${QT_CMAKE_EXPORT_NAMESPACE}${module_name}Tools_TARGETS \"${tool_targets}\")") + if(tool_targets) + string(APPEND extra_cmake_statements +"set(${QT_CMAKE_EXPORT_NAMESPACE}${package_name}Tools_TARGETS \"${tool_targets}\")") + endif() + + if(package_extra_cmake_statements) + foreach(statement ${package_extra_cmake_statements}) + string(APPEND extra_cmake_statements "\n${statement}") + endforeach() + endif() # Extract package dependencies that were determined in QtPostProcess, but only if ${module_name} # is an actual target. # module_name can be a non-existent target, if the tool doesn't have an existing associated # module, e.g. qtwaylandscanner. - if(TARGET "${module_name}") + if(module_name AND TARGET "${module_name}") get_target_property(module_package_deps "${module_name}" _qt_tools_package_deps) if(module_package_deps) list(APPEND package_deps "${module_package_deps}") endif() endif() - # Configure and install dependencies file for the ${module_name}Tools package. + if(tool_package_dependencies) + list(APPEND package_deps "${tool_package_dependencies}") + endif() + + if(third_party_package_dependencies) + foreach(third_party_dep IN LISTS third_party_package_dependencies) + list(GET third_party_dep 0 third_party_dep_name) + list(GET third_party_dep 1 third_party_dep_version) + + # Assume that all tool thirdparty deps are mandatory. + # TODO: Components are not supported + list(APPEND third_party_deps + "${third_party_dep_name}\\\;FALSE\\\;${third_party_dep_version}\\\;\\\;") + endforeach() + endif() + + # Generate ConfigExtras.cmake if a template exists. Include it first. + set(config_extras_path_in + "${standalone_tools_list_dir}/${path_suffix}ConfigExtras.cmake.in") + if(EXISTS "${config_extras_path_in}") + configure_file("${config_extras_path_in}" + "${config_build_dir}/${path_suffix}ConfigExtras.cmake" + @ONLY) + list(PREPEND extra_cmake_files "${config_build_dir}/${path_suffix}ConfigExtras.cmake") + list(PREPEND extra_cmake_includes "${path_suffix}ConfigExtras.cmake") + endif() + + # Configure and install dependencies file for the ${package_name}Tools package. configure_file( "${QT_CMAKE_DIR}/QtModuleToolsDependencies.cmake.in" - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Dependencies.cmake" + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}Dependencies.cmake" @ONLY ) qt_install(FILES - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Dependencies.cmake" + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}Dependencies.cmake" DESTINATION "${config_install_dir}" COMPONENT Devel ) @@ -481,29 +686,43 @@ endif() ) endif() - # Configure and install the ${module_name}Tools package Config file. + # Used in the template. + set(QT_SHOULD_INCLUDE_TARGETS_CODE FALSE) + if(known_tools) + set(QT_SHOULD_INCLUDE_TARGETS_CODE TRUE) + endif() + + # Configure and install the ${package_name}Tools package Config file. qt_internal_get_min_new_policy_cmake_version(min_new_policy_version) qt_internal_get_max_new_policy_cmake_version(max_new_policy_version) configure_package_config_file( "${QT_CMAKE_DIR}/QtModuleToolsConfig.cmake.in" - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Config.cmake" + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}Config.cmake" INSTALL_DESTINATION "${config_install_dir}" ) - qt_configure_file( - OUTPUT "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}TargetsPrecheck.cmake" - CONTENT + if(known_tools) + qt_configure_file( + OUTPUT + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}TargetsPrecheck.cmake" + CONTENT "_qt_internal_should_include_targets( TARGETS ${known_tools} NAMESPACE ${INSTALL_CMAKE_NAMESPACE}:: - OUT_VAR_SHOULD_SKIP __qt_${target}_skip_include_targets_file + OUT_VAR_SHOULD_SKIP __qt_${package_name}_skip_include_targets_file ) ") + endif() - # There might be Tools packages which don't have a corresponding real module_name target, like - # WaylandScannerTools. - # In that case we'll use the package version of the first tool that belongs to that package. - if(TARGET "${module_name}") + # There are multiple sources where a tools' package version can come from. + # For a standalone tools package, it is explicitly given. + # For a package associated with a Qt module, it comes from a module. + # For a package without a Qt module, like WaylandScannerTools, + # we'll use the package version of the first tool that belongs to that package. + if(standalone_tools_package_version) + # Use the explicitly given package version. + set(tools_package_version "${standalone_tools_package_version}") + elseif(TARGET "${module_name}") qt_internal_get_package_version_of_target("${module_name}" tools_package_version) elseif(first_tool_package_version) set(tools_package_version "${first_tool_package_version}") @@ -513,56 +732,63 @@ endif() set(tools_package_version "${PROJECT_VERSION}") if(FEATURE_developer_build) message(WARNING - "Could not determine package version of tools package ${module_name}. " + "Could not determine package version of tools package ${package_name}. " "Defaulting to project version ${PROJECT_VERSION}.") endif() endif() message(TRACE - "Exporting tools package ${module_name}Tools with package version ${tools_package_version}" + "Exporting tools package ${package_name}Tools with package version ${tools_package_version}" "\n included targets: ${tool_targets_non_prefixed}") write_basic_package_version_file( - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersionImpl.cmake" + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}ConfigVersionImpl.cmake" VERSION "${tools_package_version}" COMPATIBILITY AnyNewerVersion ARCH_INDEPENDENT ) qt_internal_write_qt_package_version_file( - "${INSTALL_CMAKE_NAMESPACE}${target}" - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake" + "${INSTALL_CMAKE_NAMESPACE}${package_name}" + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}ConfigVersion.cmake" ) qt_install(FILES - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}Config.cmake" - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersion.cmake" - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}ConfigVersionImpl.cmake" - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}TargetsPrecheck.cmake" + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}Config.cmake" + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}ConfigVersion.cmake" + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}ConfigVersionImpl.cmake" DESTINATION "${config_install_dir}" COMPONENT Devel ) - set(export_name "${INSTALL_CMAKE_NAMESPACE}${target}Targets") - qt_install(EXPORT "${export_name}" - NAMESPACE "${QT_CMAKE_EXPORT_NAMESPACE}::" - DESTINATION "${config_install_dir}") - - qt_internal_export_additional_targets_file( - TARGETS ${QT_KNOWN_MODULE_${module_name}_TOOLS} - TARGET_EXPORT_NAMES ${tool_targets} - EXPORT_NAME_PREFIX ${INSTALL_CMAKE_NAMESPACE}${target} - CONFIG_INSTALL_DIR "${config_install_dir}") + if(known_tools) + qt_install(FILES + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}TargetsPrecheck.cmake" + DESTINATION "${config_install_dir}" + COMPONENT Devel + ) - # Create versionless targets file. - configure_file( - "${QT_CMAKE_DIR}/QtModuleToolsVersionlessTargets.cmake.in" - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}VersionlessTargets.cmake" - @ONLY - ) + set(export_name "${INSTALL_CMAKE_NAMESPACE}${package_name}Targets") + qt_install(EXPORT "${export_name}" + NAMESPACE "${QT_CMAKE_EXPORT_NAMESPACE}::" + DESTINATION "${config_install_dir}") + + qt_internal_export_additional_targets_file( + TARGETS ${known_tools} + TARGET_EXPORT_NAMES ${tool_targets} + EXPORT_NAME_PREFIX ${INSTALL_CMAKE_NAMESPACE}${package_name} + CONFIG_INSTALL_DIR "${config_install_dir}") + + # Create versionless targets file. + configure_file( + "${QT_CMAKE_DIR}/QtModuleToolsVersionlessTargets.cmake.in" + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}VersionlessTargets.cmake" + @ONLY + ) - qt_install(FILES - "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${target}VersionlessTargets.cmake" - DESTINATION "${config_install_dir}" - COMPONENT Devel - ) + qt_install(FILES + "${config_build_dir}/${INSTALL_CMAKE_NAMESPACE}${package_name}VersionlessTargets.cmake" + DESTINATION "${config_install_dir}" + COMPONENT Devel + ) + endif() endfunction() # Returns the target name for the tool with the given name. |
