ecmwf / ecbuild

A CMake-based build system, consisting of a collection of CMake macros and functions that ease the managing of software build systems
https://ecbuild.readthedocs.io
Apache License 2.0
26 stars 25 forks source link

Exported targets and namespace? #24

Closed mathomp4 closed 2 years ago

mathomp4 commented 4 years ago

A query from someone who doesn't know a lot of deep internal CMake as well as he should. Namely, we currently use ecbuild in a local project and we make a project, libraries, etc. with it. However, I was wondering if there was a way with ecbuild to get the snazzy namespace-like access? A la MPI::MPI_Fortran or NetCDF::NetCDF_C? So I could have MyLib::profiler say.

Maybe this is automatic, but I didn't see a NAMESPACE option to ecbuild_add_library or any of the other ecbuild_ commands we use.

I see ecbuild_add_persistent has a NAMESPACE option, but my brief run through the things that use it don't quite match up to examples like this one. And, well, I'm not to sure what that ecbuild_add_persistent does, so I'm hesitant to try it out. 😄

oiffrig commented 4 years ago

There is no option to use namespaces. We have considered the idea of adding namespaced names automatically, but having something working while preserving backwards compatibility (having both MyProject::mylib and mylib defined) proved to be tricky, and impossible with older versions of CMake (<3.12 at the time the tests were done).

Adding it as an option to ecbuild_install_project should be easy enough, if you want to give it a try ;)

ecbuild_add_persistent, is completely unrelated, it is a tool to generate serialisation code for C++ classes automatically.

mathomp4 commented 4 years ago

There is no option to use namespaces. We have considered the idea of adding namespaced names automatically, but having something working while preserving backwards compatibility (having both MyProject::mylib and mylib defined) proved to be tricky, and impossible with older versions of CMake (<3.12 at the time the tests were done).

We are getting close to making CMake 3.17 almost a necessity, so might work for us 😄

Adding it as an option to ecbuild_install_project should be easy enough, if you want to give it a try ;)

Well, I might give it a try. See what happens and what I break... I think I can see where to add it.