Provide CMake components for different serialization formats #576
Copy link
Copy link
Open
Description
CMake supports finding specific package components, this is most prominently known with Qt, where you can call find_package(Qt6 REQUIRED COMPONENTS Widgets) to use widgets, but not the networking code for example.
The wish comes from the fact that I've recently evaluated to use this library and in the process came across the Debian package, which is compiled against all serialization formats. However, even if you just want to use json and toml, find_package will fail to find a good bson version. This is definitely a Debian packaging problem, however the library should provide a way to be packaged with all formats and only compile against the required parts when a user will only use a subset.
Copy-Paste Reproducer
Here a quick copy paste guide to reproduce:
podman run --rm -it --pull always debian:unstable
apt update && apt upgrade -y && apt install -y --no-install-recommends build-essential cmake ninja-build && apt install -y libreflectcpp-dev libtomlplusplus-dev libbson-dev# CMakeLists.txt
cmake_minimu_required(VERSION 3.30)
project(foo CXX)
find_package(reflectcpp REQUIRED)
add_executable(foo foo.cc)// foo.cc
auto main() -> int { return 0; }cmake -B build -G NinjaReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
liuzicheng1987 commentedon Jan 18, 2026
@deckstose, I have to admit, I am not entirely sure what you want is to do here.
The library itself absolutely provides that. If you only compile the JSON and TOML features than only those dependencies are installed and required.
I wasn't involved in making the Debian package, and frankly, didn't even know that one existed, so I can't really say much about that.
deckstose commentedon Jan 18, 2026
I suggest to make consuming the library more modular.
You're right, but this is only applicable if you control the build process.
What solves this problem is if we could provide
libreflectcpp.so+libreflectcpp-toml.soetc + CMakeConfig modules for each optional component. This way we could use an optional component, even if the library was build with all features enabled.liuzicheng1987 commentedon Jan 19, 2026
@deckstose, OK, I think that could be done.
deckstose commentedon Jan 22, 2026
@GregTheMadMonk
This might be better discussed here. I was just throwing it in the module mix but I have no idea if modules are even designed for that.
I have a branch here with exactly the ideas you have mentioned in #578 (comment). I not done with the design of the config.cmake file and installing headers in not ready either.
deckstose commentedon Jan 22, 2026
For me this seems to require listing all headers explicitly in target_sources ...