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>
This commit is contained in:
parent
27ebeeb50e
commit
98e8180e56
@ -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}")
|
||||
|
||||
|
@ -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@)
|
||||
|
@ -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}")
|
||||
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})
|
||||
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user