CMake中常见的内置变量
# CMake中常见的内置变量
# CMake常见内置变量说明
CMake的所有内置变量可通过官方文档cmake-variables (opens new window)进行查阅,以下仅对较为常见的内置变量进行说明。
PROJECT_NAME
返回通过
PROJECT
定义的项目名称
CMAKE_BUILD_TYPE
返回项目构建的类型
常常用以下三行作为 CMakeLists.txt
的开头,让默认的构建类型为发布模式。
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
CMAKE_C_COMPILER
C编译器
CMAKE_CXX_COMPILER
C++编译器
PROJECT_BINARY_DIR
表示工程的编译目录
PROJECT_SOURCE_DIR
表示工程的源码目录
CMAKE_CURRENT_SOURCE_DIR
当前处理的
CMakeLists.txt
所在的路径
CMAKE_CURRENT_LIST_FILE
调用这个变量的
CMakeLists.txt
的完整路径
CMAKE_MODULE_PATH
find_package
指令在这个路径下查找xxx.cmake文件
EXECUTABLE_OUTPUT_PATH
定义目标二进制可执行文件的存放位置
LIBRARY_OUTPUT_PATH
定义目标链接库文件的存放位置
# 输出结果
# Windows
1.PROJECT_NAME = projectName
2.CMAKE_C_COMPILER = cl.exe
3.CMAKE_CXX_COMPILER = D:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe
4.PROJECT_BINARY_DIR = D:/Users/Sirius0v0/000-worktable/MyTemplate/out/build/x64-debug
5.PROJECT_SOURCE_DIR = D:/Users/Sirius0v0/000-worktable/MyTemplate
6.CMAKE_CURRENT_SOURCE_DIR = D:/Users/Sirius0v0/000-worktable/MyTemplate
7.CMAKE_CURRENT_LIST_FILE = D:/Users/Sirius0v0/000-worktable/MyTemplate/CMakeLists.txt
8.CMAKE_MODULE_PATH =
9.EXECUTABLE_OUTPUT_PATH =
10.LIBRARY_OUTPUT_PATH =
# Ubuntu
1.PROJECT_NAME = projectName
2.CMAKE_C_COMPILER =
3.CMAKE_CXX_COMPILER = /usr/bin/c++
4.PROJECT_BINARY_DIR = /home/sirius0v0/worktable/MyTemplate/build
5.PROJECT_SOURCE_DIR = /home/sirius0v0/worktable/MyTemplate
6.CMAKE_CURRENT_SOURCE_DIR = /home/sirius0v0/worktable/MyTemplate
7.CMAKE_CURRENT_LIST_FILE = /home/sirius0v0/worktable/MyTemplate/CMakeLists.txt
8.CMAKE_MODULE_PATH =
9.EXECUTABLE_OUTPUT_PATH =
10.LIBRARY_OUTPUT_PATH =
编辑 (opens new window)
上次更新: 2023/08/14, 19:51:00