CMake Build Parallel Configuration
Introduction
To use CMake to build a project, usually I will run the following commands brainlessly.
1 | $ cmake -B build |
However, it will use all the CPU threads to build the project. If the project is very large, sometimes it will consume all the CPU and memory resources on my local machine and make the system unresponsive or crash. Therefore, it is better to control the parallelism of the CMake build process.
In this blog post, I will discuss quickly how to control the parallelism of the CMake build process.
CMake Build Parallel Configuration
There are two ways to control the parallelism of the CMake build process.
One way is to set the number of jobs for the --parallel
option.
1 | $ export NUM_CMAKE_JOBS=4 |
The other way is to set the CMAKE_BUILD_PARALLEL_LEVEL
environment variable.
1 | $ export NUM_CMAKE_JOBS=4 |
References
CMake Build Parallel Configuration
https://leimao.github.io/blog/CMake-Build-Parallel-Configuration/