How to get the number of build jobs ?

Hi,

I can see that cmake --build . -j N and export CMAKE_BUILD_PARALLEL_LEVEL=N will pass this number to the generator.

Is there a way to get this number in a variable in a CMakeLists.txt or something ?

My current use case is that I have an ExternalProject_Add() with basically a BUILD_COMMAND containing a make, and I would like to add -jN there.

No; this is a build-time thing. If what you wanted were possible, CMake would need to reconfigure the project anytime ninja -jN is passed in case it is different.

One possible solution is something like this (follow where the variable is used). Note that there is infrastructure this is riding on, but you should be able to do this in your BUILD_COMMAND bits directly.