cmake --build Command Reference
Build a configured project through one generator-agnostic command.
cmake --build invokes the underlying generator (Make, Ninja, MSBuild) with one portable syntax, so the same CI command works across platforms.
What it does
cmake --build DIR runs the native build tool for the build system generated into DIR. It abstracts over Make, Ninja, and MSBuild so your pipeline does not hardcode a generator-specific command.
Common flags and usage
- --build DIR: the build directory to build
- --target NAME: build a specific target (default: all)
- --config Release|Debug: select config for multi-config generators
- --parallel N / -j N: parallel build jobs
- -- <native args>: pass options straight to the underlying tool
Example
shell
- name: Build
run: cmake --build build --config Release --parallel "$(nproc)"In CI
Use cmake --build everywhere so the same command works whether the generator is Make or Ninja. Pass --parallel "$(nproc)" to use all cores, and --config for multi-config generators where the build type is chosen at build time.
Key takeaways
- cmake --build is generator-agnostic; the same command drives Make or Ninja.
- --parallel N (or -j N) controls build parallelism.
- --config selects the build type for multi-config generators.
Related guides
cmake Configure Command ReferenceReference for the cmake configure step in CI/CD: generate a build system out-of-source with -S/-B, pick a gen…
cmake --install Command ReferenceReference for cmake --install in CI/CD: stage built artifacts into a prefix or DESTDIR for packaging, with co…
ctest Command ReferenceReference for ctest in CI/CD: run a CMake test suite, parallelize with -j, filter by name or label, and surfa…