Sorry for an open-ended question, but I’m interested in tips on how to organize a medium sized cmake project in a structed way (or tips of good cmake projects to be inspired by).
More concretely it seems a lot of projects are doing very much in one big CMakeLists.txt and I’d prefer to work towards dividing a large file up into eg functions and macros or modules even, just like in a normal HLL.
Here though I find cmake working a bit against this by - afaik - not providing much help in terms of interfaces to modules, functions etc.
Ideally I’d like a very small main file, maybe:
defs = store_compile_defs(opts)
build_lib(opts, defs)
if tests; build_tests
if docs_requested; create_docs
etc...
Eg sometimes I see people putting options handling in a separate module, but then this is “just” a block of code that is moved someplace else. There is no interface where one would do my_options = get_options()
or such; still something working with public data and no encapsulation.
Another example I have is a very long macro storing compiler defines in a list (as I need them to 1) build my project 2) as input to doxygen and 3) to unifdef public headers). Is putting this in a macro in a helper module of sorts the best I can do, or is there something better?