diff --git a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake index ddf86230bb..9cd5c6ecfb 100644 --- a/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake +++ b/cmake/QtBuildInternals/QtBuildInternalsConfig.cmake @@ -1,11 +1,49 @@ # These values should be kept in sync with those in qtbase/.cmake.conf cmake_minimum_required(VERSION 3.14...3.19) -###################################### +############################################### # -# Macros for building Qt modules +# Macros and functions for building Qt modules # -###################################### +############################################### + +# Recursively reads the dependencies section from dependencies.yaml in ${repo_dir} and returns the +# list of dependencies, including transitive ones, in out_var. +# +# The returned dependencies are topologically sorted. +# +# Example output for qtimageformats: +# qtbase;qtshadertools;qtsvg;qtdeclarative;qttools +# +function(qt_internal_read_repo_dependencies out_var repo_dir) + set(seen ${ARGN}) + set(dependencies "") + set(in_dependencies_section FALSE) + set(dependencies_file "${repo_dir}/dependencies.yaml") + if(EXISTS "${dependencies_file}") + file(STRINGS "${dependencies_file}" lines) + foreach(line IN LISTS lines) + if(line MATCHES "^([^ ]+):") + if(CMAKE_MATCH_1 STREQUAL "dependencies") + set(in_dependencies_section TRUE) + else() + set(in_dependencies_section FALSE) + endif() + elseif(in_dependencies_section AND line MATCHES "^ (.+):$") + set(dependency "${CMAKE_MATCH_1}") + set(dependency_repo_dir "${repo_dir}/${dependency}") + string(REGEX MATCH "[^/]+$" dependency "${dependency}") + if(NOT dependency IN_LIST seen) + qt_internal_read_repo_dependencies(subdeps "${dependency_repo_dir}" + ${seen} ${dependency}) + list(APPEND dependencies ${subdeps} ${dependency}) + endif() + endif() + endforeach() + list(REMOVE_DUPLICATES dependencies) + endif() + set(${out_var} "${dependencies}" PARENT_SCOPE) +endfunction() set(QT_BACKUP_CMAKE_INSTALL_PREFIX_BEFORE_EXTRA_INCLUDE "${CMAKE_INSTALL_PREFIX}") diff --git a/cmake/QtPluginConfig.cmake.in b/cmake/QtPluginConfig.cmake.in index 25ad75ce71..e3fe9f06ae 100644 --- a/cmake/QtPluginConfig.cmake.in +++ b/cmake/QtPluginConfig.cmake.in @@ -1,5 +1,14 @@ include_guard(DIRECTORY) +if(DEFINED QT_REPO_DEPENDENCIES) + # We're building a Qt repository. + # Skip this plugin if it has not been provided by one of this repo's dependencies. + string(TOLOWER "@PROJECT_NAME@" lower_case_project_name) + if(NOT lower_case_project_name IN_LIST QT_REPO_DEPENDENCIES) + return() + endif() +endif() + @PACKAGE_INIT@ cmake_minimum_required(VERSION @min_new_policy_version@...@max_new_policy_version@) diff --git a/cmake/QtPlugins.cmake.in b/cmake/QtPlugins.cmake.in index d57611caec..3e554a43ad 100644 --- a/cmake/QtPlugins.cmake.in +++ b/cmake/QtPlugins.cmake.in @@ -19,7 +19,9 @@ function(__qt_internal_add_static_plugins_once) foreach(_config_file ${_qt_plugin_config_files}) string(REGEX REPLACE "^.*/@INSTALL_CMAKE_NAMESPACE@(.*Plugin)Config.cmake$" "\\1" _qt_plugin "${_config_file}") include("${_config_file}") - list(APPEND _qt_plugins ${_qt_plugin}) + if(TARGET "@INSTALL_CMAKE_NAMESPACE@::${_qt_plugin}") + list(APPEND _qt_plugins ${_qt_plugin}) + endif() endforeach() set_property(TARGET ${_module_target} PROPERTY QT_PLUGINS ${_qt_plugins}) diff --git a/cmake/QtPostProcessHelpers.cmake b/cmake/QtPostProcessHelpers.cmake index 2e8de1e15d..aa57c3aa9f 100644 --- a/cmake/QtPostProcessHelpers.cmake +++ b/cmake/QtPostProcessHelpers.cmake @@ -619,6 +619,15 @@ endif() string(APPEND QT_EXTRA_BUILD_INTERNALS_VARS "${install_prefix_content}") + if(NOT QT_SUPERBUILD AND NOT BUILD_SHARED_LIBS) + string(APPEND QT_EXTRA_BUILD_INTERNALS_VARS + " +if(DEFINED QT_REPO_MODULE_VERSION AND NOT DEFINED QT_REPO_DEPENDENCIES) + qt_internal_read_repo_dependencies(QT_REPO_DEPENDENCIES \"$\{PROJECT_SOURCE_DIR}\") +endif() +") + endif() + qt_compute_relative_path_from_cmake_config_dir_to_prefix() configure_file( "${CMAKE_CURRENT_LIST_DIR}/QtBuildInternalsExtra.cmake.in"