cmake Command: Configure C++ Builds in CI
cmake generates native build files (Make/Ninja) and drives the build.
CMake is the de facto build-system generator for C/C++. In CI it runs in two phases: configure (generate build files from CMakeLists.txt) and build (invoke the underlying generator). Presets standardize both across environments.
Common flags
-S DIR/-B DIR- source dir / build (binary) dir-G "Ninja"- choose the generator (Ninja, Unix Makefiles, ...)-D CMAKE_BUILD_TYPE=Release- set a cache variable--build DIR- run the build phase in a configured dir--target NAME- build a specific target-j N(with --build) - parallel build jobs--preset NAME- use a configure preset from CMakePresets.json
Example in CI
Configure with Ninja and a Release build type, then build in parallel:
shell
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)Common errors in CI
- CMake Error: could not find CMAKE_ROOT / CMakeLists.txt - wrong -S dir
- No CMAKE_CXX_COMPILER could be found - install a C++ compiler on the runner
- Could NOT find Package (missing: Package_DIR) - dependency not installed/discoverable
- CMake Error: Generator ... does not match the generator used previously - stale build dir
Key takeaways
- Configure then build are two separate cmake invocations (
-Bthen--build). - Pick the generator with
-G; Ninja is fastest on CI. - "No CMAKE_CXX_COMPILER" means the runner image lacks a C++ toolchain.
Related guides
make Command: Run Builds in CImake runs builds from a Makefile. Reference for -j, -C, -f, -B, -k, VAR=value overrides, and the Makefile err…
ninja Command: Fast Builds in CIninja is a small, fast build system. Reference for -j, -C, -f, -t, -k, -v, and the ninja CI errors you will s…
gcc Command: Compile C in CIgcc is the GNU C compiler driver. Reference for -c, -o, -I, -L, -l, -Wall, -O2, -std, and the header/library…