veselink1 / refl-cpp

Static reflection for C++17 (compile-time enumeration, attributes, proxies, overloads, template functions, metaprogramming).
https://veselink1.github.io/refl-cpp/md__introduction.html
MIT License
1.05k stars 76 forks source link

CMake support #44

Closed friendlyanon closed 3 years ago

friendlyanon commented 3 years ago

This PR enables clients using CMake to consume this library in a trivial manner.

For rationale behind the changes, please look at my recent PRs and discussions in FunctionalPlus, where I added similar support.

rileylev commented 3 years ago

Any updates?

friendlyanon commented 3 years ago

I cleaned up things further.

Regarding the developer mode, you can just add a CMakeUserPresets.json file to the repo (but not checked in, so add it to gitignore) to have a convenient developer experience. Such a preset would allow you to trivially configure cmake:

```json { "version": 1, "cmakeMinimumRequired": { "major": 3, "minor": 14, "patch": 0 }, "configurePresets": [ { "name": "dev", "displayName": "Developer mode", "description": "Developer mode", "generator": "Ninja", "binaryDir": "${sourceDir}/build", "cacheVariables": { "refl-cpp_DEVELOPER_MODE": "ON" } } ] } ```

With that presets file in place, configuring is simply done with running cmake --preset=dev in the source dir.
Version 3 will make the generator field optional in 3.21, so it'll be much easier to reuse presets. Could check a CMakePresets.json in after that.

veselink1 commented 3 years ago

Thank you for your work on this!

I am not very familiar with CMake, and I was hoping to have the time to become familiar enough to evaluate any tradeoffs. Months later, I still haven't done that.

Everything up to your latest changes is in the cmake-support branch (which is now several commits behind). I just forgot to follow up on that here. My intention was to bring that branch up to date and finally close this PR.

I'm not able to test the presets option, as my system (Ubuntu 20.04) only comes with CMake 3.16 and --preset was added in CMake 3.20, if not mistaken. Building with -Drefl-cpp_DEVELOPER_MODE=ON instead works fine, so I trust nothing has been broken.

I will now proceed to set up the CI to build with CMake and finally merge this PR sometime in the next day.

veselink1 commented 3 years ago

Merged into master, everything looks good. Thanks, @friendlyanon!

friendlyanon commented 3 years ago

Presets were added in 3.19 and Kitware provides an APT repository for Debian based distros to always get the latest and greatest, so it's trivial to install new versions. I highly recommend always using the latest version, even if your CMLs don't require such high versions, purely because of all the QoL changes, like presets.