Data source: www.jetbrains.com
File: main.cpp
File: add.h
File: add.cpp
main.cpp
) by the compilermain.cpp
) by the compilerHow does the build system know which header belongs to which translation unit?
File: main.cpp
int main()
int add(int, int)
int add(int, int)
Change main.cpp
:
Rebuild:
Sometimes callsite needs definition.
.a
,
.so
, …)addition
(library)example
(executable)What if
addition
depends on a libraryXYZ
?
XYZ
to addition
.example
automatically depends on
XYZ
.Target | User | |
---|---|---|
PRIVATE | x | |
PUBLIC | x | x |
INTERFACE | x |
BUILD_SHARED_LIBS
defines default.
Library knows paths and flags.
Library knows paths and flags.
CONFIG
mode: library maintainer provides settingsMODULE
mode: a provided program tries to detect
settingsMANUAL
mode: 🙁Eigen3
: CONFIG
mode 😎HDF5
: MODULE
mode
🙂PETSc
: MANUAL
mode 🙁
PkgConfig
may helpUse targets, not global variables.
set(CMAKE_CXX_FLAGS "-std=c++11")
😭target_compile_features(addition PUBLIC cxx_std_11)
😎Platform-independent builds.
Configure:
cmake -DCMAKE_BUILD_TYPE=Debug -S src -B build -G Ninja
# -DCMAKE_BUILD_TYPE=... Build type
# -S Source directory
# -B Build directory
# -G Build system generator
Build:
Default: Don’t pass any compiler options | |
Debug |
Enable debug compiler flags |
Release |
Enable compiler optimization flags |
RelWithDebInfo |
Include debug information for profilers |
MinSizeRel |
Release, optimizing size instead of performance |
More info: Manual