CMake configuration suite for common multiplatform c++ projects
- Presets for specific toolchains (native/clang/emscripten/android)
- Git-based Package Management
- IDE integration
- c++20 Utils module
- cmake:
include(C++Utils) target_link_libraries(<TARGET> .cmake::Utils)
- c++:
import dotcmake; - For features review main.c++
- cmake:
- cmake > 4.0.0
- gcc > 15
- clang > 19
Add this repository as a git-submodule and include CMakePresets.json in the top-level project.
Cross-Compile targets are enabled via environment variables:
| Target | Environment Variable | Example |
|---|---|---|
| debug release |
||
| debug::clang release::clang |
||
| debug::emscripten release::emscripten |
EMSCRIPTEN_ROOT EMSDK [1] |
/usr/lib/emscripten .cache/emsdk |
| debug::android release::android |
ANDROID_HOME JAVA_HOME [2] |
~/Android/Sdk /opt/android-studio/jbr |
[1] If EMSCRIPTEN_ROOT is unset use existing EMSDK or install emsdk at that location
[2] Optional but preferred JDK location (fallback to system Java)
From an empty directory run:
git init && git submodule add https://github.com/Diyou/.cmake && .cmake/setup c++-
- For vscode extensions to see environment variables export them in ~/.profile and run
source ~/.profile && /usr/bin/codeor similar
- For vscode extensions to see environment variables export them in ~/.profile and run
-
- .cmake can automatically copy launch configurations (launch.json) into .vscode depending on the currently configured compiler (see Options)
- [F5] or launch the default configuration
NOTE: Don't use the cmake-tools debug icon
-
Until cpptools fully supports c++20 modules and import std; I suggest to install vscode-clangd and disable the intellisense engine
.cmake can adjust the clangd.path automatically when cross-compiling
NOTE: Run the 'clangd: Restart language server' command after switching presets or initial build.