Skip to content

ninja build

Fabian Wein edited this page Dec 1, 2022 · 2 revisions

back to home

Ninja is an alternative to gnu make focused on speed (https://ninja-build.org/). Especially incremental builds are much faster (factor 2 to 10). CMake supports the generation of build files *.ninja by a built-in generator (https://cmake.org/cmake/help/v3.7/generator/Ninja.html). For Fortran support one currently must use Kitware's ninja branch (https://github.com/Kitware/ninja).

Usage

  1. Create a new build directory (cmake cannot mix different generators)
  2. Configure as usual but use the Ninja generator. For ccmake configure (c) as often up to you can generate (g). A single cmake is sufficient but has no the possibility to check and set options. cmake -G Ninja /path/to/cfs/source; cmake .; cmake .
  3. Build using ninja, for first builds start with the cfsdeps and use a single thread ninja [-j1] cfsdeps.
  4. To create an Eclipse project use cmake -G "Eclipse CDT4 - Ninja" .

Ninja uses multiple threads by default. For the first build one should use only one thread, i.e. the option -j1, to ensure the correct order of cfsdeps.

Development

To get ninja to work the following changes were necessary, see [15661].

  • the libraries of CFSDEPS must be specified by BUILD_BYPRODUCTS in the ExternalProject_Add call so that ninja can determin the correct build order (https://cmake.org/pipermail/cmake/2015-April/060234.html)
  • The setting of 'dependency_LIBRARY' was moved in front of ExternalProject_Add in order to include it afterwards
  • CFSDEPS not using CMake, e.g. GMP & MPFR must still be configured and built with make. The external call is adapted when the genator is set to Ninja
  • for custom targets (ADD_CUSTOM_TARGET) one can add BYPRODUCTS to tell ninja what the command should generate (https://cmake.org/cmake/help/v3.7/command/add_custom_target.html). If you specify USES_TERMINAL ninja will print COMMENT

Clone this wiki locally