JOB_POOLS vs ninja jobs flag arg?

How is JOB_POOL_COMPILE and JOB_POOL_LINK different from -j flag passed to ninja on command line?

The -j flag tells ninja the maximum number of jobs to allow. Pools limit build rules annotated with them to that number at once. So with a pool size of 3 and -j2, the pool doesn’t do much because, at most, 2 jobs are running anyways. With -j5, you ensure that no more than 3 jobs that share that pool are running at a time. CMake gives you per-target controls for how to manage its compile and link jobs.

Common use cases:

  • in a static build, put all executables into a single pool of size 1 (since linking tends to be memory-intensive)
  • for CUDA or other memory-intensive compiles, put them all into one pool with a size calculated based on total memory dividing by the expected per-TU usage

So effectively the number of jobs is limited by the smallest of JOB_POOL_COMPILE and -j flag?

On command line I can specify both jobs and limit, e.g. ninja -j0 -l14, anything similar to l flag here too?

No, the -l flag is for “load average” and basically says “don’t spawn new jobs if the machine is ‘too busy’”. There is no pool mechanism for load average in ninja itself, so CMake would have no way to do anything there.