Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between invoking `ninja` directly vs through `cmake --build`

Tags:

cmake

ninja

Follow the commands:

First I do:

cmake -G Ninja ..

then:

cmake --build . -j10

or:

ninja -j10

What is the difference between them? Are there pros or cons between them?

like image 213
phribeiro Avatar asked Nov 23 '25 08:11

phribeiro


1 Answers

When you run cmake -G Ninja.. it essentially means that you are using a build system namely Ninja. For better understanding this visual depiction will further clarify. Furthermore, the Ninja in cmake -G Ninja.. will generate Ninja build files.

Regarding your question what is the difference between cmake --build . -j10 and ninja -j10?

Apparently there is no difference in your case as you have already run cmake -G Ninja .. previously. Both cmake --build . -j10 and ninja -j10 are fine in your case.

To further clarify, the -j means "number of jobs". And to put it more precisely, it is -jN. Where N explicitly sets "number of jobs" to run in parallel. This means your build will use 10 threads as you have -j10

like image 189
BZKN Avatar answered Nov 24 '25 22:11

BZKN