Set the number of threads in a CMake build

无人久伴 提交于 2020-06-24 03:47: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 to GNU make's -j option.


回答1:


According to the Release Notes, with CMake 3.12 it can be done cross-platform:

The cmake(1) Build Tool Mode (cmake –build) gained --parallel [<jobs>] and -j [<jobs>] options to specify a parallel build level. They map to corresponding options of the native build tool.




回答2:


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.



来源:https://stackoverflow.com/questions/36633074/set-the-number-of-threads-in-a-cmake-build

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!