controlling ninja parallelism
Ninja also support the same parameter:
$ ninja --help
usage: ninja [options] [targets...]
[...]
options:
[...]
-j N run N jobs in parallel [default=10, derived from CPUs available]
[...]
controlling ninja parallelism differentiating compile
and link
jobs
Now, if you want more granularity. For example, if you would like to limit the number of simultaneous link jobs
, or compile jobs
, or both.
Starting with CMake 3.11, it is now possible to limit the number of compile
and/or link
jobs.
You could then configure your project with these options:
-DCMAKE_JOB_POOL_COMPILE:STRING=compile
-DCMAKE_JOB_POOL_LINK:STRING=link
'-DCMAKE_JOB_POOLS:STRING=compile=5;link=2'
Now, if your project end up spawning other child processed that are themselves building projects using ninja, you would have to:
use the fork of ninja that include Job Server support like it is done in make
. Binaries are also available in the associated GitHub releases. See https://github.com/kitware/ninja#readme
make sure sub-project are also configured with the same -DCMAKE_JOB_
options
in the context of externalNativeBuild
This means you could try something like this:
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_static -DCMAKE_JOB_POOL_COMPILE:STRING=compile -DCMAKE_JOB_POOL_LINK:STRING=link '-DCMAKE_JOB_POOLS:STRING=compile=5;link=2'"
abiFilters getAbis()
}
}
externalNativeBuild { cmake { arguments
section I got the following error:Error while executing process D:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build D:\...\.externalNativeBuild\cmake\fullDebug\arm64-v8a --target JniInterface} ninja: error: build.ninja:113: unknown pool name 'compile'
For the other solution. I know ninja can accept-j
parameter but I'm not running ninja directly and adding-Dj X
as an argument for cmake doesn't do anything... – Campestral