Set the number of threads in a CMake build

后端 未结 2 1771
忘了有多久
忘了有多久 2021-02-01 01:13
cmake --build . --config Release

Is it possible to set the number of cores to be used by the build process?

I\'m looking for something similar

2条回答
  •  臣服心动
    2021-02-01 01:34

    You can pass arbitrary arguments to the native build tool with --. Everything after -- will be passed to the build tool. To pass -j 3 in your example, just use

    cmake --build . --config Release -- -j 3
    

    Documentation: https://cmake.org/cmake/help/v3.5/manual/cmake.1.html

    You could also use Ninja as a build tool, it uses automatically an appropriate number of threads. Or you can modify the make command by defining CMAKE_MAKE_PROGRAM="make -j 3. But this is a rather hacky workaround.

提交回复
热议问题