[CMake] Proper way to export a library
Matthew Woehlke
matthew.woehlke at kitware.com
Mon Nov 4 11:04:51 EST 2013
On 2013-11-02 13:38, Cyrille Faucheux wrote:
> [...] from what I understood from Matthew first answer ("implicit compile
> flags [...] for imported tagets"), I was under the impression that I could
> get MYPROJECT_STATIC automatically defined when linking another program
> against a static version of my library (through its imported target).
Yes and no. *You* have to set the flag as part of your library's
interface compile definitions. But once you do that, cmake should export
that, and anyone linking to your library (via imported target) should
automatically pick up the flag.
> I've looked the documentation of target_compile_definitions, but it seems
> to be about compiling the library, not linking against its imported target.
> Am I right?
No; at least not entirely in the case of 't_c_d({PUBLIC|INTERFACE})'. A
PUBLIC definition is used both to compile your library and by anyone
linking to it. An INTERFACE definition is used *only* by other targets
linking to it.
See also the INTERFACE_COMPILE_DEFINITIONS property and note in the
t_c_d documentation how t_c_d affects that property.
--
Matthew
More information about the CMake
mailing list