输入“/”快速插入内容

CMake & c++ 编译体系

2024年9月22日修改
2024年3月10日创建
820
891
Summary
1.
入口文件 CMakeLists.txt。是一个 script,从上到下依次执行。
2.
是 build system generator,不是 build system。生成的东西,可以给 make, Ninja 等用。
CMake 入门材料,预计需要 1 天时间。
CMake - the essential package https://www.youtube.com/watch?v=UH6F6ypdYbw
cmake vs Bazel
Bazel is a multi-language build system focused on reproducible builds to enable dependency analysis and caching for fast incremental builds.
CMake v.s. Bazel:
1.
在 llvm 和 mlir 生态里,尽量还是 cmake。遵循社区主流。
2.
其他情况,bazel 大概率更好用。
llvm-project 对 Bazel 的支持不太稳定。
Reviewers should not ask authors to update Bazel build files unless the author has opted in to support Bazel. Keeping the Bazel build files up-to-date is on the people who use the Bazel build.
Cmake
Example
一共 3 个文件:
CMakeLists.txt
run.sh
test.cpp
CMakeLists.txt 的简单例子
代码块
cmake_minimum_required(VERSION 3.20.0)
project(CmakeTutorial-Jack)
# add_executable(${PROJECT_NAME} test.cpp)
add_executable(b.out test.cpp)
# install(TARGETS b.out DESTINATION bin)
运行脚本 run.sh
代码块
mkdir -p build && cd build
# Generating Build files
# -S source dir
# -B build dir
cmake -S .. -B .
# Building CXX object and Linking
make -j8 # Run make with 8 threads
# run executable target
./b.out