Every statement in a CMake file is a command invocation (see
language syntax). These are all the commands
in the cmake-commands(7) manual, in its four groups. Each command’s
keywords and options are in its own manual page; a project may also define its own
commands with function() and macro(), and modules loaded with
include() add more.
Sources: the command list of
cmake-commands(7)
(CMake 4.5); each description is the summary at the top of that command’s own manual
page as shipped with CMake 4.4 (cmake --help-command), and for
add_custom_rule, discover_tests and
cmake_diagnostic the pages on cmake.org.
Scripting commands
Usable in every kind of CMake file, including scripts run with
cmake -P.
| Command | What it does |
|---|---|
block, endblock | Evaluate a group of commands with a dedicated variable and/or policy scope (CMake 3.25). |
break | Break from an enclosing foreach or while loop. |
cmake_diagnostic | Set, raise, lower or query the response (ignore, warn, error or fatal error) for each diagnostic category, with a push and pop stack (CMake 4.4). |
cmake_host_system_information | Query various host system information. |
cmake_language | Call meta-operations on CMake commands. |
cmake_minimum_required | Require a minimum version of CMake. |
cmake_parse_arguments | Parse function or macro arguments. |
cmake_path | Manipulate paths; only syntactic aspects are handled, the file system is not consulted (CMake 3.20). |
cmake_pkg_config | Process pkg-config format package files (CMake 3.31). |
cmake_policy | Manage CMake policy settings. |
configure_file | Copy a file to another location and modify its contents. |
continue | Continue to the top of the enclosing foreach or while loop. |
if, elseif, else, endif | Conditionally execute a group of commands; start the elseif and else parts; end the block. |
foreach, endforeach | Evaluate a group of commands for each value in a list. |
function, endfunction | Start recording a function for later invocation as a command. |
macro, endmacro | Start recording a macro for later invocation as a command. |
while, endwhile | Evaluate a group of commands while a condition is true. |
execute_process | Execute one or more child processes. |
file | File manipulation command. |
find_file, find_library, find_path, find_program | Find a file, a library, the folder holding a file, or a program. |
find_package | Find a package (an external project) and load its settings. |
get_cmake_property | Get a global property of the CMake instance. |
get_directory_property | Get a property of DIRECTORY scope. |
get_filename_component | Get a specific component of a full file name; superseded by cmake_path() from CMake 3.20. |
get_property | Get a property. |
include | Load and run CMake code from a file or module. |
include_guard | Provide an include guard for the file being processed (CMake 3.10). |
list | Operations on semicolon-separated lists. |
load_cache | Load in the values from another project’s CMakeCache.txt. |
mark_as_advanced | Mark cached variables as advanced. |
math | Evaluate a mathematical expression. |
message | Log a message. |
option | Provide a boolean option that the user can optionally select (default OFF). |
return | Return from a file, directory or function. |
separate_arguments | Parse command-line arguments into a semicolon-separated list. |
set | Set a normal, cache or environment variable to a given value. |
set_directory_properties | Set properties of the current directory and subdirectories. |
set_property | Set a named property in a given scope. |
site_name | Set the given variable to the name of the computer. |
string | String operations. |
unset | Unset a variable, cache variable or environment variable. |
variable_watch | Watch a CMake variable for change. |
Project commands
Usable in CMakeLists.txt files and the modules they include; script
mode does not allow commands that define build targets or actions.
| Command | What it does |
|---|---|
add_compile_definitions | Add preprocessor definitions to the compilation of source files. |
add_compile_options | Add options to the compilation of source files. |
add_custom_command | Add a custom build rule to the generated build system. |
add_custom_rule | Define a reusable rule that generates a custom build command for each source file in a file set, or derive one rule from another (CMake 4.5). |
add_custom_target | Add a target with no output, so it is always built. |
add_definitions | Add -D define flags to the compilation of source files. |
add_dependencies | Add a dependency between top-level targets. |
add_executable | Add an executable to the project from the given source files. |
add_library | Add a library to the project from the given source files (STATIC, SHARED, MODULE and other kinds; without a kind, BUILD_SHARED_LIBS decides). |
add_link_options | Add options to the link step for executables, shared libraries and modules. |
add_subdirectory | Add a subdirectory to the build. |
add_test | Add a test to the project, to be run by ctest. |
aux_source_directory | Find all source files in a directory. |
build_command | Get a command line to build the current project. |
cmake_file_api | Interact with the CMake file API (CMake 3.27). |
cmake_instrumentation | Interact with the CMake instrumentation API, configured per project (CMake 4.3). |
create_test_sourcelist | Create a test driver program that links together many small tests. |
define_property | Define and document custom properties. |
discover_tests | Have CTest run a discovery command at test time and register one test per matching line of its output (CMake 4.4). |
enable_language | Enable languages (C, CXX, OBJC, OBJCXX, Fortran and others). |
enable_testing | Enable testing for the current directory and below. |
export | Export targets or packages for outside projects to use directly from the build tree. |
fltk_wrap_ui | Create FLTK user-interface wrappers. |
get_source_file_property | Get a property of a source file. |
get_target_property | Get a property of a target. |
get_test_property | Get a property of a test. |
include_directories | Add include directories to the build. |
include_external_msproject | Include an external Microsoft project file in the generated solution. |
include_regular_expression | Set the regular expression used for dependency checking. |
install | Specify rules to run at install time. |
link_directories | Add directories in which the linker will look for libraries. |
link_libraries | Link libraries to all targets added later. |
project | Set the name of the project. |
remove_definitions | Remove compile definitions added by add_compile_definitions() or add_definitions(). |
set_source_files_properties | Set properties of source files, which affect how they are built. |
set_target_properties | Set properties of targets, which affect how they are built. |
set_tests_properties | Set a property of the tests. |
source_group | Define a grouping for source files in IDE project generation. |
target_compile_definitions | Add compile definitions to a target. |
target_compile_features | Add expected compiler features to a target. |
target_compile_options | Add compile options to a target. |
target_include_directories | Add include directories to a target. |
target_link_directories | Add link directories to a target. |
target_link_libraries | Specify libraries or flags to use when linking a target and its dependents. |
target_link_options | Add options to the link step for an executable, shared library or module target. |
target_precompile_headers | Add a list of header files to precompile. |
target_sources | Add sources to a target. |
try_compile | Try building some code. |
try_run | Try compiling and then running some code. |
CTest commands
For CTest dashboard client scripts.
| Command | What it does |
|---|---|
ctest_build | Perform the CTest build step as a dashboard client. |
ctest_configure | Perform the CTest configure step. |
ctest_coverage | Perform the CTest coverage step. |
ctest_empty_binary_directory | Empty the binary directory. |
ctest_memcheck | Perform the CTest memory-check step. |
ctest_read_custom_files | Read CTestCustom files. |
ctest_run_script | Run a ctest -S script. |
ctest_sleep | Sleep for some amount of time. |
ctest_start | Perform the CTest start step. |
ctest_submit | Perform the CTest submit step. |
ctest_test | Perform the CTest test step. |
ctest_update | Perform the CTest update step. |
ctest_upload | Upload files to a dashboard server. |
Deprecated commands
| Command | Status, as its manual page gives it |
|---|---|
build_name | Disallowed since CMake 3.0 (policy CMP0036); use ${CMAKE_SYSTEM} and ${CMAKE_CXX_COMPILER}. |
exec_program | Available only while policy CMP0153 is not NEW (CMake 3.28); port to execute_process(). |
export_library_dependencies | Disallowed since CMake 3.0 (CMP0033). |
install_files, install_programs, install_targets | Superseded by install(); kept for older code. |
load_command | Disallowed since CMake 3.0 (CMP0031). |
make_directory | Creates the named directory and any missing parents. |
output_required_files | Disallowed since CMake 3.0 (CMP0032). |
qt_wrap_cpp | Makes moc files for listed headers; the page suggests the AUTOMOC target property instead. |
qt_wrap_ui | Makes .h and .cxx files from .ui files. |
remove | Removes values from a list variable. |
subdir_depends | Disallowed since CMake 3.0 (CMP0029). |
subdirs | Adds subdirectories; add_subdirectory() should be used instead. |
use_mangled_mesa | Disallowed since CMake 3.0 (CMP0030). |
utility_source | Disallowed since CMake 3.0 (CMP0034). |
variable_requires | Disallowed since CMake 3.0 (CMP0035); use if(). |
write_file | Writes text to a file; file(WRITE) and file(APPEND) do the same and more. |