Files
Library/cmake/Module.cmake
T
faumarayandClaude Fable 5 28b94883fd Restructure into umbrella modules (~55 -> 16 targets)
Headers move, CMake targets merge, C++ namespaces stay unchanged:
- Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant
- Functional: Pipeline, Either, Result, Retry
- Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval
- Math: +Matrix, Numeric, Random, Histogram
- Text: Str, Format, Tokenizer, Diff, Encoding, Semver
- Data: Json, Csv, Ini
- Async: Coro, Concurrency, EventBus, Observable
- Time: +Bench
- Log: Log facade + Logging framework (facade now header-only, breaking
  the Stacktrace<->Log link cycle the merge would have created)
- System: FileSystem + Process
- Configuration: +Argparse
- Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail

Module system fixes:
- OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no
  longer depends on the alphabetical discovery order of src/ subdirs
  (Testing -> Text would have been silently dropped).
- Every header-only module now has a tracked module.cmake; previously the
  empty src/<Name> marker dirs were untracked, so a fresh clone would have
  silently skipped those modules.
- VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT.

Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files
prefixed: ResultBasic etc.). Test count verified identical (831) before and
after. README/CLAUDE.md module tables updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 18:50:02 +03:00

164 lines
6.5 KiB
CMake

set_property(GLOBAL PROPERTY VOID_MODULES "")
set_property(GLOBAL PROPERTY VOID_EXT_DEPS "")
set_property(GLOBAL PROPERTY VOID_PENDING_OPTIONAL_DEPS "")
function(void_add_module MODULE_NAME)
cmake_parse_arguments(ARG "" ""
"INTERNAL_DEPS;EXTERNAL_DEPS;OPTIONAL_DEPS;DEPS_WIN32;DEPS_UNIX;OPTIONS_WIN32;OPTIONS_UNIX"
${ARGN})
set(TGT ${PROJECT_NAME}_${MODULE_NAME})
set(ALIAS ${PROJECT_NAME}::${MODULE_NAME})
file(GLOB_RECURSE SRC CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/${MODULE_NAME}/*.cpp")
file(GLOB_RECURSE HDR CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/Void/${MODULE_NAME}/*.hpp")
if(NOT SRC AND NOT HDR)
return()
endif()
if(NOT SRC)
set(LIB_TYPE "INTERFACE")
set(SCOPE "INTERFACE")
add_library(${TGT} INTERFACE)
target_compile_features(${TGT} INTERFACE cxx_std_26)
else()
set(LIB_TYPE "SHARED")
set(SCOPE "PUBLIC")
if (MODULE_NAME STREQUAL "Testing")
add_library(${TGT} STATIC)
else()
add_library(${TGT} SHARED)
endif()
target_sources(${TGT} PRIVATE ${SRC})
target_compile_features(${TGT} PUBLIC cxx_std_26)
endif()
add_library(${ALIAS} ALIAS ${TGT})
set_property(GLOBAL APPEND PROPERTY VOID_MODULES ${MODULE_NAME})
foreach(ext_dep IN LISTS ARG_EXTERNAL_DEPS)
string(REGEX REPLACE "::.*" "" BASE_DEP ${ext_dep})
set_property(GLOBAL APPEND PROPERTY VOID_EXT_DEPS ${BASE_DEP})
include(cmake/Dependencies.cmake)
void_fetch_dependency(${BASE_DEP})
endforeach()
foreach(int_dep IN LISTS ARG_INTERNAL_DEPS)
target_link_libraries(${TGT} ${SCOPE} ${PROJECT_NAME}::${int_dep})
endforeach()
# Optional deps are resolved in void_finalize_modules() after every
# module has been discovered, so resolution does not depend on the
# alphabetical order in which src/ subdirectories are processed.
if(ARG_OPTIONAL_DEPS)
string(REPLACE ";" "," _opt_list "${ARG_OPTIONAL_DEPS}")
set_property(GLOBAL APPEND PROPERTY VOID_PENDING_OPTIONAL_DEPS
"${TGT}|${SCOPE}|${_opt_list}")
endif()
if(ARG_EXTERNAL_DEPS)
target_link_libraries(${TGT} ${SCOPE} ${ARG_EXTERNAL_DEPS})
endif()
foreach(_lib IN LISTS ARG_DEPS_WIN32)
target_link_libraries(${TGT} ${SCOPE} "$<$<PLATFORM_ID:Windows>:${_lib}>")
endforeach()
foreach(_lib IN LISTS ARG_DEPS_UNIX)
target_link_libraries(${TGT} ${SCOPE} "$<$<NOT:$<PLATFORM_ID:Windows>>:${_lib}>")
endforeach()
if(SRC)
foreach(_opt IN LISTS ARG_OPTIONS_WIN32)
target_compile_options(${TGT} PRIVATE "$<$<PLATFORM_ID:Windows>:${_opt}>")
endforeach()
foreach(_opt IN LISTS ARG_OPTIONS_UNIX)
target_compile_options(${TGT} PRIVATE "$<$<NOT:$<PLATFORM_ID:Windows>>:${_opt}>")
endforeach()
if(VOID_WARNINGS_AS_ERRORS)
target_compile_options(${TGT} PRIVATE
"$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-Wall;-Wextra;-Wpedantic;-Werror;-Wno-missing-field-initializers>"
"$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-missing-designated-field-initializers>"
"$<$<CXX_COMPILER_ID:MSVC>:/W4;/WX>"
)
endif()
if(VOID_ENABLE_ASAN)
target_compile_options(${TGT} PUBLIC
"$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-fsanitize=address;-fno-omit-frame-pointer>"
)
target_link_options(${TGT} PUBLIC
"$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-fsanitize=address>"
)
endif()
if(VOID_ENABLE_UBSAN)
target_compile_options(${TGT} PUBLIC
"$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-fsanitize=undefined>"
)
target_link_options(${TGT} PUBLIC
"$<$<CXX_COMPILER_ID:GNU,Clang,AppleClang>:-fsanitize=undefined>"
)
endif()
if(VOID_ENABLE_COVERAGE)
target_compile_options(${TGT} PUBLIC
"$<$<CXX_COMPILER_ID:GNU>:--coverage;-fprofile-update=atomic>"
"$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fprofile-instr-generate;-fcoverage-mapping>"
)
target_link_options(${TGT} PUBLIC
"$<$<CXX_COMPILER_ID:GNU>:--coverage>"
"$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fprofile-instr-generate>"
)
endif()
endif()
set_target_properties(${TGT} PROPERTIES
CXX_STANDARD 26
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
EXPORT_NAME ${MODULE_NAME}
)
# GCC 16+ exposes experimental C++26 reflection (P2996) via -freflection.
# Apply it to every module unconditionally so any module is free to use
# ^^T / std::meta::* without per-module wiring.
if(SRC AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16)
target_compile_options(${TGT} PUBLIC -freflection)
endif()
target_sources(${TGT} ${SCOPE} FILE_SET HEADERS BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" FILES ${HDR})
target_include_directories(${TGT} ${SCOPE}
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
install(TARGETS ${TGT} EXPORT ${EXPORT_SET_NAME}
FILE_SET HEADERS DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endfunction()
# Resolve OPTIONAL_DEPS recorded by void_add_module(). Must be called once
# after all modules have been discovered. Each present dep is linked and
# defines VOID_HAS_<UPPERCASE_DEP> on the dependent target.
function(void_finalize_modules)
get_property(_modules GLOBAL PROPERTY VOID_MODULES)
get_property(_pending GLOBAL PROPERTY VOID_PENDING_OPTIONAL_DEPS)
foreach(_entry IN LISTS _pending)
string(REPLACE "|" ";" _parts "${_entry}")
list(GET _parts 0 _tgt)
list(GET _parts 1 _scope)
list(GET _parts 2 _deps_packed)
string(REPLACE "," ";" _deps "${_deps_packed}")
foreach(_dep IN LISTS _deps)
if(_dep IN_LIST _modules)
target_link_libraries(${_tgt} ${_scope} ${PROJECT_NAME}::${_dep})
string(TOUPPER ${_dep} _upper)
target_compile_definitions(${_tgt} ${_scope} VOID_HAS_${_upper})
endif()
endforeach()
endforeach()
endfunction()