# CMake Variables

## Variables that Provide Information

* `CMAKE_CURRENT_SOURCE_DIR`  The path to the source directory currently being processed.
* `CMAKE_CURRENT_BINARY_DIR`  The path to the binary directory currently being processed.
* `CMAKE_SOURCE_DIR`  The path to the top level of the source tree.
* `CMAKE_BINARY_DIR`  The path to the binary directory currently being processed.
  * for an in-source build, this would be the same as `CMAKE_SOURCE_DIR`
  * for an out-of-source build, this would be at `./build` folder
* `PROJECT_SOURCE_DIR`  Top level source directory for the current project.
* `PROJECT_BINARY_DIR`  Full path to build directory for project.
* `<PROJECT-NAME>_SOURCE_DIR`  Top level source directory for the named project.
* `<PROJECT-NAME>_BINARY_DIR`  Top level binary directory for the named project.
* `PROJECT_VERSION` Value given to the VERSION option of the most recent call to the `project()` command, if any.
* `CMAKE_VERSION`&#x20;
* `CMAKE_COMMAND`  The full path to the cmake executable.
* `CMAKE_GENERATOR`  The generator used to build the project.

```bash
# ~/catkin_ws/src/example_pkg
message(${CMAKE_CURRENT_SOURCE_DIR})
message(${CMAKE_SOURCE_DIR})
message(${PROJECT_SOURCE_DIR})

# ~/catkin_ws/build/example_pkg
message(${CMAKE_CURRENT_BINARY_DIR})
message(${CMAKE_BINARY_DIR})
message(${PROJECT_BINARY_DIR})
```

## Variables that Change Behavior

* `CMAKE_BUILD_TYPE`  Specifies the build type on single-configuration generators.
  * Can be set to `Debug`, `Release`, `RelWithDebInfo`, `MinSizeRel`, ...
* `CMAKE_CONFIGURATION_TYPES` Specifies the available build types on multi-config generators.
* `CMAKE_MODULE_PATH` List of directories to search for CMake modules.
  * Commands like `include()` and `find_package()` search for files in directories listed by this variable before checking the default modules that come with CMake.
* `CMAKE_INSTALL_PREFIX` Install directory used by install.
  * If “make install” is invoked or INSTALL is built, this directory is **prepended** onto all install directories.&#x20;
  * This variable defaults to `/usr/local` on UNIX and `c:/Program Files` on Windows.

#### CMAKE\_XXX\_PATH

By default it is empty, it is intended to be set by the project.

* `CMAKE_PREFIX_PATH`  Path used for searching by FIND\_XXX(), with appropriate suffixes added.
  * a.k.a. `CATKIN_DEVEL_PREFIX` in earlier CMake versions; set to `catkin_ws/devel` for example.
  * It contains the “base” directories, the FIND\_XXX() commands append appropriate subdirectories to the base directories.&#x20;
    * FIND\_PROGRAM() adds `/bin` to each of the directories in the path,&#x20;
    * FIND\_LIBRARY() appends `/lib` to each of the directories, and&#x20;
    * FIND\_FILE() and FIND\_PATH() append `/include`.&#x20;
* `CMAKE_IGNORE_PATH` Path to be ignored by FIND\_XXX() commands.
  * This is useful in cross-compiled environments where some system directories contain incompatible but possibly linkable libraries.&#x20;
* `CMAKE_INCLUDE_PATH` Path used for searching by FIND\_FILE() and FIND\_PATH().
* `CMAKE_LIBRARY_PATH` Path used for searching by FIND\_LIBRARY().
* `CMAKE_PROGRAM_PATH` Path used for searching by FIND\_PROGRAM().

#### CMAKE\_SYSTEM\_XXX\_PATH

By default it contains the standard directories for the current system. It is NOT intended to be modified by the project.

*

```
`CMAKE_SYSTEM_IGNORE_PATH`
```

* `CMAKE_SYSTEM_INCLUDE_PATH`
* `CMAKE_SYSTEM_LIBRARY_PATH`
* `CMAKE_SYSTEM_PREFIX_PATH`
* `CMAKE_SYSTEM_PROGRAM_PATH`

```bash
message("${CMAKE_BUILD_TYPE}")  # add "" to prevent error from empty variable
message("${CMAKE_CONFIGURATION_TYPES}")
message("${CMAKE_MODULE_PATH}")
message("${CMAKE_INSTALL_PREFIX}")
```

## Variables that Describe the System

* `CMAKE_HOST_SYSTEM`
* `CMAKE_SYSTEM_NAME`&#x20;
* `UNIX` or `CMAKE_HOST_UNIX`
* `WIN32` or `CMAKE_HOST_WIN32`
* `MSVC`, `MSVC_VERSION`
* `ENV`: Access environment variables.&#x20;
  * Use the syntax `$ENV{VAR}` to read environment variable VAR.&#x20;
  * See also the `set()` command to set `ENV{VAR}`.

## Variables that Control the Build

* `EXECUTABLE_OUTPUT_PATH`
* `LIBRARY_OUTPUT_PATH`
* `CMAKE_RUNTIME_OUTPUT_DIRECTORY` Where to put all the RUNTIME targets when built.
  * This variable is used to initialize the RUNTIME\_OUTPUT\_DIRECTORY property on all the targets.
  * See that target property for additional information.

## Variables for Languages

* `CMAKE_<LANG>_COMPILER` The full path to the compiler for LANG.
  * `CMAKE_CXX_COMPILER`, `CMAKE_C_COMPILER`
* `CMAKE_<LANG>_FLAGS`  Flags for all build types.
  * `CMAKE_CXX_FLAGS`, `CMAKE_C_FLAGS`
  * `CMAKE_<LANG>_FLAGS_RELEASE`  Flags for Release build type or configuration.
* `CMAKE_CXX_STANDARD` New in version 3.1. Default value for CXX\_STANDARD property of targets.
* `CMAKE_CUDA_STANDARD`New in version 3.8.  &#x20;Default value for CUDA\_STANDARD property of targets.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.hanzheteng.com/development/cmake/cmake-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
