From c8062a424495617d0c5e6debe0fb243c438b9998 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Fri, 22 Sep 2023 12:50:30 +0200 Subject: [PATCH] Add QtSortModuleDependencies.cmake The script produces the list of Qt submodules that are required to build the submodules listed in the QT_BUILD_SUBMODULES variable. Also the script supports the "collect all but skip repos" mode. The repos that needs to be skipped should be specified by setting BUILD_=FALSE. The resulting list preserves the required build order. Change-Id: Ia1cfe0ce013f80dc2793a0ba863a18789657e5a1 Reviewed-by: Alexandru Croitor Reviewed-by: Amir Masoud Abdol --- cmake/QtSortModuleDependencies.cmake | 13 ++++++++++ cmake/QtTopLevelHelpers.cmake | 38 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 cmake/QtSortModuleDependencies.cmake diff --git a/cmake/QtSortModuleDependencies.cmake b/cmake/QtSortModuleDependencies.cmake new file mode 100644 index 00000000..d27f1818 --- /dev/null +++ b/cmake/QtSortModuleDependencies.cmake @@ -0,0 +1,13 @@ +# The script produces the list of qt submodules that are required to build the submodules listed +# in the QT_BUILD_SUBMODULES variable. The resulting list preserves the required build order. +# Usage: +# cmake [-DQT_BUILD_SUBMODULES=""] [-BUILD_=] \ +# -P /qt6/cmake/QtSortModuleDependencies.cmake +cmake_minimum_required(VERSION 3.16) + +include(${CMAKE_CURRENT_LIST_DIR}/QtTopLevelHelpers.cmake) + +qt_internal_collect_modules_only(result "${QT_BUILD_SUBMODULES}") + +list(JOIN result " " result) +message("${result}") diff --git a/cmake/QtTopLevelHelpers.cmake b/cmake/QtTopLevelHelpers.cmake index abce0eeb..f8473d72 100644 --- a/cmake/QtTopLevelHelpers.cmake +++ b/cmake/QtTopLevelHelpers.cmake @@ -505,3 +505,41 @@ function(qt_internal_foreach_repo_run) ) message("Successes: ${count_success}") endfunction() + +# The function collects repos and dependencies that are required to build +# repos listed in ARGN. If the BUILD_ is defined the 'repo' will be +# excluded from the list. +function(qt_internal_collect_modules_only out_repos) + set(initial_modules "${ARGN}") + get_filename_component(qt5_repo_dir "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE) + + # Overriding CMAKE_CURRENT_SOURCE_DIR is ugly but works + set(CMAKE_CURRENT_SOURCE_DIR "${qt5_repo_dir}") + if(NOT initial_modules) + qt_internal_find_modules(initial_modules) + endif() + + qt_internal_sort_module_dependencies("${initial_modules}" ${out_repos}) + foreach(module IN LISTS ${out_repos}) + # Check for unmet dependencies + if(DEFINED BUILD_${module} AND NOT BUILD_${module}) + list(REMOVE_ITEM ${out_repos} ${module}) + continue() + endif() + get_property(required_deps GLOBAL PROPERTY QT_REQUIRED_DEPS_FOR_${module}) + get_property(dependencies GLOBAL PROPERTY QT_DEPS_FOR_${module}) + foreach(dep IN LISTS dependencies) + set(required FALSE) + if(dep IN_LIST required_deps) + set(required TRUE) + endif() + if(required AND DEFINED BUILD_${dep} AND NOT BUILD_${dep}) + set(BUILD_${module} FALSE) + list(REMOVE_ITEM ${out_repos} ${module}) + break() + endif() + endforeach() + endforeach() + + set(${out_repos} "${${out_repos}}" PARENT_SCOPE) +endfunction()