CMake Best Practices
In a Nutshell
Declare modules with
ADD_LIBRARY
orADD_EXECUTABLE
Declare build flags with
TARGET_xxx()
Declare dependencies with
TARGET_LINK_LIBRARIES
Specify which is
PUBLIC
and which isPRIVATE
Boilderplate
Headers
Add Libraries
Declare Flags
Declare Dependencies
Header-only libraries
INTERFACE basically indicates that we don't need to build anything
DO NOT
Don't use macros that affect all targets:
INCLUDE_DIRECTORIES()
ADD_DEFINITIONS()
LINK_LIBRARIES
Dont' use
TARGET_INCLUDE_LIBRARIES()
with path outside your own moduleDon't use
TARGET_LINK_LIBRARIES()
without specifying scope (PUBLIC, PRIVATE, or INTERFACE)Don't use
TARGET_COMPILE_OPTIONS()
to set flags that affect the ABI
Last updated