summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2021-03-22 20:43:25 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2021-03-26 11:52:00 +0100
commit98e8180e56322ce065e39cc1ef1d65b54caa8c25 (patch)
tree5a1879eb18d9359ba66038a2f72e30d81d71af77 /cmake
parent27ebeeb50e192ead7f839cbfcf13a2a42132a920 (diff)
Fix error when re-configuring an already installed Qt repository
When building and installing a Qt repo that provides plugins for a Qt module within a different repository (for example, qtimageformats providing imageformat plugins for QtGui), re-configuring that repository would result in configuration errors like "add_library cannot create ALIAS target "Qt6::QTgaPlugin" because another target with the same name already exists." This happened, because the find_package(Qt6 COMPONENTS Gui) calls pulled in the Qt6*PluginConfig.cmake files that create imported targets for the plugins we want to build. To fix this, when building Qt, we now load only plugins that are provided by repositories the currently building repository depends on. We read the repo dependencies from dependencies.yaml when the Qt6BuildInternals package is loaded, but only in static builds and only if we're currently building a Qt repository. To find out whether we're building a Qt repository, we check whether QT_REPO_MODULE_VERSION is defined. We cannot check QT_BUILDING_QT, because that variable is not available for the first find_package calls in the repository's top-level project file. In each Qt6*PluginConfig.cmake file, we bail out if the plugin's repository is not one of the ones in QT_REPO_DEPENDENCIES. Fixes: QTBUG-86670 Fixes: QTBUG-91887 Change-Id: I8f6c8398032227032742f1ca019e983ff2bcd745 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtBuildInternals/QtBuildInternalsConfig.cmake44
-rw-r--r--cmake/QtPluginConfig.cmake.in9
-rw-r--r--cmake/QtPlugins.cmake.in4
-rw-r--r--cmake/QtPostProcessHelpers.cmake9
4 files changed, 62 insertions, 4 deletions
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"