Reputation: 4925
This related question shows how to build a CMake project using a specified numbers of cores. For example if I wanted to use 10 cores, I could invoke CMake like this:
cmake --build . -j 10
My question is: how can I build using all my available cores. I effectively want CMake to autodetect my core count and use all of them.
Upvotes: 11
Views: 13390
Reputation: 19916
As of CMake 3.22, there is no standard way to do this. However, there are a few practical approaches.
Ninja
or Ninja Multi-Config
generators, on any platform, simply running the build with cmake --build /path/to/build-dir
will use all cores.cmake --build . -j $(nproc)
cmake --build . -j %NUMBER_OF_PROCESSORS%
Upvotes: 23