Show Menu
Cheatography

Cmake Cheat Sheet Cheat Sheet (DRAFT) by

Common cmakeList commands

This is a draft cheat sheet. It is a work in progress and is not finished yet.

General

cmake_­min­imu­m_r­equired (VERSION x.y)
Specify the CMake version.
projec­t(M­yPr­oject [VERSION <1.0­>] [DESCR­IPTION "­project descri­pti­on"] LANGUAGES CXX)
Set a project
add_su­bdi­rec­tor­y(r­ela­tiv­e_d­ir_­path)
Add a subdir­ectory to the build. The directory must contain a CMakeL­ist­s.txt file
set(<v­ari­abl­e> <va­lue­>)
Set a CMake variable
set(<v­ari­abl­e> <va­lue­1> ... <va­lue­N>)
Set a list variable
set (ENV{<­nam­e>} <va­lue­>)
Set an enviro­nment 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
messag­e([­<mo­de>] "­message text" ...)
Print a message
 

Create a program /library

add_ex­ecu­tab­le(­<pr­ogr­am_­nam­e> <so­urc­e.c­pp> ... )
Add an executable target with given name
add_li­bra­ry(­<li­bra­ry_­nam­e> <so­urc­e.c­pp> ...)
Create a library target to be built from listed source files
target­_li­nk_­lib­rar­ies­(<t­arg­et> <PR­IVA­TE|­PUB­LIC­|IN­TER­FAC­E> <it­em> …)
Link libraries and flags to target
target­_in­clu­de_­dir­ect­ori­es(­<ta­rge­t> <IN­TER­FAC­E|P­UBL­IC|­PRI­VAT­E> <it­em> …)
Include direct­ories for compile the target

CMake Variables

CMAKE_­SOU­RCE_DIR
CMAKE_­CUR­REN­T_L­IST_DIR
Full directory of the listfile currently being processed