Repository navigation
Description
Part of #138
Popularity: 1/7 corpus consumers (fanuc-libs)
Related issues
- complements Build/CMake: reflectcpp target lacks SYSTEM headers, warning/visibility/PIC/linter isolation, and collides on bundled yyjson #140 (CMake target hygiene) and Map (Lane 1): Core Hygiene & Perf #85 (Lane 1: Core Hygiene & Perf), which do not cover C++ standard usage-requirement propagation.
Problem
When a parent project configures CMAKE_CXX_STANDARD 17 (either in CMakeLists.txt or via -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON, common across ROS 2 and robotics/embedded codebases), embedding reflect-cpp via FetchContent or add_subdirectory leaves reflectcpp compiling as C++17 and fails to propagate C++20 to linking targets. Consumers must manually force CXX_STANDARD 20 on reflectcpp itself and on every target that links it.
Observed Downstream Workaround (FANUC-CORPORATION/fanuc_driver @ da5db3f6)
fanuc_libs/CMakeLists.txt#L9and.github/workflows/ci.yaml#L59-L64: the parent workspace builds with C++17:set(CMAKE_CXX_STANDARD 17)
CMAKE_ARGS: >- -DBUILD_TESTING=1 -DBUILD_EXAMPLES=1 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_STANDARD=17 -DCMAKE_CXX_STANDARD_REQUIRED=ON
fanuc_libs/CMakeLists.txt#L56-L58: manually overridesCXX_STANDARDon thereflectcpptarget afterFetchContent_MakeAvailable:FetchContent_MakeAvailable(reflect-cpp) set_target_properties(reflectcpp PROPERTIES CXX_STANDARD 20) set_target_properties(reflectcpp PROPERTIES POSITION_INDEPENDENT_CODE ON)
- Every target linking
reflectcppmust also manually repeatCXX_STANDARD 20:fanuc_libs/gpio_config/CMakeLists.txt#L9-L15:target_link_libraries(gpio_config PRIVATE reflectcpp) ... set_target_properties(gpio_config PROPERTIES CXX_STANDARD 20)
fanuc_libs/rmi/CMakeLists.txt#L9-L15:target_link_libraries(rmi PRIVATE reflectcpp Sockpp::sockpp) ... set_target_properties(rmi PROPERTIES CXX_STANDARD 20)
fanuc_libs/rmi/test/CMakeLists.txt#L6-L8:set_target_properties(rmi_test PROPERTIES CXX_STANDARD 20) target_link_libraries(rmi_test PRIVATE rmi reflectcpp GTest::gtest_main)
Root Cause in reflect-cpp
CMakeLists.txt#L36-L50 (both at pinned 2a0fdeab and on current main) only sets the directory variable CMAKE_CXX_STANDARD inside if(NOT DEFINED CMAKE_CXX_STANDARD) and never calls target_compile_features(reflectcpp PUBLIC ...). When a parent project already defines CMAKE_CXX_STANDARD to 17, the if(NOT DEFINED CMAKE_CXX_STANDARD) branch is skipped completely, so reflectcpp compiles with -std=c++17 (failing to compile) and exports no INTERFACE_COMPILE_FEATURES requirement to consumers.
Suggested Direction / Fix
- Declare target-scoped C++ standard usage requirements on
reflectcppviatarget_compile_features:cxx_std_20by defaultcxx_std_23whenREFLECTCPP_USE_STD_EXPECTEDisONcxx_std_26whenREFLECTCPP_USE_CPP26_REFLECTIONisON
- Keep
target_compile_features(reflectcpp PUBLIC ...)authoritative so C++17 parent projects can linkreflectcppPRIVATEinto C++20 implementation libraries without post-FetchContentproperty hacks, while still allowing parent projects on newer standards (e.g. C++23) to compilereflectcppat their higher standard.
Upstream Overlap
- CMake complaining that cxx_std_20 is not supported by Clang 19.1.3 munich-data-engineering/reflect-cpp#253 / [#253] Comment out redundant cxx_std_20 check munich-data-engineering/reflect-cpp#254 (closed/merged regression, exact root cause) — PR
#254commented outtarget_compile_features(reflectcpp PUBLIC cxx_std_20)inCMakeLists.txtto work around a Clang 19.1.3 macOS Sequoia beta CMake complaint reported in#253, directly causing this C++17 parent-build breakage (despite a review note on#253advocating target-scoped features over globalCMAKE_CXX_STANDARD). No open upstream issue tracks restoring it.
Activity
build(cmake): declare target_compile_features for C++20/23/26 on refl…
build(cmake): declare target_compile_features for C++20/23/26 on refl…
build(cmake): declare target_compile_features for C++20/23/26 on refl…