I am very new to cmake.
I am not new to build systems.
I have maintained signficant ones.
I have a very custom build system.
Very declarative, and embeds a little custom scripting language as an escape hatch.
Nice but design, but that I would rather stop maintaining. At least the underlying
platform support. I envision keeping the declarative stuff
and generating cmake files from it. Or maybe translating
once to idiomatic maintainable cmake.
However it has at least one very nice simple useful
feature that I have seen rarely or never elsewhere,
and I would like to know how to achieve it in cmake (or automake/libtool,
for better or worse, I want to delegate the work to others).
We compile everything just once, with -fPIC.
I find the approach of compiling things twice quite absurd, really.
For any “library” by default we make a static library and
link a shared library. We name the static libraries like foo.a.sa
or foo.lib.sa. (I forget what we do on HP-UX, where .sa means shared archive;
we have very broad platform support also).
If a library however is marked as “build_standalone”, we only build
the .sa form.
When we link an executable, by default, we probe around for the libraries
it requests. If there is dynamic we use that, else if there is static we use that.
If an executable is marked “standalone”, we look only for static,
which always succeeds.
The standalone libraries have another use, I only just realized.
The system is its own language. We have to write “bindings”, like rewriting
the X headers in our language, and such. Then we have like:
source(xwhateverbindings)
if not HasX11
build_standalone()
end
library(“x11bindings”)
The result of this, the same, compile, make static archive, and do not
attempt shared link. In this fashion, we can still compile our bindings
to check them somewhat, w/o error due to lack of underlying X11.
i.e. because we’d have unresolved symbols, depending (I know shared
libraries can sometimes have unresolved symbols).
The users of the library, granted:
if HasX11
use_library(“x11bindings”)
program(“guiapp”)
end
so no checking on executable source we cannot link.
Does my explanation make sense?
Is this possible in cmake? How?
If no way, maybe a reasonable feature request?
I do find the cmake documenation a bit obtuse, I’m sorry to say.
It speaks of higher level concepts.
Thank you very much,
- Jay