CMake Variables
Variables that Provide Information
CMAKE_CURRENT_SOURCE_DIRThe path to the source directory currently being processed.CMAKE_CURRENT_BINARY_DIRThe path to the binary directory currently being processed.CMAKE_SOURCE_DIRThe path to the top level of the source tree.CMAKE_BINARY_DIRThe path to the binary directory currently being processed.for an in-source build, this would be the same as
CMAKE_SOURCE_DIRfor an out-of-source build, this would be at
./buildfolder
PROJECT_SOURCE_DIRTop level source directory for the current project.PROJECT_BINARY_DIRFull path to build directory for project.<PROJECT-NAME>_SOURCE_DIRTop level source directory for the named project.<PROJECT-NAME>_BINARY_DIRTop level binary directory for the named project.PROJECT_VERSIONValue given to the VERSION option of the most recent call to theproject()command, if any.CMAKE_VERSIONCMAKE_COMMANDThe full path to the cmake executable.CMAKE_GENERATORThe generator used to build the project.
# ~/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_TYPESpecifies the build type on single-configuration generators.Can be set to
Debug,Release,RelWithDebInfo,MinSizeRel, ...
CMAKE_CONFIGURATION_TYPESSpecifies the available build types on multi-config generators.CMAKE_MODULE_PATHList of directories to search for CMake modules.Commands like
include()andfind_package()search for files in directories listed by this variable before checking the default modules that come with CMake.
CMAKE_INSTALL_PREFIXInstall directory used by install.If “make install” is invoked or INSTALL is built, this directory is prepended onto all install directories.
This variable defaults to
/usr/localon UNIX andc:/Program Fileson Windows.
CMAKE_XXX_PATH
By default it is empty, it is intended to be set by the project.
CMAKE_PREFIX_PATHPath used for searching by FIND_XXX(), with appropriate suffixes added.a.k.a.
CATKIN_DEVEL_PREFIXin earlier CMake versions; set tocatkin_ws/develfor example.It contains the “base” directories, the FIND_XXX() commands append appropriate subdirectories to the base directories.
FIND_PROGRAM() adds
/binto each of the directories in the path,FIND_LIBRARY() appends
/libto each of the directories, andFIND_FILE() and FIND_PATH() append
/include.
CMAKE_IGNORE_PATHPath to be ignored by FIND_XXX() commands.This is useful in cross-compiled environments where some system directories contain incompatible but possibly linkable libraries.
CMAKE_INCLUDE_PATHPath used for searching by FIND_FILE() and FIND_PATH().CMAKE_LIBRARY_PATHPath used for searching by FIND_LIBRARY().CMAKE_PROGRAM_PATHPath 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_PATHCMAKE_SYSTEM_INCLUDE_PATHCMAKE_SYSTEM_LIBRARY_PATHCMAKE_SYSTEM_PREFIX_PATHCMAKE_SYSTEM_PROGRAM_PATH
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_SYSTEMCMAKE_SYSTEM_NAMEUNIXorCMAKE_HOST_UNIXWIN32orCMAKE_HOST_WIN32MSVC,MSVC_VERSIONENV: Access environment variables.Use the syntax
$ENV{VAR}to read environment variable VAR.See also the
set()command to setENV{VAR}.
Variables that Control the Build
EXECUTABLE_OUTPUT_PATHLIBRARY_OUTPUT_PATHCMAKE_RUNTIME_OUTPUT_DIRECTORYWhere 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>_COMPILERThe full path to the compiler for LANG.CMAKE_CXX_COMPILER,CMAKE_C_COMPILER
CMAKE_<LANG>_FLAGSFlags for all build types.CMAKE_CXX_FLAGS,CMAKE_C_FLAGSCMAKE_<LANG>_FLAGS_RELEASEFlags for Release build type or configuration.
CMAKE_CXX_STANDARDNew in version 3.1. Default value for CXX_STANDARD property of targets.CMAKE_CUDA_STANDARDNew in version 3.8. Default value for CUDA_STANDARD property of targets.
Last updated
Was this helpful?