无论使用哪种构建工具,是否有可能以某种方式进行并行构建?
在 Unix 下,我们可以添加make -jN
其中 N 是线程数,在 Windows 下,我添加到CXX_FLAG "/MP"
其中,然后在 Visual Studio 中用于并行构建......(?)我怎样才能使我的版本CMAKE_MAKE_PROGRAM
不总是在我扩展时运行 CMake?
什么是通用解决方案?
我想出了这个:
# Add some multithreaded build support
MARK_AS_ADVANCED(MULTITHREADED_BUILD)
set(MULTITHREADED_BUILD 12 CACHE STRING "How many threads are used to build the project")
if(MULTITHREADED_BUILD)
if(${CMAKE_GENERATOR} MATCHES "Unix Makefiles")
message(STATUS ${CMAKE_BUILD_TOOL})
set(CMAKE_MAKE_PROGRAM "${CMAKE_MAKE_PROGRAM} -j${MULTITHREADED_BUILD}")
message(STATUS "Added arguments to CMAKE_BUILD_TOOL: ${CMAKE_MAKE_PROGRAM}")
elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
message(STATUS "Added parallel build arguments to CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
endif()
endif()