diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2020-01-08 17:04:43 +0100 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-03-18 21:26:26 +0100 |
commit | 0739a54a4bd05e24d20989ecb3c4da79d903d542 (patch) | |
tree | fd5e2faa28a5be979baa9a1657e8add810651cd3 /CMakeLists.txt | |
parent | a59826003e2e361bbe1beb9c899afc2ca25bc736 (diff) |
Read module list from .gitmodules
This patch mimics the behavior of qt.pro, where the module list is
extracted from the .gitmodules file and then topologically sorted
based on the modules dependencies.
This patch also introduces a small check to make sure all the required
dependencies are met and will be built.
Change-Id: Idd3df9b618805ca0b2347eac57aaa39c1bcdb3dd
Reviewed-by: Qt CMake Build Bot
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
(cherry picked from commit b01225fb3257fa4c26d364c9a8fe5e19a04039e3)
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 80 |
1 files changed, 72 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e54ec11a..98b44543 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,12 +10,39 @@ project(Qt # Required so we can call ctest from the root build directory enable_testing() +set(qt_module_prop_prefix "__qt_prop_") +function(extract_git_submodules out_module_list) + set(modules "") + set(current_module "") + set(module_list "") + file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/.gitmodules" lines) + foreach(line IN LISTS lines) + string(REGEX REPLACE "^\\[submodule \"([^\"]+)\"\\]$" "\\1" module ${line}) + if (NOT module STREQUAL line) + list(APPEND modules ${modules}) + set(current_module ${module}) + list(APPEND module_list ${module}) + else() + string(REGEX REPLACE "^\t([^ =]+) *=.*$" "\\1" prop ${line}) + if (NOT prop STREQUAL line) + string(REGEX REPLACE "^[^=]+= *" "" value ${line}) + string(REPLACE " " ";" value ${value}) + set("${qt_module_prop_prefix}${current_module}_${prop}" "${value}" PARENT_SCOPE) + else() + message(FATAL_ERROR "Malformed line ${CMAKE_CURRENT_SOURCE_DIR}/.gitmodules: ${line}") + endif() + endif() + endforeach() + set(${out_module_list} ${module_list} PARENT_SCOPE) +endfunction() + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") if (NOT QT_BUILD_STANDALONE_TESTS) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/qtbase/cmake") endif() include(ECMOptionalAddSubdirectory) +include(TopologicalSort) # Use the CMake config files from the binary dir list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}") @@ -25,21 +52,58 @@ if (NOT QT_BUILD_STANDALONE_TESTS) endif() set(QT_SUPERBUILD TRUE) +# Get submodules list +extract_git_submodules(git_module_list) +foreach(module IN LISTS git_module_list) + # Prepare a list of dependencies to be fed into topological sort + set("${qt_module_prop_prefix}${module}_all_dependencies" + ${${qt_module_prop_prefix}${module}_depends} + ${${qt_module_prop_prefix}${module}_recommends} + ${${qt_module_prop_prefix}${module}_serialize} + ) +endforeach() + +# Sort by dependencies +topological_sort(git_module_list "${qt_module_prop_prefix}" "_all_dependencies") + +# Check for unknown modules +foreach(module IN LISTS git_module_list) + foreach(dep IN LISTS "${qt_module_prop_prefix}${module}_all_dependencies") + if (NOT dep IN_LIST git_module_list) + message(FATAL_ERROR "Module '${module}' depends on undeclared module '${dep}'") + endif() + endforeach() +endforeach() + # qtbase is always needed +list(REMOVE_ITEM git_module_list qtbase) add_subdirectory(qtbase) if (NOT QT_BUILD_STANDALONE_TESTS) list(APPEND CMAKE_PREFIX_PATH "${QtBase_BINARY_DIR}") endif() -ecm_optional_add_subdirectory(qtconnectivty) -ecm_optional_add_subdirectory(qtdeclarative) -ecm_optional_add_subdirectory(qtgraphicaleffects) -ecm_optional_add_subdirectory(qtimageformats) -ecm_optional_add_subdirectory(qtsvg) -ecm_optional_add_subdirectory(qtquickcontrols2) -ecm_optional_add_subdirectory(qtgamepad) -ecm_optional_add_subdirectory(qttools) +foreach(module IN LISTS git_module_list) + ecm_optional_add_subdirectory(${module}) +endforeach() + +# Check for unmet dependencies +foreach(module IN LISTS git_module_list) + foreach(dep IN LISTS "${qt_module_prop_prefix}${module}_depends") + if (dep STREQUAL qtbase) + # Always available skip + continue() + endif() + if (DEFINED BUILD_${module} AND BUILD_${module}) + if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dep}/CMakeLists.txt") + message(FATAL_ERROR "Module '${module} depends on '${dep}', but ${deps}'s CMakeLists.txt couldn't be found.\n") + endif() + if(NOT BUILD_${dep}) + message(FATAL_ERROR "Module '${module} depends on '${dep}', but ${deps} will not be built.\n") + endif() + endif() + endforeach() +endforeach() if(NOT QT_BUILD_STANDALONE_TESTS) |