Skip to content

build(cmake): subproject ergonomics, CMake 3.20 support, warning/linter isolation, and FetchContent docs - #256

Open
clockblocker wants to merge 1 commit into
mainfrom
queue/build-cmake-subproject-ergonomics
Open

clockblocker wants to merge 1 commit into
mainfrom
queue/build-cmake-subproject-ergonomics

Conversation

@clockblocker

@clockblocker clockblocker commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

AI-authored below this line.

Problem

Embedding reflect-cpp via FetchContent or add_subdirectory mutates parent CMake globals and unconditionally enables install and vcpkg integration.

It also requires CMake 3.23+ (breaking RHEL 8, Ubuntu 22.04, and ROS 2 Humble) and trips strict parent -Werror, clang-tidy, and MSVC /WX policies.

# Works out of the box on CMake >= 3.20 (Linux, macOS, Windows MSVC / clang-cl)
# without setting REFLECTCPP_USE_VCPKG=OFF, REFLECTCPP_INSTALL=OFF, or global -w:
FetchContent_Declare(reflectcpp
  GIT_REPOSITORY https://github.com/munich-data-engineering/reflect-cpp.git
  GIT_TAG        v0.26.1
  GIT_SUBMODULES "")
FetchContent_MakeAvailable(reflectcpp)

target_link_libraries(my_app PRIVATE reflectcpp::reflectcpp)

Summary

  • Lowers the minimum CMake version to 3.20 (with 3.23 FILE_SET and 3.24 WHOLE_ARCHIVE fallbacks), uses target-scoped C++20/23/26 features, and scopes CPack, ament_cmake, install, and vcpkg defaults to top-level builds.
  • Isolates subproject consumers with SYSTEM includes, strips inherited linter and warning-as-error flags across GCC, Clang, MSVC, and clang-cl, and fixes compiled-source MSVC warnings (C4459/C4702/C5267).
  • Marks test and benchmark subprojects CXX-only, preserves default Windows library naming for Conan, and adds FetchContent quickstart docs.

OSS consumers

Consumer Location Pain point solved
NVIDIA/cuda-quantum NVIDIA/cuda-quantum Embeds reflect-cpp inside a multi-compiler CMake build with strict warning/linter policies.
nvidia-holoscan/holoscan-sdk nvidia-holoscan/holoscan-sdk Builds on Ubuntu 22.04 / RHEL-class toolchains without parent global mutations or vcpkg overrides.
FANUC-CORPORATION/fanuc_driver FANUC-CORPORATION/fanuc_driver ROS 2 Humble (ament_cmake) consumer on CMake 3.22 needing subproject-safe ament_package() scoping.
For Agents

…er isolation, and FetchContent docs

Make reflect-cpp work out of the box as a CMake subproject (FetchContent /
add_subdirectory) across Linux, macOS, and Windows (VS 2022 MSBuild, Ninja
MSVC, Ninja clang-cl) without mutating parent project state or tripping
consumer warning/linter policies:

- **Target-scoped C++ standard & top-level scoping (#157):** Compute
  `_REFLECTCPP_IS_TOP_LEVEL` (`CMAKE_CURRENT_SOURCE_DIR STREQUAL
  CMAKE_SOURCE_DIR`), scope global `CMAKE_CXX_STANDARD` /
  `CMAKE_CXX_STANDARD_REQUIRED` / `CMAKE_EXPORT_COMPILE_COMMANDS` defaults,
  `ament_cmake` / `ament_package()`, and `CPack` to top-level builds, and
  declare target-scoped `target_compile_features` (`cxx_std_20` /
  `cxx_std_23` / `cxx_std_26` guarded on CMake >= 3.30 with `CXX_STANDARD 26`
  fallback on 3.25-3.29) + `CXX_STANDARD_REQUIRED ON`.
- **CMake 3.20 minimum with 3.23 FILE_SET fallback (#156):** Lower
  `cmake_minimum_required` from 3.23 to 3.20 (supporting RHEL 8 / Ubuntu
  22.04 / ROS 2 Humble), replace `PROJECT_IS_TOP_LEVEL` with
  `_REFLECTCPP_IS_TOP_LEVEL`, gate `FILE_SET reflectcpp_headers` on CMake >=
  3.23 with an `install(DIRECTORY ...)` fallback, fix `${INCLUDE_INSTALL_DIR}`
  to `${CMAKE_INSTALL_INCLUDEDIR}`, and guard `$<LINK_LIBRARY:WHOLE_ARCHIVE,...>`
  on CMake >= 3.24 with `/WHOLEARCHIVE:` fallback.
- **Subproject vcpkg/install defaults & config ordering (#142):** Default
  `REFLECTCPP_INSTALL` and `REFLECTCPP_USE_VCPKG` to
  `${_REFLECTCPP_IS_TOP_LEVEL}` (removing the unconditional top-level
  `REFLECTCPP_INSTALL=ON` override), preserve pre-set `CMAKE_TOOLCHAIN_FILE`
  (preferring explicit `-DVCPKG_ROOT`, then local `./vcpkg` submodule, then
  `$ENV{VCPKG_ROOT}`), replace directory-level
  `include_directories(PUBLIC ${jsoncons_INCLUDE_DIRS})` with target-scoped
  `SYSTEM PUBLIC $<BUILD_INTERFACE:...>`, and order `reflectcpp-exports.cmake`
  after all `find_dependency()` calls in `reflectcpp-config.cmake.in`. Keep
  default library naming untouched for Conan (`conanfile.py`) and existing
  Windows Debug consumers, documenting `-DCMAKE_DEBUG_POSTFIX=d` for
  multi-config single-prefix Windows installs.
- **SYSTEM interface includes & warning/linter isolation (#140 Part 1):**
  Mark subproject consumer interface includes `SYSTEM` (unless top-level or
  `REFLECTCPP_STRICT_WARNINGS=ON`), propagate subproject `pugixml` includes
  onto `reflectcpp`'s own `SYSTEM PUBLIC $<BUILD_INTERFACE:...>` without
  mutating parent targets, mark bundled thirdparty & YAS includes `SYSTEM`,
  silence vendored `src/yyjson.c` warnings cleanly (`-w` on GNU/Clang, `/W0`
  under MSVC `REFLECTCPP_STRICT_WARNINGS`), clear inherited
  `CLANG_TIDY`/`CPPCHECK`/`IWYU` and `COMPILE_WARNING_AS_ERROR` on subproject
  `reflectcpp`, strip inherited MSVC `/W*`/`-W*`/`/WX*`/`-WX*` flags cleanly
  in local scope to eliminate D9025 spam (restoring `/W3` for `tests/` and
  `benchmarks/` under top-level `REFLECTCPP_STRICT_WARNINGS=ON`), use `/W4`
  instead of `-Wall` under `REFLECTCPP_STRICT_WARNINGS` on MSVC/clang-cl,
  remove redundant Release `-DNDEBUG` injection, and fix compiled-source
  warnings in `src/rfl/env/Writer.cpp`, `include/rfl/parsing/schema/Type.hpp`/`.cpp`
  (explicit out-of-line copy/move special members for C5267), and
  `src/rfl/json/to_schema.cpp` (C4459/C4702).
- **CXX-only & MSVC-safe test/benchmark subprojects:** Add `LANGUAGES CXX`
  to all `tests/*/CMakeLists.txt` and `benchmarks/*/CMakeLists.txt` so
  `-DCMAKE_CXX_COMPILER=clang-cl` does not probe a C compiler, and guard
  GCC-only `-Wall -O2` `CMAKE_C_FLAGS` with `if (NOT MSVC)`.
- **FetchContent quickstart & install docs:** Fix broken links and Option 5
  option ordering in `README.md` and `docs/content/install.md`, and add
  JSON-only (`GIT_SUBMODULES ""`) and YAML FetchContent quickstart snippets.

Addresses #140, #142, #156, #157 and
clockblocker/refl-cpp-workbench#23.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant