I have a set of C source files and headers. From this I want to compile a shared library for normal linkage and then similar (just some different DEFINEs) MODULE library used to dynamically load the functionality as a module with RTLD_GLOBAL, so the namespace will be afterwards infused with its symbols.
For modules which depends on symbols from previous modules, I need to create an interface - set of header files. For the normal shared library, this works well as I just set the
PUBLIC and every library depending on it with
target_link_libraries() will transitively get the headers. But I cannot use the
target_link_libraries() call to get the same functionality for
MODULE library because in that case that library will be linked in the binary, which cannot be.
One way how to solve this is to create an
INTERFACE library with only the PUBLIC headers and
target_link_libraries() this to both the shared library and the MODULE library. Any additional module which will depend on this module will just
target_link_libraries() the INTERFACE library.
Problem is, I feel this is ugly, and I am making everybody who wants to add another module to the software package to add basically two targets instead of one (not every module will have both shared library and MODULE library version).
So, can I somehow set an option on the
MODULE library that when somebody calls
target_link_libraries() on it, it will only add the headers, but will not link in any way?
Forgot to mention: This is Linux only question. Probably GNU Libc only too.