marzer / tomlplusplus

Header-only TOML config file parser and serializer for C++17.
https://marzer.github.io/tomlplusplus/
MIT License
1.53k stars 146 forks source link

Generate CMake configuration file #20

Closed traversaro closed 4 years ago

traversaro commented 4 years ago

Is your feature request related to a problem? Please describe. It would be great if tomlplusplus could install a CMake config file to permit downstream users to use it in CMake by simply:

find_package(tomlplusplus REQUIRED)

// ...

target_link_libraries(<downstream_target> PRIVATE tomlplusplus::tomlplusplus)

Describe the solution you'd like I think this is possible by using meson support for writing CMake configuration files, see https://mesonbuild.com/CMake-module.html#cmake-configuration-files .

Describe alternatives you've considered The alternative is to leave to downstream users to write and install a Findtomlplusplus.cmake file, see https://github.com/dic-iit/bipedal-locomotion-controllers/issues/26#issuecomment-607929202

Additional context Depending on wheter we end up using toml++ in our projects, I may be happy to work on it myself. This should also simplify the integration of toml++ in vcpkg (see https://github.com/microsoft/vcpkg/issues/10667).

cc @GiulioRomualdi @S-Dafarra

marzer commented 4 years ago

Ah, thanks @traversaro. Since I'm largely a cmake novice this may take me a while to dig into, so if you do decide to work on this yourself I'd be very grateful!

An alternative short-term workaround is to eliminate the need for build systems and subprojects completely by dropping the single-file version of the library toml.hpp in your source tree.

marzer commented 4 years ago

On an unrelated note, I just had a look at the linked issue and noticed that my use of <charconv> is problematic for you guys. Since I'm already forced to use stringstreams on some platforms, there's no significant reason why I can't add support for an entirely stringstream-based mode, if that's helpful.

GiulioRomualdi commented 4 years ago

Hi @marzer, If it's ok for you I can propose a PR with the solution described by @traversaro in https://github.com/marzer/tomlplusplus/issues/20#issue-594852506

marzer commented 4 years ago

Yup, go for it! I'm going to push a fix for the <charconv> issue and the locale issue later today, so I won't merge anything in until after that, but if it's just build configuration stuff I'm sure it'll be fairly simple to merge.

marzer commented 4 years ago

@traversaro @GiulioRomualdi I've just done some minor cleanup to move the cmake stuff behind a configuration option GENERATE_CMAKE_CONFIG that defaults to auto (disabled when invoked as a submodule, enabled otherwise). It should still 'just work', but if you want to be explicit about it you can when you invoke meson, e.g.:

CXX=clang++ meson build-clang -DGENERATE_CMAKE_CONFIG=enabled