CMake build parallel
CMake environment variable CMAKE_BUILD_PARALLEL_LEVEL can be manually set to control default number of build parallel threads. Parallel builds are virtually always desired to save build and rebuild time. As a starting point, perhaps set CMAKE_BUILD_PARALLEL_LEVEL environment variable to be equal to the number of physical or logical CPU cores by setting it in the user profile:
#!/bin/bash
if [[ x"${CMAKE_BUILD_PARALLEL_LEVEL}" == x ]]; then
n=8;
case "$OSTYPE" in
linux*)
n=$(nproc);;
darwin*)
n=$(sysctl -n hw.physicalcpu);;
bsd*)
n=$(sysctl -n hw.ncpu);;
esac
export CMAKE_BUILD_PARALLEL_LEVEL=${n}
fi
Or for Windows, in environment variable settings:
CMAKE_BUILD_PARALLEL_LEVEL=%NUMBER_OF_PROCESSORS%
If the computer runs out of RAM, reduce the specific command parallelism with the cmake --build --parallel N
command line option.
For Ninja build systems, specific targets can control the number of workers with
job pools.