3 ms·
If you don't know it, CMake can use ninja instead of make for compilation so instead of "mkdir build && cd build && cmake .. && make" you can run "mkdir build &
by antoinealb 6y ago
If you don't know it, CMake can use ninja instead of make for compilation so instead of "mkdir build && cd build && cmake .. && make" you can run "mkdir build && cd build && cmake -GNinja && ninja".
It feels faster on my side projects (haven't benchmarked it really), but most importantly, when running a parallel build it does not interleave the output of the different steps, making it much easier to read warnings and errors.
- jart 6y agoIf anyone wants to know more about preventing interleaving, try using `make -O` or adding `GNUMAKEFLAGS += --output-sync` to the top of your Makefile.
- ihnorton 6y agoA small warning for code with many CMake ExternalProject dependencies: the defaults for cmake+ninja will recursively run `ninja -jN` for each level of the dependency tree, which can spawn a very large number of compile jobs. There is a proposal to add jobserver support for global process count management [1], but it has not been merged for philosophical reasons (IIRC). The CMake folks maintain a soft fork with this patch applied, available in the `ninja` package on PyPI and probably elsewhere. [1] https://github.com/ninja-build/ninja/issues/1139 https://github.com/ninja-build/ninja/issues/1139
- tomjakubowski 6y agoNinja is especially beneficial on large projects with lots of source files. Where Make can take 30+ seconds to run a "no-op" build, when nothing needs rebuilding, ninja does it instantly.
- kingosticks 6y agoThe conclusion at https://david.rothlis.net/ninja-benchmark/ https://david.rothlis.net/ninja-benchmark/ (2016) was that this doesn't have an impact until you get to really large projects (assuming you are able to utilise make -j).
- CUViper 6y agoYou can also use "cmake --build <dir>" to build regardless of which generator was used.
- maccard 6y agoFor cross platform-ness you can do cmake -H. -Bbuild -GNinja cd build && ninja