Skip to content

Ninja: Add multi-configuration variant

Kyle Edwards requested to merge kyle.edwards/cmake:ninja-multi into master

This MR continues the work of !2483 (closed). Some small pieces of it were used in this MR, but most of it is done from scratch, as master has changed too much to simply rebase the old MR.

Rather than having a single build.ninja file, this new multi-configuration Ninja generator has one build-<config>.ninja file for each configuration in CMAKE_CONFIGURATION_TYPES, intended to be run with ninja -f build-<config>.ninja. This is due to the fact that it is possible for custom commands to produce the same file with different commands, based on the configuration. Ninja does not allow the same file to be generated with different commands, so these different commands have to live in separate build graphs.

The "simple" case of building a target with a desired configuration can be done by simply selecting the build-<config>.ninja file and entering the desired target name as normal. For example:

ninja -f build-debug.ninja tgt

This will build the Debug configuration of tgt.

It is possible to build a target of any configuration regardless of which build-<config>.ninja file you use simply by appending a :<config> suffix to the end of the target name. For example:

ninja -f build-release.ninja tgt:Debug

This will build the Debug configuration of tgt from the Release build graph. Note that when building in this manner, custom commands from the Release configuration will be used instead of the ones from the Debug configuration. This is useful for running the Release version of a source file generator program, rather than the Debug version, to get improved performance while still ultimately building the Debug configuration of the desired target.

TODO:

  • Unity build support
  • Precompile header support
  • Swift support
  • CUDA support
  • Multi-config packaging with cpack -C
  • Qt support (e.g. the <ORIGIN>_autogen output directory and associated include path handling)

Co-Authored-by: vector-of-bool vectorofbool@gmail.com

Edited by Craig Scott

Merge request reports