1

Follow the commands:

First I do cmake -G Ninja ..

then

cmake --build . -j10

or

ninja -j10

My question is, what is the best command or the difference between then?

phribeiro
  • 11
  • 2
  • `cmake --build` just calls `ninja` for you – Alan Birtles Jan 25 '22 at 20:19
  • cmake is a build system; you define how your project should be put together. It *can* create `ninja.build` files for you. Ninja will do the building. `cmake --build` just calls the builder for you. This should have been explained. – sweenish Jan 25 '22 at 20:36
  • `cmake --build . -j10` will build with 10 threads using whatever project type / build method is enabled by the generator setting that was set on the cmake -G – drescherjm Jan 25 '22 at 20:41
  • ***what is the best command*** It does not really matter in your case however `ninja -j10` is less characters to type.. – drescherjm Jan 25 '22 at 20:42

1 Answers1

6

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

BZKN
  • 1,267
  • 1
  • 8
  • 23