一个用于学习 C++ 语法和 C++ Core Guidelines 的 demo 工程
本工程使用 Git submodule 引入 Microsoft GSL:
third_party/microsoft-gsl -> https://github.com/microsoft/GSL.git
GSL 当前固定在:
v4.2.0
推荐直接递归克隆:
git clone --recurse-submodules https://github.com/XiaoYang943/CookBook-CPP.git如果已经普通 clone 了,需要再初始化子仓库:
git submodule update --init --recursive查看当前子仓库指向的提交:
git submodule status查看 GSL 当前版本:
git -C third_party/microsoft-gsl describe --tags --exact-match进入子仓库:
cd third_party/microsoft-gsl拉取远端 tag:
git fetch --tags切换到指定版本,例如:
git checkout v4.2.0回到主工程并提交 submodule 指针变化:
cd ../..
git add third_party/microsoft-gsl
git commit -m "Update Microsoft GSL submodule"根目录的 CMakeLists.txt 会优先检测:
third_party/microsoft-gsl/CMakeLists.txt
如果存在,就通过:
add_subdirectory(third_party/microsoft-gsl EXCLUDE_FROM_ALL)把 GSL 作为子工程引入
所有 demo target 都会链接:
Microsoft.GSL::GSL所以 demo 中可以直接使用:
#include <gsl/gsl>打开工程后,等待 CLion 自动 Reload CMake
如果 GSL 相关头文件无法解析,先确认子仓库已经初始化:
git submodule update --init --recursive然后在 CLion 中执行:
Reload CMake Project