Targets, Properties, And More¶
Target Types¶
Two basic types:
add_executable()
andadd_library()
add_executable()
is not relevant …Only entry point into dependency graph
⟶ does not propagate anything to dependers
There are no dependers
add_library()
…Type
Description
Normal library
STATIC
(default),SHARED
,MODULE
. Has sources to be built.Object libraries
Technically much like normal libraries, but not an archive or shared object (only virtual, implemented by CMake)
Interface libraries
No sources; only there to propagate properties to dependers, and to have further dependencies on their own.
Properties¶
(For a complete list see add_library())
Target function |
Property name |
Description |
Documentation |
---|---|---|---|
|
|
Macros set on the compiler command line ( |
|
|
|
Non-macro compiler flags/options |
|
|
|
Include directories |
|
|
(Much more complicated, see documentation) |
Dependencies, in the widest sense |
|
|
Any property, including custom properties |
See documentation |
Properties: PRIVATE
, PUBLIC
, INTERFACE
?¶
PUBLIC
propagated to dependersDependency through
#include <other.h>
in a header file ⟶ all includers need to knowblacklist
availability in approach 2 (but only ifblacklist
has compiled code)PUBLIC
only possible when target has compiled code
PRIVATE
does not propagateFor example, one might structure a target’s source code into
src/
,private-inc/
, andpublic-inc/
⟶private-inc/
would betarget_include_directories(... PRIVATE ...)
For example,
target_compile_definitions()
for target-local compilation only
INTERFACE
propagated to dependersJust like
PUBLIC
- except thatPUBLIC
is not possible onINTERFACE
targets (e.g. header-only libraries)Asymmetric; smells like it does in many corners of CMake
Documentation has no clear explanation. Exceptions, and paragraph-long explanations.
Demo Time¶
Move on to Screenplay: Public And Private Include Directories