From 0f2a480ced0a711525a382a26ad235e935afb76a Mon Sep 17 00:00:00 2001 From: Petri Savolainen Date: Fri, 3 Jul 2026 12:13:37 +0300 Subject: [PATCH 1/2] =?UTF-8?q?Phase=202.0:=20modules=20scaffolding=20?= =?UTF-8?q?=E2=80=94=20StreamrModules.cmake,=20bench.sh,=20macOS=20baselin?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - cmake/StreamrModules.cmake (canonical + synced per-package): Ninja and non-AppleClang guards, CMP0155 NEW, streamr_add_module_library() / streamr_enable_imports() helpers, STREAMR_IMPORT_STD opt-in (OFF). Scanning stays globally OFF; targets opt in via the helpers. - bench.sh: clean / incremental [header] / trace modes on the root single-tree build; trace integrates ClangBuildAnalyzer. - Baselines recorded in MODERNIZATION.md: clean 8s+102s (108 TUs); incremental StreamID.hpp 10 TUs/19s, SLogger.hpp 48 TUs/62-70s; 93% of compile CPU is frontend parsing; top expensive headers are DhtRpc.pb.h, SLogger/Logger.hpp, RpcCommunicator.hpp — the exact stack the module partitions wrap. Co-Authored-By: Claude Fable 5 --- .gitignore | 2 + MODERNIZATION.md | 47 +++++++ bench.sh | 115 ++++++++++++++++++ cmake/StreamrModules.cmake | 84 +++++++++++++ packages/streamr-dht/StreamrModules.cmake | 84 +++++++++++++ .../streamr-eventemitter/StreamrModules.cmake | 84 +++++++++++++ packages/streamr-json/StreamrModules.cmake | 84 +++++++++++++ .../StreamrModules.cmake | 84 +++++++++++++ packages/streamr-logger/StreamrModules.cmake | 84 +++++++++++++ .../streamr-proto-rpc/StreamrModules.cmake | 84 +++++++++++++ .../StreamrModules.cmake | 84 +++++++++++++ packages/streamr-utils/StreamrModules.cmake | 84 +++++++++++++ sync-cmake-files.sh | 2 +- 13 files changed, 921 insertions(+), 1 deletion(-) create mode 100755 bench.sh create mode 100644 cmake/StreamrModules.cmake create mode 100644 packages/streamr-dht/StreamrModules.cmake create mode 100644 packages/streamr-eventemitter/StreamrModules.cmake create mode 100644 packages/streamr-json/StreamrModules.cmake create mode 100644 packages/streamr-libstreamrproxyclient/StreamrModules.cmake create mode 100644 packages/streamr-logger/StreamrModules.cmake create mode 100644 packages/streamr-proto-rpc/StreamrModules.cmake create mode 100644 packages/streamr-trackerless-network/StreamrModules.cmake create mode 100644 packages/streamr-utils/StreamrModules.cmake diff --git a/.gitignore b/.gitignore index 5522cf05..b49f8de1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ setenvs.sh *.DS_Store* packages/streamr-libstreamrproxyclient/dist/android/StreamrProxyClient/libs/arm64-v8a/libstreamrproxyclient.so packages/streamr-libstreamrproxyclient/dist/android-library-module/StreamrProxyClient/libs/arm64-v8a/libstreamrproxyclient.so +/build-bench-trace/ +bench-trace.bin diff --git a/MODERNIZATION.md b/MODERNIZATION.md index b3ac6291..64d05af6 100644 --- a/MODERNIZATION.md +++ b/MODERNIZATION.md @@ -409,6 +409,53 @@ document/replace in 1.4. | 2.5 | streamr-trackerless-network, streamr-libstreamrproxyclient | tn `:protos` over NetworkRpc; proxyclient imports only, C header untouched; full iOS XCFramework + Android smoke. **Final metrics** | | 2.6 | Consolidation (MANDATORY, interleaved) | Per package, once its last dependent is module-based: move declarations into module purview, delete the package's `include/` tree (grep-enforced). End state: no internal headers anywhere; `#include` only for third-party, generated proto, and the C API header. Finalize lint posture; docs | +## Phase 2.0 — Scaffolding + baselines (PR pending) +- `cmake/StreamrModules.cmake` (canonical, synced to all packages): Ninja + + non-AppleClang guards, CMP0155 NEW, `streamr_add_module_library()` + (STATIC + `FILE_SET CXX_MODULES` rooted at `modules/`), + `streamr_enable_imports()` for import-using targets, and the + `STREAMR_IMPORT_STD` opt-in (OFF; requires the CMake-version-specific + experimental UUID to be supplied explicitly). Module scanning stays + globally OFF — targets opt in via the helpers, so clangd's compile + commands stay clean for non-migrated code. +- `bench.sh`: `clean` / `incremental [header]` / `trace` modes measuring the + root single-tree build; prints host/compiler/parallelism with every run. + `trace` uses a separate `build-bench-trace/` tree (shares + `build/vcpkg_installed`) + ClangBuildAnalyzer if installed. + +### Baseline (macOS, 2026-07-03) +Apple Silicon dev machine, 10 cores used, Homebrew clang 22.1.8, CMake 4.3, +Debug, Ninja; root single tree (108 TUs: all tests + generated proto + +proxyclient). Single runs on an idle machine. + +| Metric | Baseline | +|---|---| +| Clean build | configure 8 s + build **102 s** | +| Incremental: touch `streamr-utils/StreamID.hpp` | 10 TUs, **19 s** | +| Incremental: touch `streamr-logger/SLogger.hpp` | 48 TUs, **62–70 s** | +| Compile CPU split (`-ftime-trace`) | frontend parse **859 s** vs backend codegen **61 s** → **93% parsing** | + +ClangBuildAnalyzer expensive headers (cumulative parse, count): +1. `DhtRpc.pb.h` **96.0 s** (33×, avg 2.9 s) — becomes `streamr.dht:protos` +2. `gtest/gtest.h` 84.3 s (87×) — stays `#include` (macros) +3. `SLogger.hpp` **80.8 s** (47×) — becomes a `streamr.logger` partition +4. `Logger.hpp` 66.4 s (50×) — ditto +5. `ConnectionManager.hpp` 38.2 s (4×, **avg 9.5 s per inclusion**) +6. `RpcCommunicator.hpp` 34.7 s (21×) +7. `Identifiers.hpp` 31.2 s (31×) + +Top template-instantiation sets (nlohmann parse ~22 s, `std::format` ~13 s, +magic_enum ~13 s) — instantiation cost that modules will NOT move (recorded +so post-migration numbers are read fairly). + +The data confirms the plan's premise: >90% of compile CPU is repeated +header parsing, and the top of the expensive list is exactly the +`.pb.h`/streamr-header stack the partitions wrap. + +- Linux and iOS baselines: not yet captured (macOS dev iteration is the + primary metric). Capture the Linux numbers on the self-hosted arm64 box + and an iOS build-only timing before the Phase 2.4 checkpoint. + ## Lint/IDE survival - During the façade stage, headers remain the fully-linted source of truth (`lint.sh` globs only `*.hpp/*.cpp`); `.cppm` added to clang-format only. diff --git a/bench.sh b/bench.sh new file mode 100755 index 00000000..0078fa64 --- /dev/null +++ b/bench.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +# Compile-time benchmark harness for the C++ modules migration +# (MODERNIZATION.md Part 2). Measures the ROOT single-tree build — the +# workflow the migration optimizes (it compiles every package's tests, the +# generated protobuf sources and the proxy client in one Ninja graph). +# Results are recorded per phase in MODERNIZATION.md. +# +# Usage: +# ./bench.sh clean clean-build wall-clock (root tree only; keeps +# build/vcpkg_installed and the per-package build +# dirs — their exported configs are needed by the +# root configure) +# ./bench.sh incremental [header] +# rebuild after touching a mid-stack header +# (default: streamr-utils/StreamID.hpp, included +# by most dht/trackerless-network TUs) +# ./bench.sh trace clean build in a separate build-bench-trace/ +# tree with -ftime-trace; if ClangBuildAnalyzer is +# installed (brew install clang-build-analyzer), +# prints the expensive-headers/templates report +# +# Methodology: run on an otherwise idle machine, 2-3 repetitions, take the +# best. All modes print a single "BENCH : ..." summary line at the end. + +set -e + +if [ -z "$VCPKG_ROOT" ]; then + echo "Error: environment not set up. Run 'source install-prerequisities.sh' or 'source setenvs.sh' first." + exit 1 +fi + +MODE="$1" +BUILD_TYPE="${BENCH_BUILD_TYPE:-Debug}" + +print_env() { + echo "bench environment:" + echo " host: $(sysctl -n machdep.cpu.brand_string 2>/dev/null || grep -m1 'model name' /proc/cpuinfo | cut -d: -f2)" + echo " cores: $(sysctl -n hw.ncpu 2>/dev/null || nproc)" + echo " parallelism: ${CMAKE_BUILD_PARALLEL_LEVEL:-ninja default}" + echo " compiler: $(${LLVM_PREFIX:+$LLVM_PREFIX/bin/}clang++ --version | head -1)" + echo " cmake: $(cmake --version | head -1)" + echo " build type: $BUILD_TYPE" +} + +configure_and_build() { + # $1 = binary dir, remaining args = extra cmake configure options + local BINDIR="$1"; shift + local T_CONF_START T_CONF_END T_BUILD_END + T_CONF_START=$(date +%s) + cmake -B "$BINDIR" -DCMAKE_BUILD_TYPE=$BUILD_TYPE "$@" . + T_CONF_END=$(date +%s) + cmake --build "$BINDIR" + T_BUILD_END=$(date +%s) + CONFIGURE_SECONDS=$((T_CONF_END - T_CONF_START)) + BUILD_SECONDS=$((T_BUILD_END - T_CONF_END)) +} + +case "$MODE" in + clean) + print_env + # Clean the root tree only: vcpkg_installed stays (dependencies are not + # what is being measured), per-package build dirs stay (the root + # configure resolves sibling packages against their exported configs). + find build -mindepth 1 -maxdepth 1 ! -name vcpkg_installed ! -name .gitignore -exec rm -rf {} + + configure_and_build build + echo "" + echo "BENCH clean: configure ${CONFIGURE_SECONDS}s, build ${BUILD_SECONDS}s (total $((CONFIGURE_SECONDS + BUILD_SECONDS))s)" + ;; + + incremental) + HEADER="${2:-packages/streamr-utils/include/streamr-utils/StreamID.hpp}" + if [ ! -f "$HEADER" ]; then + echo "Error: header not found: $HEADER" + exit 1 + fi + if [ ! -f build/build.ninja ]; then + echo "Error: no configured root build tree; run ./bench.sh clean (or ./install.sh) first." + exit 1 + fi + print_env + # Warm the graph so only the header touch is measured. + cmake --build build + touch "$HEADER" + T_START=$(date +%s) + cmake --build build + T_END=$(date +%s) + echo "" + echo "BENCH incremental ($HEADER): $((T_END - T_START))s" + ;; + + trace) + print_env + # Separate tree: -ftime-trace changes every object file, and the root + # CMakeLists pins VCPKG_INSTALLED_DIR to build/vcpkg_installed, so a + # second binary dir reuses the installed dependencies for free. + rm -rf build-bench-trace + configure_and_build build-bench-trace -DCMAKE_CXX_FLAGS=-ftime-trace + echo "" + echo "BENCH trace: configure ${CONFIGURE_SECONDS}s, build ${BUILD_SECONDS}s (with -ftime-trace)" + if command -v ClangBuildAnalyzer >/dev/null 2>&1; then + ClangBuildAnalyzer --all build-bench-trace bench-trace.bin + ClangBuildAnalyzer --analyze bench-trace.bin + rm -f bench-trace.bin + else + echo "ClangBuildAnalyzer not found (brew install clang-build-analyzer / build from" + echo "https://github.com/aras-p/ClangBuildAnalyzer) — traces are in build-bench-trace/**/*.json" + fi + ;; + + *) + echo "Usage: ./bench.sh clean | incremental [header] | trace" + exit 1 + ;; +esac diff --git a/cmake/StreamrModules.cmake b/cmake/StreamrModules.cmake new file mode 100644 index 00000000..1e46e778 --- /dev/null +++ b/cmake/StreamrModules.cmake @@ -0,0 +1,84 @@ +# CANONICAL COPY — the per-package copies in packages/*/StreamrModules.cmake +# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and +# run the sync script; do not edit the package copies directly. +# (Each package carries its own copy so that it can be published as a +# standalone vcpkg package later.) +# +# C++ named-modules build support (MODERNIZATION.md Part 2). A package +# includes this file when it starts defining module targets. Non-migrated +# packages are unaffected: the root build keeps CMAKE_CXX_SCAN_FOR_MODULES +# OFF globally (clean compile commands for clangd), and the helpers below +# re-enable scanning per target. + +# CMake's C++ modules support requires the Ninja generator (Makefiles cannot +# express the dynamically discovered module dependency graph). +if(NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "C++ modules require the Ninja generator; current generator is " + "'${CMAKE_GENERATOR}'. install-prerequisities.sh/setenvs.sh export " + "CMAKE_GENERATOR=Ninja — source one of them (and ./clean.sh once if " + "the build dir was configured with another generator).") +endif() + +# AppleClang has no CMake modules support; the build already uses Homebrew +# LLVM everywhere (homebrewClang.cmake), so this only guards misconfiguration. +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + message(FATAL_ERROR + "CMake does not support C++ modules with AppleClang. The build is " + "expected to use Homebrew LLVM (see homebrewClang.cmake / " + "LLVM_PREFIX).") +endif() + +# CMP0155 NEW: scan C++20+ sources for module dependencies by default. +# Scanning stays globally disabled via CMAKE_CXX_SCAN_FOR_MODULES OFF until +# a target opts in through the helpers below. +cmake_policy(SET CMP0155 NEW) + +# Opt-in `import std;` (experimental in CMake, OFF by default — see the +# MODERNIZATION.md decision: no rollout now). CMake gates the feature behind +# a per-version experimental UUID, so turning this on requires passing the +# UUID for the CMake version in use: +# cmake -DSTREAMR_IMPORT_STD=ON \ +# -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= ... +option(STREAMR_IMPORT_STD "Build with experimental 'import std' support" OFF) +if(STREAMR_IMPORT_STD) + if(NOT DEFINED CMAKE_EXPERIMENTAL_CXX_IMPORT_STD) + message(FATAL_ERROR + "STREAMR_IMPORT_STD=ON needs " + "-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= (the experimental " + "feature UUID documented for your CMake version in " + "Help/dev/experimental.rst of the CMake source).") + endif() + set(CMAKE_CXX_MODULE_STD ON) +endif() + +# streamr_add_module_library( FILES ...) +# +# Defines as a STATIC library whose C++ module interface units are +# the given files (FILE_SET CXX_MODULES, rooted at the package's modules/ +# directory). STATIC rather than INTERFACE: module interface units are +# compiled TUs, so even a previously header-only package gains a compiled +# archive when it grows a module. +function(streamr_add_module_library TARGET) + cmake_parse_arguments(ARG "" "" "FILES" ${ARGN}) + if(NOT ARG_FILES) + message(FATAL_ERROR "streamr_add_module_library(${TARGET}): FILES is required") + endif() + add_library(${TARGET} STATIC) + target_sources(${TARGET} + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules + FILES ${ARG_FILES}) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() + +# streamr_enable_imports() +# +# Enables module scanning on an existing target whose ordinary .cpp sources +# use `import` (e.g. a test executable of a migrated package). Without this +# the global CMAKE_CXX_SCAN_FOR_MODULES OFF would leave the import edges +# undiscovered and the build would race the BMIs. +function(streamr_enable_imports TARGET) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() diff --git a/packages/streamr-dht/StreamrModules.cmake b/packages/streamr-dht/StreamrModules.cmake new file mode 100644 index 00000000..1e46e778 --- /dev/null +++ b/packages/streamr-dht/StreamrModules.cmake @@ -0,0 +1,84 @@ +# CANONICAL COPY — the per-package copies in packages/*/StreamrModules.cmake +# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and +# run the sync script; do not edit the package copies directly. +# (Each package carries its own copy so that it can be published as a +# standalone vcpkg package later.) +# +# C++ named-modules build support (MODERNIZATION.md Part 2). A package +# includes this file when it starts defining module targets. Non-migrated +# packages are unaffected: the root build keeps CMAKE_CXX_SCAN_FOR_MODULES +# OFF globally (clean compile commands for clangd), and the helpers below +# re-enable scanning per target. + +# CMake's C++ modules support requires the Ninja generator (Makefiles cannot +# express the dynamically discovered module dependency graph). +if(NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "C++ modules require the Ninja generator; current generator is " + "'${CMAKE_GENERATOR}'. install-prerequisities.sh/setenvs.sh export " + "CMAKE_GENERATOR=Ninja — source one of them (and ./clean.sh once if " + "the build dir was configured with another generator).") +endif() + +# AppleClang has no CMake modules support; the build already uses Homebrew +# LLVM everywhere (homebrewClang.cmake), so this only guards misconfiguration. +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + message(FATAL_ERROR + "CMake does not support C++ modules with AppleClang. The build is " + "expected to use Homebrew LLVM (see homebrewClang.cmake / " + "LLVM_PREFIX).") +endif() + +# CMP0155 NEW: scan C++20+ sources for module dependencies by default. +# Scanning stays globally disabled via CMAKE_CXX_SCAN_FOR_MODULES OFF until +# a target opts in through the helpers below. +cmake_policy(SET CMP0155 NEW) + +# Opt-in `import std;` (experimental in CMake, OFF by default — see the +# MODERNIZATION.md decision: no rollout now). CMake gates the feature behind +# a per-version experimental UUID, so turning this on requires passing the +# UUID for the CMake version in use: +# cmake -DSTREAMR_IMPORT_STD=ON \ +# -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= ... +option(STREAMR_IMPORT_STD "Build with experimental 'import std' support" OFF) +if(STREAMR_IMPORT_STD) + if(NOT DEFINED CMAKE_EXPERIMENTAL_CXX_IMPORT_STD) + message(FATAL_ERROR + "STREAMR_IMPORT_STD=ON needs " + "-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= (the experimental " + "feature UUID documented for your CMake version in " + "Help/dev/experimental.rst of the CMake source).") + endif() + set(CMAKE_CXX_MODULE_STD ON) +endif() + +# streamr_add_module_library( FILES ...) +# +# Defines as a STATIC library whose C++ module interface units are +# the given files (FILE_SET CXX_MODULES, rooted at the package's modules/ +# directory). STATIC rather than INTERFACE: module interface units are +# compiled TUs, so even a previously header-only package gains a compiled +# archive when it grows a module. +function(streamr_add_module_library TARGET) + cmake_parse_arguments(ARG "" "" "FILES" ${ARGN}) + if(NOT ARG_FILES) + message(FATAL_ERROR "streamr_add_module_library(${TARGET}): FILES is required") + endif() + add_library(${TARGET} STATIC) + target_sources(${TARGET} + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules + FILES ${ARG_FILES}) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() + +# streamr_enable_imports() +# +# Enables module scanning on an existing target whose ordinary .cpp sources +# use `import` (e.g. a test executable of a migrated package). Without this +# the global CMAKE_CXX_SCAN_FOR_MODULES OFF would leave the import edges +# undiscovered and the build would race the BMIs. +function(streamr_enable_imports TARGET) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() diff --git a/packages/streamr-eventemitter/StreamrModules.cmake b/packages/streamr-eventemitter/StreamrModules.cmake new file mode 100644 index 00000000..1e46e778 --- /dev/null +++ b/packages/streamr-eventemitter/StreamrModules.cmake @@ -0,0 +1,84 @@ +# CANONICAL COPY — the per-package copies in packages/*/StreamrModules.cmake +# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and +# run the sync script; do not edit the package copies directly. +# (Each package carries its own copy so that it can be published as a +# standalone vcpkg package later.) +# +# C++ named-modules build support (MODERNIZATION.md Part 2). A package +# includes this file when it starts defining module targets. Non-migrated +# packages are unaffected: the root build keeps CMAKE_CXX_SCAN_FOR_MODULES +# OFF globally (clean compile commands for clangd), and the helpers below +# re-enable scanning per target. + +# CMake's C++ modules support requires the Ninja generator (Makefiles cannot +# express the dynamically discovered module dependency graph). +if(NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "C++ modules require the Ninja generator; current generator is " + "'${CMAKE_GENERATOR}'. install-prerequisities.sh/setenvs.sh export " + "CMAKE_GENERATOR=Ninja — source one of them (and ./clean.sh once if " + "the build dir was configured with another generator).") +endif() + +# AppleClang has no CMake modules support; the build already uses Homebrew +# LLVM everywhere (homebrewClang.cmake), so this only guards misconfiguration. +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + message(FATAL_ERROR + "CMake does not support C++ modules with AppleClang. The build is " + "expected to use Homebrew LLVM (see homebrewClang.cmake / " + "LLVM_PREFIX).") +endif() + +# CMP0155 NEW: scan C++20+ sources for module dependencies by default. +# Scanning stays globally disabled via CMAKE_CXX_SCAN_FOR_MODULES OFF until +# a target opts in through the helpers below. +cmake_policy(SET CMP0155 NEW) + +# Opt-in `import std;` (experimental in CMake, OFF by default — see the +# MODERNIZATION.md decision: no rollout now). CMake gates the feature behind +# a per-version experimental UUID, so turning this on requires passing the +# UUID for the CMake version in use: +# cmake -DSTREAMR_IMPORT_STD=ON \ +# -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= ... +option(STREAMR_IMPORT_STD "Build with experimental 'import std' support" OFF) +if(STREAMR_IMPORT_STD) + if(NOT DEFINED CMAKE_EXPERIMENTAL_CXX_IMPORT_STD) + message(FATAL_ERROR + "STREAMR_IMPORT_STD=ON needs " + "-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= (the experimental " + "feature UUID documented for your CMake version in " + "Help/dev/experimental.rst of the CMake source).") + endif() + set(CMAKE_CXX_MODULE_STD ON) +endif() + +# streamr_add_module_library( FILES ...) +# +# Defines as a STATIC library whose C++ module interface units are +# the given files (FILE_SET CXX_MODULES, rooted at the package's modules/ +# directory). STATIC rather than INTERFACE: module interface units are +# compiled TUs, so even a previously header-only package gains a compiled +# archive when it grows a module. +function(streamr_add_module_library TARGET) + cmake_parse_arguments(ARG "" "" "FILES" ${ARGN}) + if(NOT ARG_FILES) + message(FATAL_ERROR "streamr_add_module_library(${TARGET}): FILES is required") + endif() + add_library(${TARGET} STATIC) + target_sources(${TARGET} + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules + FILES ${ARG_FILES}) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() + +# streamr_enable_imports() +# +# Enables module scanning on an existing target whose ordinary .cpp sources +# use `import` (e.g. a test executable of a migrated package). Without this +# the global CMAKE_CXX_SCAN_FOR_MODULES OFF would leave the import edges +# undiscovered and the build would race the BMIs. +function(streamr_enable_imports TARGET) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() diff --git a/packages/streamr-json/StreamrModules.cmake b/packages/streamr-json/StreamrModules.cmake new file mode 100644 index 00000000..1e46e778 --- /dev/null +++ b/packages/streamr-json/StreamrModules.cmake @@ -0,0 +1,84 @@ +# CANONICAL COPY — the per-package copies in packages/*/StreamrModules.cmake +# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and +# run the sync script; do not edit the package copies directly. +# (Each package carries its own copy so that it can be published as a +# standalone vcpkg package later.) +# +# C++ named-modules build support (MODERNIZATION.md Part 2). A package +# includes this file when it starts defining module targets. Non-migrated +# packages are unaffected: the root build keeps CMAKE_CXX_SCAN_FOR_MODULES +# OFF globally (clean compile commands for clangd), and the helpers below +# re-enable scanning per target. + +# CMake's C++ modules support requires the Ninja generator (Makefiles cannot +# express the dynamically discovered module dependency graph). +if(NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "C++ modules require the Ninja generator; current generator is " + "'${CMAKE_GENERATOR}'. install-prerequisities.sh/setenvs.sh export " + "CMAKE_GENERATOR=Ninja — source one of them (and ./clean.sh once if " + "the build dir was configured with another generator).") +endif() + +# AppleClang has no CMake modules support; the build already uses Homebrew +# LLVM everywhere (homebrewClang.cmake), so this only guards misconfiguration. +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + message(FATAL_ERROR + "CMake does not support C++ modules with AppleClang. The build is " + "expected to use Homebrew LLVM (see homebrewClang.cmake / " + "LLVM_PREFIX).") +endif() + +# CMP0155 NEW: scan C++20+ sources for module dependencies by default. +# Scanning stays globally disabled via CMAKE_CXX_SCAN_FOR_MODULES OFF until +# a target opts in through the helpers below. +cmake_policy(SET CMP0155 NEW) + +# Opt-in `import std;` (experimental in CMake, OFF by default — see the +# MODERNIZATION.md decision: no rollout now). CMake gates the feature behind +# a per-version experimental UUID, so turning this on requires passing the +# UUID for the CMake version in use: +# cmake -DSTREAMR_IMPORT_STD=ON \ +# -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= ... +option(STREAMR_IMPORT_STD "Build with experimental 'import std' support" OFF) +if(STREAMR_IMPORT_STD) + if(NOT DEFINED CMAKE_EXPERIMENTAL_CXX_IMPORT_STD) + message(FATAL_ERROR + "STREAMR_IMPORT_STD=ON needs " + "-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= (the experimental " + "feature UUID documented for your CMake version in " + "Help/dev/experimental.rst of the CMake source).") + endif() + set(CMAKE_CXX_MODULE_STD ON) +endif() + +# streamr_add_module_library( FILES ...) +# +# Defines as a STATIC library whose C++ module interface units are +# the given files (FILE_SET CXX_MODULES, rooted at the package's modules/ +# directory). STATIC rather than INTERFACE: module interface units are +# compiled TUs, so even a previously header-only package gains a compiled +# archive when it grows a module. +function(streamr_add_module_library TARGET) + cmake_parse_arguments(ARG "" "" "FILES" ${ARGN}) + if(NOT ARG_FILES) + message(FATAL_ERROR "streamr_add_module_library(${TARGET}): FILES is required") + endif() + add_library(${TARGET} STATIC) + target_sources(${TARGET} + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules + FILES ${ARG_FILES}) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() + +# streamr_enable_imports() +# +# Enables module scanning on an existing target whose ordinary .cpp sources +# use `import` (e.g. a test executable of a migrated package). Without this +# the global CMAKE_CXX_SCAN_FOR_MODULES OFF would leave the import edges +# undiscovered and the build would race the BMIs. +function(streamr_enable_imports TARGET) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() diff --git a/packages/streamr-libstreamrproxyclient/StreamrModules.cmake b/packages/streamr-libstreamrproxyclient/StreamrModules.cmake new file mode 100644 index 00000000..1e46e778 --- /dev/null +++ b/packages/streamr-libstreamrproxyclient/StreamrModules.cmake @@ -0,0 +1,84 @@ +# CANONICAL COPY — the per-package copies in packages/*/StreamrModules.cmake +# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and +# run the sync script; do not edit the package copies directly. +# (Each package carries its own copy so that it can be published as a +# standalone vcpkg package later.) +# +# C++ named-modules build support (MODERNIZATION.md Part 2). A package +# includes this file when it starts defining module targets. Non-migrated +# packages are unaffected: the root build keeps CMAKE_CXX_SCAN_FOR_MODULES +# OFF globally (clean compile commands for clangd), and the helpers below +# re-enable scanning per target. + +# CMake's C++ modules support requires the Ninja generator (Makefiles cannot +# express the dynamically discovered module dependency graph). +if(NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "C++ modules require the Ninja generator; current generator is " + "'${CMAKE_GENERATOR}'. install-prerequisities.sh/setenvs.sh export " + "CMAKE_GENERATOR=Ninja — source one of them (and ./clean.sh once if " + "the build dir was configured with another generator).") +endif() + +# AppleClang has no CMake modules support; the build already uses Homebrew +# LLVM everywhere (homebrewClang.cmake), so this only guards misconfiguration. +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + message(FATAL_ERROR + "CMake does not support C++ modules with AppleClang. The build is " + "expected to use Homebrew LLVM (see homebrewClang.cmake / " + "LLVM_PREFIX).") +endif() + +# CMP0155 NEW: scan C++20+ sources for module dependencies by default. +# Scanning stays globally disabled via CMAKE_CXX_SCAN_FOR_MODULES OFF until +# a target opts in through the helpers below. +cmake_policy(SET CMP0155 NEW) + +# Opt-in `import std;` (experimental in CMake, OFF by default — see the +# MODERNIZATION.md decision: no rollout now). CMake gates the feature behind +# a per-version experimental UUID, so turning this on requires passing the +# UUID for the CMake version in use: +# cmake -DSTREAMR_IMPORT_STD=ON \ +# -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= ... +option(STREAMR_IMPORT_STD "Build with experimental 'import std' support" OFF) +if(STREAMR_IMPORT_STD) + if(NOT DEFINED CMAKE_EXPERIMENTAL_CXX_IMPORT_STD) + message(FATAL_ERROR + "STREAMR_IMPORT_STD=ON needs " + "-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= (the experimental " + "feature UUID documented for your CMake version in " + "Help/dev/experimental.rst of the CMake source).") + endif() + set(CMAKE_CXX_MODULE_STD ON) +endif() + +# streamr_add_module_library( FILES ...) +# +# Defines as a STATIC library whose C++ module interface units are +# the given files (FILE_SET CXX_MODULES, rooted at the package's modules/ +# directory). STATIC rather than INTERFACE: module interface units are +# compiled TUs, so even a previously header-only package gains a compiled +# archive when it grows a module. +function(streamr_add_module_library TARGET) + cmake_parse_arguments(ARG "" "" "FILES" ${ARGN}) + if(NOT ARG_FILES) + message(FATAL_ERROR "streamr_add_module_library(${TARGET}): FILES is required") + endif() + add_library(${TARGET} STATIC) + target_sources(${TARGET} + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules + FILES ${ARG_FILES}) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() + +# streamr_enable_imports() +# +# Enables module scanning on an existing target whose ordinary .cpp sources +# use `import` (e.g. a test executable of a migrated package). Without this +# the global CMAKE_CXX_SCAN_FOR_MODULES OFF would leave the import edges +# undiscovered and the build would race the BMIs. +function(streamr_enable_imports TARGET) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() diff --git a/packages/streamr-logger/StreamrModules.cmake b/packages/streamr-logger/StreamrModules.cmake new file mode 100644 index 00000000..1e46e778 --- /dev/null +++ b/packages/streamr-logger/StreamrModules.cmake @@ -0,0 +1,84 @@ +# CANONICAL COPY — the per-package copies in packages/*/StreamrModules.cmake +# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and +# run the sync script; do not edit the package copies directly. +# (Each package carries its own copy so that it can be published as a +# standalone vcpkg package later.) +# +# C++ named-modules build support (MODERNIZATION.md Part 2). A package +# includes this file when it starts defining module targets. Non-migrated +# packages are unaffected: the root build keeps CMAKE_CXX_SCAN_FOR_MODULES +# OFF globally (clean compile commands for clangd), and the helpers below +# re-enable scanning per target. + +# CMake's C++ modules support requires the Ninja generator (Makefiles cannot +# express the dynamically discovered module dependency graph). +if(NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "C++ modules require the Ninja generator; current generator is " + "'${CMAKE_GENERATOR}'. install-prerequisities.sh/setenvs.sh export " + "CMAKE_GENERATOR=Ninja — source one of them (and ./clean.sh once if " + "the build dir was configured with another generator).") +endif() + +# AppleClang has no CMake modules support; the build already uses Homebrew +# LLVM everywhere (homebrewClang.cmake), so this only guards misconfiguration. +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + message(FATAL_ERROR + "CMake does not support C++ modules with AppleClang. The build is " + "expected to use Homebrew LLVM (see homebrewClang.cmake / " + "LLVM_PREFIX).") +endif() + +# CMP0155 NEW: scan C++20+ sources for module dependencies by default. +# Scanning stays globally disabled via CMAKE_CXX_SCAN_FOR_MODULES OFF until +# a target opts in through the helpers below. +cmake_policy(SET CMP0155 NEW) + +# Opt-in `import std;` (experimental in CMake, OFF by default — see the +# MODERNIZATION.md decision: no rollout now). CMake gates the feature behind +# a per-version experimental UUID, so turning this on requires passing the +# UUID for the CMake version in use: +# cmake -DSTREAMR_IMPORT_STD=ON \ +# -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= ... +option(STREAMR_IMPORT_STD "Build with experimental 'import std' support" OFF) +if(STREAMR_IMPORT_STD) + if(NOT DEFINED CMAKE_EXPERIMENTAL_CXX_IMPORT_STD) + message(FATAL_ERROR + "STREAMR_IMPORT_STD=ON needs " + "-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= (the experimental " + "feature UUID documented for your CMake version in " + "Help/dev/experimental.rst of the CMake source).") + endif() + set(CMAKE_CXX_MODULE_STD ON) +endif() + +# streamr_add_module_library( FILES ...) +# +# Defines as a STATIC library whose C++ module interface units are +# the given files (FILE_SET CXX_MODULES, rooted at the package's modules/ +# directory). STATIC rather than INTERFACE: module interface units are +# compiled TUs, so even a previously header-only package gains a compiled +# archive when it grows a module. +function(streamr_add_module_library TARGET) + cmake_parse_arguments(ARG "" "" "FILES" ${ARGN}) + if(NOT ARG_FILES) + message(FATAL_ERROR "streamr_add_module_library(${TARGET}): FILES is required") + endif() + add_library(${TARGET} STATIC) + target_sources(${TARGET} + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules + FILES ${ARG_FILES}) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() + +# streamr_enable_imports() +# +# Enables module scanning on an existing target whose ordinary .cpp sources +# use `import` (e.g. a test executable of a migrated package). Without this +# the global CMAKE_CXX_SCAN_FOR_MODULES OFF would leave the import edges +# undiscovered and the build would race the BMIs. +function(streamr_enable_imports TARGET) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() diff --git a/packages/streamr-proto-rpc/StreamrModules.cmake b/packages/streamr-proto-rpc/StreamrModules.cmake new file mode 100644 index 00000000..1e46e778 --- /dev/null +++ b/packages/streamr-proto-rpc/StreamrModules.cmake @@ -0,0 +1,84 @@ +# CANONICAL COPY — the per-package copies in packages/*/StreamrModules.cmake +# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and +# run the sync script; do not edit the package copies directly. +# (Each package carries its own copy so that it can be published as a +# standalone vcpkg package later.) +# +# C++ named-modules build support (MODERNIZATION.md Part 2). A package +# includes this file when it starts defining module targets. Non-migrated +# packages are unaffected: the root build keeps CMAKE_CXX_SCAN_FOR_MODULES +# OFF globally (clean compile commands for clangd), and the helpers below +# re-enable scanning per target. + +# CMake's C++ modules support requires the Ninja generator (Makefiles cannot +# express the dynamically discovered module dependency graph). +if(NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "C++ modules require the Ninja generator; current generator is " + "'${CMAKE_GENERATOR}'. install-prerequisities.sh/setenvs.sh export " + "CMAKE_GENERATOR=Ninja — source one of them (and ./clean.sh once if " + "the build dir was configured with another generator).") +endif() + +# AppleClang has no CMake modules support; the build already uses Homebrew +# LLVM everywhere (homebrewClang.cmake), so this only guards misconfiguration. +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + message(FATAL_ERROR + "CMake does not support C++ modules with AppleClang. The build is " + "expected to use Homebrew LLVM (see homebrewClang.cmake / " + "LLVM_PREFIX).") +endif() + +# CMP0155 NEW: scan C++20+ sources for module dependencies by default. +# Scanning stays globally disabled via CMAKE_CXX_SCAN_FOR_MODULES OFF until +# a target opts in through the helpers below. +cmake_policy(SET CMP0155 NEW) + +# Opt-in `import std;` (experimental in CMake, OFF by default — see the +# MODERNIZATION.md decision: no rollout now). CMake gates the feature behind +# a per-version experimental UUID, so turning this on requires passing the +# UUID for the CMake version in use: +# cmake -DSTREAMR_IMPORT_STD=ON \ +# -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= ... +option(STREAMR_IMPORT_STD "Build with experimental 'import std' support" OFF) +if(STREAMR_IMPORT_STD) + if(NOT DEFINED CMAKE_EXPERIMENTAL_CXX_IMPORT_STD) + message(FATAL_ERROR + "STREAMR_IMPORT_STD=ON needs " + "-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= (the experimental " + "feature UUID documented for your CMake version in " + "Help/dev/experimental.rst of the CMake source).") + endif() + set(CMAKE_CXX_MODULE_STD ON) +endif() + +# streamr_add_module_library( FILES ...) +# +# Defines as a STATIC library whose C++ module interface units are +# the given files (FILE_SET CXX_MODULES, rooted at the package's modules/ +# directory). STATIC rather than INTERFACE: module interface units are +# compiled TUs, so even a previously header-only package gains a compiled +# archive when it grows a module. +function(streamr_add_module_library TARGET) + cmake_parse_arguments(ARG "" "" "FILES" ${ARGN}) + if(NOT ARG_FILES) + message(FATAL_ERROR "streamr_add_module_library(${TARGET}): FILES is required") + endif() + add_library(${TARGET} STATIC) + target_sources(${TARGET} + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules + FILES ${ARG_FILES}) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() + +# streamr_enable_imports() +# +# Enables module scanning on an existing target whose ordinary .cpp sources +# use `import` (e.g. a test executable of a migrated package). Without this +# the global CMAKE_CXX_SCAN_FOR_MODULES OFF would leave the import edges +# undiscovered and the build would race the BMIs. +function(streamr_enable_imports TARGET) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() diff --git a/packages/streamr-trackerless-network/StreamrModules.cmake b/packages/streamr-trackerless-network/StreamrModules.cmake new file mode 100644 index 00000000..1e46e778 --- /dev/null +++ b/packages/streamr-trackerless-network/StreamrModules.cmake @@ -0,0 +1,84 @@ +# CANONICAL COPY — the per-package copies in packages/*/StreamrModules.cmake +# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and +# run the sync script; do not edit the package copies directly. +# (Each package carries its own copy so that it can be published as a +# standalone vcpkg package later.) +# +# C++ named-modules build support (MODERNIZATION.md Part 2). A package +# includes this file when it starts defining module targets. Non-migrated +# packages are unaffected: the root build keeps CMAKE_CXX_SCAN_FOR_MODULES +# OFF globally (clean compile commands for clangd), and the helpers below +# re-enable scanning per target. + +# CMake's C++ modules support requires the Ninja generator (Makefiles cannot +# express the dynamically discovered module dependency graph). +if(NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "C++ modules require the Ninja generator; current generator is " + "'${CMAKE_GENERATOR}'. install-prerequisities.sh/setenvs.sh export " + "CMAKE_GENERATOR=Ninja — source one of them (and ./clean.sh once if " + "the build dir was configured with another generator).") +endif() + +# AppleClang has no CMake modules support; the build already uses Homebrew +# LLVM everywhere (homebrewClang.cmake), so this only guards misconfiguration. +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + message(FATAL_ERROR + "CMake does not support C++ modules with AppleClang. The build is " + "expected to use Homebrew LLVM (see homebrewClang.cmake / " + "LLVM_PREFIX).") +endif() + +# CMP0155 NEW: scan C++20+ sources for module dependencies by default. +# Scanning stays globally disabled via CMAKE_CXX_SCAN_FOR_MODULES OFF until +# a target opts in through the helpers below. +cmake_policy(SET CMP0155 NEW) + +# Opt-in `import std;` (experimental in CMake, OFF by default — see the +# MODERNIZATION.md decision: no rollout now). CMake gates the feature behind +# a per-version experimental UUID, so turning this on requires passing the +# UUID for the CMake version in use: +# cmake -DSTREAMR_IMPORT_STD=ON \ +# -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= ... +option(STREAMR_IMPORT_STD "Build with experimental 'import std' support" OFF) +if(STREAMR_IMPORT_STD) + if(NOT DEFINED CMAKE_EXPERIMENTAL_CXX_IMPORT_STD) + message(FATAL_ERROR + "STREAMR_IMPORT_STD=ON needs " + "-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= (the experimental " + "feature UUID documented for your CMake version in " + "Help/dev/experimental.rst of the CMake source).") + endif() + set(CMAKE_CXX_MODULE_STD ON) +endif() + +# streamr_add_module_library( FILES ...) +# +# Defines as a STATIC library whose C++ module interface units are +# the given files (FILE_SET CXX_MODULES, rooted at the package's modules/ +# directory). STATIC rather than INTERFACE: module interface units are +# compiled TUs, so even a previously header-only package gains a compiled +# archive when it grows a module. +function(streamr_add_module_library TARGET) + cmake_parse_arguments(ARG "" "" "FILES" ${ARGN}) + if(NOT ARG_FILES) + message(FATAL_ERROR "streamr_add_module_library(${TARGET}): FILES is required") + endif() + add_library(${TARGET} STATIC) + target_sources(${TARGET} + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules + FILES ${ARG_FILES}) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() + +# streamr_enable_imports() +# +# Enables module scanning on an existing target whose ordinary .cpp sources +# use `import` (e.g. a test executable of a migrated package). Without this +# the global CMAKE_CXX_SCAN_FOR_MODULES OFF would leave the import edges +# undiscovered and the build would race the BMIs. +function(streamr_enable_imports TARGET) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() diff --git a/packages/streamr-utils/StreamrModules.cmake b/packages/streamr-utils/StreamrModules.cmake new file mode 100644 index 00000000..1e46e778 --- /dev/null +++ b/packages/streamr-utils/StreamrModules.cmake @@ -0,0 +1,84 @@ +# CANONICAL COPY — the per-package copies in packages/*/StreamrModules.cmake +# are generated from this file by ./sync-cmake-files.sh. Edit THIS file and +# run the sync script; do not edit the package copies directly. +# (Each package carries its own copy so that it can be published as a +# standalone vcpkg package later.) +# +# C++ named-modules build support (MODERNIZATION.md Part 2). A package +# includes this file when it starts defining module targets. Non-migrated +# packages are unaffected: the root build keeps CMAKE_CXX_SCAN_FOR_MODULES +# OFF globally (clean compile commands for clangd), and the helpers below +# re-enable scanning per target. + +# CMake's C++ modules support requires the Ninja generator (Makefiles cannot +# express the dynamically discovered module dependency graph). +if(NOT CMAKE_GENERATOR MATCHES "Ninja") + message(FATAL_ERROR + "C++ modules require the Ninja generator; current generator is " + "'${CMAKE_GENERATOR}'. install-prerequisities.sh/setenvs.sh export " + "CMAKE_GENERATOR=Ninja — source one of them (and ./clean.sh once if " + "the build dir was configured with another generator).") +endif() + +# AppleClang has no CMake modules support; the build already uses Homebrew +# LLVM everywhere (homebrewClang.cmake), so this only guards misconfiguration. +if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + message(FATAL_ERROR + "CMake does not support C++ modules with AppleClang. The build is " + "expected to use Homebrew LLVM (see homebrewClang.cmake / " + "LLVM_PREFIX).") +endif() + +# CMP0155 NEW: scan C++20+ sources for module dependencies by default. +# Scanning stays globally disabled via CMAKE_CXX_SCAN_FOR_MODULES OFF until +# a target opts in through the helpers below. +cmake_policy(SET CMP0155 NEW) + +# Opt-in `import std;` (experimental in CMake, OFF by default — see the +# MODERNIZATION.md decision: no rollout now). CMake gates the feature behind +# a per-version experimental UUID, so turning this on requires passing the +# UUID for the CMake version in use: +# cmake -DSTREAMR_IMPORT_STD=ON \ +# -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= ... +option(STREAMR_IMPORT_STD "Build with experimental 'import std' support" OFF) +if(STREAMR_IMPORT_STD) + if(NOT DEFINED CMAKE_EXPERIMENTAL_CXX_IMPORT_STD) + message(FATAL_ERROR + "STREAMR_IMPORT_STD=ON needs " + "-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD= (the experimental " + "feature UUID documented for your CMake version in " + "Help/dev/experimental.rst of the CMake source).") + endif() + set(CMAKE_CXX_MODULE_STD ON) +endif() + +# streamr_add_module_library( FILES ...) +# +# Defines as a STATIC library whose C++ module interface units are +# the given files (FILE_SET CXX_MODULES, rooted at the package's modules/ +# directory). STATIC rather than INTERFACE: module interface units are +# compiled TUs, so even a previously header-only package gains a compiled +# archive when it grows a module. +function(streamr_add_module_library TARGET) + cmake_parse_arguments(ARG "" "" "FILES" ${ARGN}) + if(NOT ARG_FILES) + message(FATAL_ERROR "streamr_add_module_library(${TARGET}): FILES is required") + endif() + add_library(${TARGET} STATIC) + target_sources(${TARGET} + PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/modules + FILES ${ARG_FILES}) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() + +# streamr_enable_imports() +# +# Enables module scanning on an existing target whose ordinary .cpp sources +# use `import` (e.g. a test executable of a migrated package). Without this +# the global CMAKE_CXX_SCAN_FOR_MODULES OFF would leave the import edges +# undiscovered and the build would race the BMIs. +function(streamr_enable_imports TARGET) + set_target_properties(${TARGET} PROPERTIES CXX_SCAN_FOR_MODULES ON) +endfunction() diff --git a/sync-cmake-files.sh b/sync-cmake-files.sh index f722c538..80de798a 100755 --- a/sync-cmake-files.sh +++ b/sync-cmake-files.sh @@ -13,7 +13,7 @@ set -e cd "$(dirname "$0")" -SYNCED_FILES="homebrewClang.cmake monorepoPackage.cmake" +SYNCED_FILES="homebrewClang.cmake monorepoPackage.cmake StreamrModules.cmake" MODE_CHECK=false if [ "$1" = "--check" ]; then From 8c904dd11a9560691d2b9df071bc253ed072d0ac Mon Sep 17 00:00:00 2001 From: Petri Savolainen Date: Fri, 3 Jul 2026 12:14:21 +0300 Subject: [PATCH 2/2] gitignore the -.json time-trace artifact of CMake compiler detection Co-Authored-By: Claude Fable 5 --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b49f8de1..90e7cfa6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ packages/streamr-libstreamrproxyclient/dist/android/StreamrProxyClient/libs/arm6 packages/streamr-libstreamrproxyclient/dist/android-library-module/StreamrProxyClient/libs/arm64-v8a/libstreamrproxyclient.so /build-bench-trace/ bench-trace.bin +/-.json