phribeiro
phribeiro

Reputation: 199

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

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?

Upvotes: 19

Views: 31283

Answers (2)

beeka
beeka

Reputation: 66

As previously answered, there is no practical difference in the way it is called. However one reason you might want to use cmake --build is as an abstraction of the build system: you can write a script to perform the build without knowing the tool specified / used to generate the build scripts.

Upvotes: 3

BZKN
BZKN

Reputation: 1719

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

Upvotes: 18

Related Questions