[CMake] Static Modules
Michael Wild
themiwi at gmail.com
Fri Mar 12 08:00:29 EST 2010
On 12. Mar, 2010, at 11:42 , Markus Raab wrote:
> Hello!
>
> Michael Wild wrote:
>> IMHO it would be simpler and safer to have a function which collects all
>> the file names, adds them to a global property and then allows you to
>> compile a static library from that. E.g (completely untested):
>
> Yeah, you are right, this approach sounds much better.
>
> But there is still a small missing piece. Modules have at least one entry
> point (or symbol) which is the same, so that they can be loaded.
>
> This is perfectly ok for modules, but raises a problem when you want to link
> them together statically.
>
> Elektra has solved this issue by having defined:
> #ifdef ELEKTRA_STATIC
> #define KDBEXPORT(module) KDB
> *libelektra_##module##_LTX_kdbBackendFactory(void)
> #else
> #define KDBEXPORT(module) KDB *kdbBackendFactory(void)
> #endif
>
> and Modules use
> KDBEXPORT(modulename)
> {
> return kdbBackendExport(BACKENDNAME, ...
> }
>
> to export this symbol which changes for the module and static case.
>
>
> Which is the cmake way to solve this issue?
>
> thank you
> Markus
>
>
> --
> http://www.markus-raab.org | I can't believe that life's so complex,
> -o) | when I just want to sit here and watch you
> Kernel 2.6.24-1-a /\ | undress
> on a x86_64 _\_v |
For shared libraries, CMake defined <name>_EXPORTS automatically, so you could use that in a #ifndef. Alternatively, in MY_ADD_STATIC_MODULE you can do the following after the ADD_LIBRARY call:
set_target_properties(${name} PROPERTIES
COMPILE_DEFINITIONS ${name}_STATIC)
HTH
Michael
More information about the CMake
mailing list