1. 基础操作
# 设置cmake的最低版本
cmake_minimum_required(VERSION 3.10)
# 设置项目名称和版本号
project(Tutorial VERSION 1.0)
# 添加一个可执行文件构建目标
add_executable(Tutorial tutorial.cxx)
# 配置文件,通过头文件传递,使得在代码文件中使用CMake中定义的的变量
configure_file(TutorialConfig.h.in TutorialConfig.h)
# 指定目标包含的头文件路径,此处目标二进制是Tutorial
target_include_directories(Tutorial PUBLIC
"${PROJECT_BINARY_DIR}"
)
// the configured options and settings for Tutorial
#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
if (argc < 2) {
// report version
std::cout << argv[0] << " Version " << Tutorial_VERSION_MAJOR << "."
<< Tutorial_VERSION_MINOR << std::endl;
std::cout << "Usage: " << argv[0] << " number" << std::endl;
return 1;
}
# 设置C++标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)