Skip to content

Build/CMake: format opt-in boilerplate, implicit yaml-cpp/tomlplusplus FetchContent ordering, and silent REFLECTCPP_USE_VCPKG=ON #142

Backlog

Description

@clockblocker

Part of #138
Popularity: 4/7 corpus consumers (cuda-quantum, fanuc-libs, moqx, wolf)

Problem

  1. Consumers that want a minimal, deterministic single-format configuration (e.g. YAML-only or TOML-only, no vcpkg, no install rules) must spell out many REFLECTCPP_* cache flags (23 set(...) statements in cuda-quantum, 8 in wolf) to guard against default-on options (REFLECTCPP_JSON, REFLECTCPP_INSTALL, REFLECTCPP_USE_VCPKG, etc.).
  2. Enabling any non-JSON format (REFLECTCPP_YAML=ON, REFLECTCPP_TOML=ON, REFLECTCPP_MSGPACK=ON, etc.) silently flips REFLECTCPP_USE_VCPKG_DEFAULT to ON inside reflect-cpp/CMakeLists.txt (#L71-L94, #L185) — even when embedded as a subproject (NOT PROJECT_IS_TOP_LEVEL) where vcpkg is never configured — mutating CMAKE_TOOLCHAIN_FILE in the parent project's CMakeCache.txt unless consumers explicitly override REFLECTCPP_USE_VCPKG=OFF.
  3. Under FetchContent / CPM without vcpkg, reflect-cpp relies on undocumented ordering tricks (if (NOT TARGET yaml-cpp::yaml-cpp) find_package(yaml-cpp CONFIG REQUIRED) / if (NOT TARGET tomlplusplus::tomlplusplus) find_package(tomlplusplus)), forcing every consumer to manually pre-fetch yaml-cpp or tomlplusplus (with OVERRIDE_FIND_PACKAGE) strictly before reflect-cpp, with no explicit CMake target-injection API.

Observed Downstream Workarounds

NVIDIA/cuda-quantum (90e4aa08)

  • cudaq/lib/Target/cmake/FetchDependencies.cmake#L42-L69: sets 23 REFLECTCPP_* variables to select YAML-only with bundled header dependencies, then enforces FetchContent_MakeAvailable ordering:
    # reflect-cpp: YAML support only, on top of the bundled header dependencies
    # (ctre, enchantum); never resolve dependencies through vcpkg.
    set(REFLECTCPP_BUILD_SHARED OFF)
    set(REFLECTCPP_INSTALL OFF)
    set(REFLECTCPP_YAML ON)
    set(REFLECTCPP_JSON OFF)
    ... # 14 more format OFF flags + VCPKG/BUNDLED/TESTS/BENCHMARKS/CHECK_HEADERS
    set(REFLECTCPP_CHECK_HEADERS OFF)
    
    # Ordering matters: yaml-cpp is a dependency of reflect-cpp.
    FetchContent_MakeAvailable(yaml_cpp reflectcpp)

FANUC-CORPORATION/fanuc_driver (da5db3f6)

  • fanuc_libs/CMakeLists.txt#L38-L56: must declare and make yaml-cpp available before reflect-cpp so TARGET yaml-cpp::yaml-cpp is already defined, and sets REFLECTCPP_YAML ON without REFLECTCPP_USE_VCPKG OFF (which silently flips REFLECTCPP_USE_VCPKG_DEFAULT=ON and writes CMAKE_TOOLCHAIN_FILE into the parent cache):
    FetchContent_Declare(
      yaml-cpp
      GIT_REPOSITORY ${CMAKE_SOURCE_DIR}/dependencies/yaml-cpp
      GIT_TAG 2f86d13775d119edbb69af52e5f566fd65c6953b
    )
    FetchContent_MakeAvailable(yaml-cpp)
    set(YAML_BUILD_SHARED_LIBS OFF CACHE BOOL "Build yaml-cpp shared library")
    set(YAML_CPP_INSTALL OFF CACHE BOOL "Enable generation of yaml-cpp install targets")
    
    # Build the reflectcpp library
    FetchContent_Declare(
        reflect-cpp
        GIT_REPOSITORY ${CMAKE_SOURCE_DIR}/dependencies/reflect-cpp
        GIT_TAG 2a0fdeabe35bdab0e07e05d4f869ca88bd6d2b8c
        PATCH_COMMAND bash ${CMAKE_SOURCE_DIR}/dependencies/apply_patch.bash ${CMAKE_SOURCE_DIR}/dependencies/reflectcpp.patch
    )
    set(REFLECTCPP_BUILD_SHARED OFF CACHE BOOL "Build reflectcpp as a shared library")
    set(REFLECTCPP_YAML ON CACHE BOOL "Enable YAML support")
    FetchContent_MakeAvailable(reflect-cpp)
  • .gitmodules#L4-L6 and .github/workflows/ci.yaml#L37-L39: CI also checks out submodules: recursive (and FetchContent_Declare omits GIT_SUBMODULES ""), pulling getml/reflect-cpp's dev-only vcpkg submodule unnecessarily (related to Build/CMake: dev-only vcpkg git submodule fetched by default under FetchContent, CPM, and recursive git submodules #139).

openmoq/moqx (60bab7f13925acbaf578670223e660d71e891547)

  • CMakeLists.txt#L286-L305: must manually declare and configure yaml-cpp before reflect-cpp via CPM with an explicit ordering comment:
    # --- yaml-cpp (CPM) ---
    CPMAddPackage(
            NAME yaml-cpp
            GITHUB_REPOSITORY jbeder/yaml-cpp
            GIT_TAG ${YAMLCPP_VERSION}
            OPTIONS
            "YAML_CPP_BUILD_TESTS OFF"
            "YAML_CPP_BUILD_TOOLS OFF"
            "YAML_CPP_FORMAT_SOURCE OFF"
            "CMAKE_WARN_DEPRECATED OFF"
    )
    
    # --- reflect-cpp (CPM, needs yaml-cpp available) ---
    
    CPMAddPackage(
            NAME reflectcpp
            GITHUB_REPOSITORY getml/reflect-cpp
            GIT_TAG ${REFLECTCPP_VERSION}
            OPTIONS "REFLECTCPP_YAML ON" "REFLECTCPP_BUILD_TESTS OFF"
    )
  • CMakeLists.txt#L93-L95: must also carry a CMake 4+ policy workaround (set(CMAKE_POLICY_VERSION_MINIMUM 3.5)) for yaml-cpp 0.8.0.
  • cmake/dependencies.cmake#L23-L25: must maintain and bump a separate YAMLCPP_VERSION pin alongside REFLECTCPP_VERSION solely to satisfy reflect-cpp's YAML backend.

games-on-whales/wolf (ac2461f6)

  • src/moonlight-server/CMakeLists.txt#L28-L59: must pre-fetch tomlplusplus with OVERRIDE_FIND_PACKAGE strictly before reflect-cpp, explicitly turn REFLECTCPP_USE_VCPKG OFF, and enumerate 7 format flags:
    # TOML
    FetchContent_Declare(
            tomlplusplus
            GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git
            GIT_TAG v3.4.0
            OVERRIDE_FIND_PACKAGE
    )
    FetchContent_MakeAvailable(tomlplusplus)
    ...
    # Serialization
    FetchContent_Declare(
            reflect-cpp
            GIT_REPOSITORY https://github.com/getml/reflect-cpp
            GIT_TAG v0.21.0
    )
    set(REFLECTCPP_USE_VCPKG OFF)
    
    set(REFLECTCPP_BSON OFF)
    set(REFLECTCPP_CBOR OFF)
    set(REFLECTCPP_FLEXBUFFERS OFF)
    set(REFLECTCPP_MSGPACK OFF)
    set(REFLECTCPP_TOML ON)
    set(REFLECTCPP_XML OFF)
    set(REFLECTCPP_YAML OFF)
    
    FetchContent_MakeAvailable(reflect-cpp)
    target_link_libraries(wolf_runner PUBLIC reflectcpp)
  • Historical context in wolf's git log confirms the same vcpkg friction previously blocked enabling REFLECTCPP_MSGPACK: commit 62936637 initially carried set(REFLECTCPP_MSGPACK OFF) # Only works with vcpkg, doing it manually and wired pkg_check_modules(MSGPACK ...) manually before commit e0ba6e60 switched to REFLECTCPP_USE_VCPKG OFF + tomlplusplus with OVERRIDE_FIND_PACKAGE.

Potential Improvements

  • Never default REFLECTCPP_USE_VCPKG to ON (and never overwrite CMAKE_TOOLCHAIN_FILE) when NOT PROJECT_IS_TOP_LEVEL.
  • Default REFLECTCPP_INSTALL to PROJECT_IS_TOP_LEVEL (standard CMake practice when embedded via FetchContent/add_subdirectory) and consider a minimal/explicit format preset.
  • Document and standardize explicit target injection for external format backends (yaml-cpp, tomlplusplus, yyjson, pugixml, etc.).

Upstream Overlap

Activity

  1. added
    enhancement
    needs-triage
    known-downstream-workarounds
    on Nov 29, 2026
  2. changed the title [-]Build/CMake: verbose format opt-in boilerplate (23 REFLECTCPP_* flags) and implicit yaml-cpp FetchContent ordering[/-] [+]Build/CMake: format opt-in boilerplate, implicit yaml-cpp/tomlplusplus FetchContent ordering, and silent REFLECTCPP_USE_VCPKG=ON[/+] on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementknown-downstream-workaroundsneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions