Skip to content

build(cmake): isolate bundled yyjson visibility, support external yyjson, and add reflectcpp::headers target - #258

Open
clockblocker wants to merge 1 commit into
queue/build-cmake-subproject-ergonomicsfrom
queue/build-cmake-yyjson-visibility
Open

clockblocker wants to merge 1 commit into
queue/build-cmake-subproject-ergonomicsfrom
queue/build-cmake-yyjson-visibility

Conversation

@clockblocker

@clockblocker clockblocker commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

AI-authored below this line.

Stacked on: #256 (queue/build-cmake-subproject-ergonomics)

Problem

Linking static reflect-cpp into a shared library or plugin re-exports bundled yyjson_* C symbols and causes duplicate-symbol errors when consumers bring their own yyjson.

Header-only and OBJECT-library targets also have no way to pull reflect-cpp headers without linking its compiled objects.

# 1. Reuse an existing external yyjson target without disabling bundled ctre/enchantum
set(REFLECTCPP_USE_BUNDLED_YYJSON OFF)
set(REFLECTCPP_YYJSON_TARGET my::yyjson)
set(REFLECTCPP_HIDDEN_VISIBILITY ON) # optional: also hide static rfl:: symbols
add_subdirectory(reflect-cpp)

# 2. Header-only / OBJECT libraries consume headers without linking compiled objects
target_link_libraries(my_obj_lib PUBLIC reflectcpp::headers)
target_link_libraries(my_plugin  PRIVATE my_obj_lib reflectcpp::reflectcpp) # 0 leaked yyjson_* in nm -D

Summary

  • Hides bundled yyjson symbols by default on static non-Windows builds (verified 0 leaked yyjson_* symbols in consumer DSOs via nm -D), defaults static subproject PIC, and adds opt-in REFLECTCPP_HIDDEN_VISIBILITY.
  • Adds REFLECTCPP_USE_BUNDLED_YYJSON and REFLECTCPP_YYJSON_TARGET with fail-fast validation (preserving parent normal variables under CMake 3.20) and omits include/rfl/thirdparty when JSON is disabled.
  • Exports header-only reflectcpp::headers (INTERFACE target mirroring compile features, definitions, and headers without compiled objects).

OSS consumers

Consumer Location Pain point solved
NVIDIA/cuda-quantum NVIDIA/cuda-quantum Links static reflect-cpp into plugin shared libraries that must export zero yyjson_* symbols.
hudson-trading/slang-server hudson-trading/slang-server Separates thin header-only reflection targets (reflectcpp::headers) from compiled JSON linking.
For Agents

…son, and add reflectcpp::headers target

Improve library packaging and embedding hygiene for static/shared consumers
and header-only / OBJECT-library builds:

- **Bundled yyjson hidden visibility & external yyjson target (#140 Part 2):**
  Default-hide bundled `yyjson` symbols on static non-Windows builds
  (`yyjson_api=__attribute__((visibility("hidden")))` + `-fvisibility=hidden`
  on `src/yyjson.c`) so consumer DSOs never export `yyjson_*` symbols even
  with `REFLECTCPP_HIDDEN_VISIBILITY=OFF`, while keeping shared and Windows
  static builds untouched. Add `REFLECTCPP_USE_BUNDLED_YYJSON` and
  `REFLECTCPP_YYJSON_TARGET` (preserving parent normal variables under
  CMP0126 OLD and failing fast on misconfiguration or missing targets,
  including alias targets), gate `include/rfl/thirdparty` on both
  `REFLECTCPP_USE_BUNDLED_YYJSON` and `_REFLECTCPP_NEEDS_JSON_IMPL` so
  JSON-disabled builds never receive thirdparty includes, enable
  `POSITION_INDEPENDENT_CODE ON` by default for static subprojects when
  unset, and add opt-in `REFLECTCPP_HIDDEN_VISIBILITY`.
- **Header-only `reflectcpp::headers` interface target (#141):** Add and
  export `INTERFACE` target `reflectcpp_headers` (`reflectcpp::headers`)
  mirroring `reflectcpp`'s C++ standard compile features, public compile
  definitions, SYSTEM/non-SYSTEM include directories, and conditional
  bundled/external dependency headers (without CMake 3.20-3.25
  directory-scope `TARGET_PROPERTY` failures) without linking compiled
  objects, and document usage in `docs/content/install.md`.

Depends on CMake PR 1 (subproject ergonomics & CMake 3.20 support).
Addresses #140 and #141.
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