From 5a74df95f25f3f2012bc182a0dad665136740ec0 Mon Sep 17 00:00:00 2001 From: Torsten Wierschin Date: Fri, 17 Jul 2026 13:28:53 +0200 Subject: [PATCH] chore(cmake): honor -DMIGRATE_MODULE to add only necessary subdirectories for per-module migration builds\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CMakeLists.txt | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7657ca7a..f7cb10bf6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -326,11 +326,35 @@ if(NOT RTI_FOUND) endforeach() endif() -ADD_SUBDIRECTORY(TetraIF) -ADD_SUBDIRECTORY(Z/src) -ADD_SUBDIRECTORY(Lts) +# Respect MIGRATE_MODULE: when set to a relative path (e.g. "Lts/Common"), only add +# the top-level subdirectories required to configure/build that module. This allows +# per-module migration builds via -DMIGRATE_MODULE=. +if(NOT DEFINED MIGRATE_MODULE) + set(MIGRATE_MODULE "" CACHE STRING "If set, only add subdirectories covering this module (path relative to repo root)") +endif() + +function(NGL_ADD_SUBDIR_GUARDED subdir) + if(MIGRATE_MODULE STREQUAL "") + add_subdirectory(${subdir}) + else() + # normalize to forward slashes + string(REPLACE "\\" "/" _mig "${MIGRATE_MODULE}") + string(REPLACE "\\" "/" _sub "${subdir}") + if(_mig MATCHES "^${_sub}(/|$)" OR _sub MATCHES "^${_mig}(/|$)") + message(STATUS "Including subdir ${subdir} because MIGRATE_MODULE=${MIGRATE_MODULE}") + add_subdirectory(${subdir}) + else() + message(STATUS "Skipping subdir ${subdir} because MIGRATE_MODULE=${MIGRATE_MODULE}") + endif() + endif() +endfunction() + +# Add only guarded subdirectories +NGL_ADD_SUBDIR_GUARDED(TetraIF) +NGL_ADD_SUBDIR_GUARDED(Z/src) +NGL_ADD_SUBDIR_GUARDED(Lts) # at last, to make sure we get all targets in NGL_TS_TARGETS property -ADD_SUBDIRECTORY(translations) +NGL_ADD_SUBDIR_GUARDED(translations) #-----------------------------------------------------------------------------------------------------