Skip to content

Build/CMake: private static embedding and header-only reflection reuse require TARGET_OBJECTS and property hacks #141

Backlog

Description

@clockblocker

Part of #138
Popularity: 2/7 corpus consumers (cuda-quantum, holoscan-sdk)

Problem

Both NVIDIA consumers treat reflect-cpp as a strictly private implementation detail that must never leak into installed CMake export sets (INTERFACE_LINK_LIBRARIES) or public installed headers. However, reflect-cpp does not provide:

  1. A clean header-only interface target (e.g. reflectcpp::headers) for TUs that only use compile-time reflection (<rfl/to_view.hpp>, <rfl/enums.hpp>, etc.) or link a parent library that already absorbed reflectcpp's objects, without re-linking duplicate static objects.
  2. First-class support for private object absorption (OBJECT library / private embedding) without consumers reaching into $<TARGET_OBJECTS:reflectcpp> or manually compiling src/*.cpp.

Observed Downstream Workarounds

NVIDIA/cuda-quantum (90e4aa08)

  • cudaq/lib/Target/CMakeLists.txt#L101-L107: absorbs $<TARGET_OBJECTS:reflectcpp> directly into CUDAQTargetCatalog so reflectcpp is never exported in CUDAQTargetCatalogTargets.cmake:
    add_library(CUDAQTargetCatalog
      TargetCatalog.cpp
      TargetRuntimeArgs.cpp
      TargetPluginLibrary.cpp
      $<TARGET_OBJECTS:CUDAQTargetYamlObjects>
      $<TARGET_OBJECTS:reflectcpp>
      $<TARGET_OBJECTS:yaml-cpp>)
  • cudaq/lib/Target/test/CMakeLists.txt#L45-L48 and cudaq/lib/Target/python/CMakeLists.txt#L49-L50: downstream targets that link CUDAQTargetCatalog and only need reflect-cpp headers cannot target_link_libraries(... reflectcpp) without duplicating objects, so both hack around it with:
    # The catalog already contains reflect-cpp's objects, so take only its headers,
    # as system headers like linking it would.
    target_include_directories(TargetCatalogTestDriver SYSTEM PRIVATE
      $<TARGET_PROPERTY:reflectcpp,INTERFACE_INCLUDE_DIRECTORIES>)

nvidia-holoscan/holoscan-sdk (358c772f)

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