Skip to content

Commit

Permalink
Add support for building and installing repo target sets
Browse files Browse the repository at this point in the history
Introduce the concept of repository target sets, which is a named set of
targets within a Qt module repository.

In a Qt repository, a repo target set 'qtfoo' can be defined in the
top-level project file with
    qt_internal_define_repo_target_set(qtfoo DEPENDS Bar Baz)

The DEPENDS argument specifies Qt components that need to be
find_package'd when building the targets that belong to qtfoo.

In subdirectory project files, use
qt_internal_include_in_repo_target_set(qtfoo) to mark the file as
belonging to the repo target set.

To build and install a single repo target set, specify
QT_BUILD_SINGLE_REPO_TARGET_SET=qtfoo when configuring the Qt
repository.

Change-Id: Ic9e6213e3225988fd561f315bc857ee44ff17420
Reviewed-by: Alexandru Croitor <[email protected]>
  • Loading branch information
jobor committed May 20, 2021
1 parent df02297 commit 4b09522
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/QtBaseGlobalTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ qt_copy_or_install(FILES
cmake/QtSeparateDebugInfo.cmake
cmake/QtSetup.cmake
cmake/QtSimdHelpers.cmake
cmake/QtSingleRepoTargetSetBuildHelpers.cmake
cmake/QtStandaloneTestsConfig.cmake.in
cmake/QtSyncQtHelpers.cmake
cmake/QtTargetHelpers.cmake
Expand Down
1 change: 1 addition & 0 deletions cmake/QtBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ include(QtRpathHelpers)
include(QtSanitizerHelpers)
include(QtScopeFinalizerHelpers)
include(QtSimdHelpers)
include(QtSingleRepoTargetSetBuildHelpers)
include(QtSyncQtHelpers)
include(QtTargetHelpers)
include(QtTestHelpers)
Expand Down
44 changes: 44 additions & 0 deletions cmake/QtBuildInternals/QtBuildInternalsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,50 @@ macro(qt_prepare_standalone_project)
qt_enable_cmake_languages()
endmacro()

# Define a repo target set, and store accompanying information.
#
# A repo target set is a subset of targets in a Qt module repository. To build a repo target set,
# set QT_BUILD_SINGLE_REPO_TARGET_SET to the name of the repo target set.
#
# This function is to be called in the top-level project file of a repository,
# before qt_internal_prepare_single_repo_target_set_build()
#
# This function stores information in variables of the parent scope.
#
# Positional Arguments:
# name - The name of this repo target set.
#
# Named Arguments:
# DEPENDS - List of Qt6 COMPONENTS that are build dependencies of this repo target set.
function(qt_internal_define_repo_target_set name)
set(oneValueArgs DEPENDS)
set(prefix QT_REPO_TARGET_SET_)
cmake_parse_arguments(${prefix}${name} "" ${oneValueArgs} "" ${ARGN})
foreach(arg IN LISTS oneValueArgs)
set(${prefix}${name}_${arg} ${${prefix}${name}_${arg}} PARENT_SCOPE)
endforeach()
set(QT_REPO_KNOWN_TARGET_SETS "${QT_REPO_KNOWN_TARGET_SETS};${name}" PARENT_SCOPE)
endfunction()

# Setup a single repo target set build if QT_BUILD_SINGLE_REPO_TARGET_SET is defined.
#
# This macro must be called in the top-level project file of the repository after all repo target
# sets have been defined.
macro(qt_internal_prepare_single_repo_target_set_build)
if(DEFINED QT_BUILD_SINGLE_REPO_TARGET_SET)
if(NOT QT_BUILD_SINGLE_REPO_TARGET_SET IN_LIST QT_REPO_KNOWN_TARGET_SETS)
message(FATAL_ERROR
"Repo target set '${QT_BUILD_SINGLE_REPO_TARGET_SET}' is undefined.")
endif()
message(STATUS
"Preparing single repo target set build of ${QT_BUILD_SINGLE_REPO_TARGET_SET}")
if (NOT "${QT_REPO_TARGET_SET_${QT_BUILD_SINGLE_REPO_TARGET_SET}_DEPENDS}" STREQUAL "")
find_package(${INSTALL_CMAKE_NAMESPACE} ${PROJECT_VERSION} CONFIG REQUIRED
COMPONENTS ${QT_REPO_TARGET_SET_${QT_BUILD_SINGLE_REPO_TARGET_SET}_DEPENDS})
endif()
endif()
endmacro()

macro(qt_build_repo_begin)
qt_build_internals_set_up_private_api()
qt_enable_cmake_languages()
Expand Down
11 changes: 11 additions & 0 deletions cmake/QtSingleRepoTargetSetBuildHelpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Macro that checks for a single repo target set build, and returns from the current file, directory
# or function. Use this at the top of project files to whitelist the file for the given package.
macro(qt_internal_include_in_repo_target_set _repo_target_set_name)
if(DEFINED QT_BUILD_SINGLE_REPO_TARGET_SET)
if(NOT "${_repo_target_set_name}" STREQUAL QT_BUILD_SINGLE_REPO_TARGET_SET)
message(STATUS "Not part of repo target set ${QT_BUILD_SINGLE_REPO_TARGET_SET}: "
"${CMAKE_CURRENT_LIST_DIR}")
return()
endif()
endif()
endmacro()

0 comments on commit 4b09522

Please sign in to comment.