11

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?

starball
  • 20,030
  • 7
  • 43
  • 238
phribeiro
  • 119
  • 1
  • 1
  • 4
  • `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

14

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,499
  • 2
  • 10
  • 25
  • what would be the difference if the `-GNinja` option was not present? What's the advantage of using a builder like ninja, or using none? – carnicer Jul 04 '23 at 12:07