- Check Cmake version using
cmake --version
- Add comments using
#
- Variables are accessed using
${VARIABLE_NAME}
which is similar to bash scripting mark_as_advanced
ensures that variable doesn’t show up in GUIs unlessshow advanced
is ONoption()
does something similar more succinctly
This is pretty useful! It supports a range of CMake versions while also using the better settings. This is especially helpful when I’m focusing on backward compatibility without sacrificing modern behaviour
This line comes next. You describe
- The name of your project
- The version number of your project
- A simple description of your project
- The programming language of your project’s code
Add executable
exe_name
- The name of the executable you want to createtarget_name
- Name of CMake target generatedsource_files_names
- A list of all the source files and headers to compile with the target
Header Files
Header files will be ignored by CMake here. They are here only for them to show up in IDEs. CMake will compile source file extensions
Targets
This adds info about the include files the executable requires
- PUBLIC{Library} - Any targets that link to this target must require
include
- PRIVATE - Only affect current target, not dependency
- INTERFACE - Only needed for dependencies
graph LR
A["lib"]
B["exe"]
A -->|linked to| B
- Some source files are added to lib
- lib is now linked to exe
add_library()
- This makes a library that your project will use
- I’ll ignore STATIC for now. I don’t get what this does yet
Source: CMake Basics