CMake Commands
CMake Commands
Starting from v3.0, CMake commands are all in lower case SET() --> set()
Common
message([<mode>] "message to display" ...)
set(<variable> <value> [[CACHE <type> <docstring> [FORCE]] | PARENT_SCOPE])
unset(<variable> [CACHE | PARENT_SCOPE])
option(<option_variable> "help string describing option" [initial value])
export(EXPORT <export-name> [NAMESPACE <namespace>] [FILE <filename>])
install(TARGETS targets... [EXPORT <export-name>] [...])
file(WRITE filename "message to write"... )
also READ/APPEND/...list(APPEND <list> [<element> ...])
also LENGTH/FIND/INSERT/REMOVE/SORT...string(REGEX REPLACE <regular_expression> <replace_expression> <output variable>
<input> [<input>...])
also FIND/COMPARE/LENGTH/TOLOWER...
Flow Control
if()
,elseif()
,else()
,endif()
while()
,endwhile()
foreach()
,endforeach()
macro()
,endmacro()
function()
,endfunction()
break()
,return()
enable_language(<lang> [OPTIONAL] )
enable_testing()
Build Target
find_file (<VAR> name1 [path1 path2 ...])
find_library (<VAR> name1 [path1 path2 ...])
find_package(<package> [version] [EXACT] [QUIET] [MODULE] [REQUIRED] [[COMPONENTS]
[components...]] [OPTIONAL_COMPONENTS components...] [NO_POLICY_SCOPE])
find_path (<VAR> name1 [path1 path2 ...])
find_program (<VAR> name1 [path1 path2 ...])
add_compile_options(<option> ...)
add_definitions(-DFOO -DBAR ...)
: Adds -D define flags to the compilation of source files.add_dependencies(<target> [<target-dependency>]...)
add_executable(<name> source1 [source2 ...])
add_library(<name> [STATIC | SHARED | MODULE] source1 [source2 ...])
add_subdirectory()
add_test()
include_directories()
for all build targetstarget_include_directories()
for a specific build targettarget_link_libraries()
link to a specific targetHeader-only libraries (e.g., Eigen3) are not needed to be linked here.
target_link_directories()
is not encouraged to use
Build Dependencies
configure_file(<input> <output> [...])
Copy a file to another location and modify its contents.execute_process(COMMAND <cmd1> [args1...]] [WORKING_DIRECTORY <directory>] [...])
include(<file|module>[...])
Load and run CMake code from a file or module.
Last updated