CMake基本语句

  1. Declare a target
  2. Declare target’s traits
  3. It’s all about targets

Hello CMake

一个最简单的CMake:

1
2
3
4
5
6
7
8
9
10
# Set the minimum version of CMake that can be used
# To find the cmake version run
# $ cmake --version
cmake_minimum_required(VERSION 3.5)

# Set the project name
project (hello_cmake VERSION 1.0.0)

# Add an executable file
add_executable(hello main.cpp)

基本语句及功能

cmake_minimum_required

指定最小的cmake版本

project

指定project的名称和版本号

add_subdirectory

add_subdirectory(src)会跳转到对应的src文件中,并寻找src/CMakeLists.txt,更新环境变量

1
add_subdirectory
0%