概念
Ref: Getting Started
文件结构
在 CMake 中划分了两个基础路径结构,source 和 binary,推荐将 source 与 binary 路径分开,这样文件路径可以更加整洁。
- source directory: 源码位置,即CMakeLists 文件位置,并且是只读的
- binary directory: 构建位置,存放输出文件,只写
典型的工作流
- 通过 CMakeLists 定义项目
- CMake 配置 (configure) 并生成 (generate) 项目
- 用户使用自定义开发构建项目
Hello World
cmake_minimum_required(VERSION 3.20)
project(Hello)
add_executable(Hello Hello.c)
所有调用了project
的 CMakeLists 会为其生成一个 Makefile,包含该 CMakeLists 中和add_subdirectory
中的 target。