Cmake

发布时间 2023-04-02 22:51:10作者: 小白一号(本降专)

1.Generate a Project Buildsystem

 cmake [<options>] <path-to-source>
 cmake [<options>] <path-to-existing-build>
 cmake [<options>] -S <path-to-source> -B <path-to-build>

2.Buid a Project

cmake --build <dir> [<options>] [-- <build-tool-options>]

3.Install a Project

cmake --install <dir> [<options>]

4.Open a Project

 cmake --open <dir>

5.Run a Script

cmake [{-D <var>=<value>}...] -P <cmake-script-file>

6.Run a Command-Line Tool

cmake -E <command> [<options>]

7.Run the Find-Package Tool

cmake --find-package [<options>]

8.View Help

cmake --help[-<topic>]

1.工程目录下的 CMakeList.txt

cmake_minimun_required(VERSION 版本号) #必须
project(项目名)  #必须,后输出的可执行文件和它同名
add_executable(Example main.cpp)  #必须
set(var a.cpp b.cpp)  #变量

2.配置项目

cmake -S . -B build


3. 构建项目

cmake --build build