Cheatography
https://cheatography.com
Common cmakeList commands
This is a draft cheat sheet. It is a work in progress and is not finished yet.
General
cmake_minimum_required (VERSION x.y)
|
Specify the CMake version. |
project(MyProject [VERSION <1.0>] [DESCRIPTION "project description"] LANGUAGES CXX)
|
Set a project |
add_subdirectory(relative_dir_path)
|
Add a subdirectory to the build. The directory must contain a CMakeLists.txt file |
set(<variable> <value>)
|
Set a CMake variable |
set(<variable> <value1> ... <valueN>)
|
Set a list variable |
set (ENV{<name>} <value>)
|
Set an environment variable |
option(MY_OPTION "This is settable from the command line" ON|OFF) |
Set a boolean variable. It can be set from the command line |
message([<mode>] "message text" ...)
|
Print a message |
|
|
Create a program /library
add_executable(<program_name> <source.cpp> ... )
|
Add an executable target with given name |
add_library(<library_name> <source.cpp> ...)
|
Create a library target to be built from listed source files |
target_link_libraries(<target> <PRIVATE|PUBLIC|INTERFACE> <item> …)
|
Link libraries and flags to target |
target_include_directories(<target> <INTERFACE|PUBLIC|PRIVATE> <item> …)
|
Include directories for compile the target |
CMake Variables
|
CMAKE_CURRENT_LIST_DIR
|
Full directory of the listfile currently being processed |
|