Use ninja with cmake
Nowdays it is very common for C/C++ projects use cmake as the build tool, or at least will support cmake.
Then the easy command to build the project will be like:
cd project \
&& mkdir build \
&& cd build \
&& cmake .. \
&& make
As I wrote in the previous article, if you want to make build fast you should set more jobs, like:
make $(nproc)
Or you can use another build tool, ninja
, which use the the number of processors as the default job number, like:
cd project \
&& mkdir build \
&& cd build \
&& cmake -GNinja .. \
&& ninja
Here are several advantages for ninja:
- Use the default number of process as the job number
- No annoying output on standard output if no error or waning
- More fast than make especially for large projects and for no change build
- And for parallel jobs, the output is buffered, and will not mixed with other job
But a very disadvantages for ninja is that you can't write the ninja makefile like the common makefile, the beset way is to use a generator, like cmake.
If you like the build tool only works well and won't complain under normal case ninja is a good choice.