diff options
author | Brad King <brad.king@kitware.com> | 2018-02-20 16:44:51 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-02-20 16:44:59 (GMT) |
commit | 10f39ca7f7c9b2396101d4ebd7b5933276017b85 (patch) | |
tree | 8e79bcc90e4880a471aa7e66356624b4928f31f6 | |
parent | 3bc3762c7c54ba0280413b3782473e078e1b00c8 (diff) | |
parent | a1dee224b8f92a16a84ac285620136d04adb880a (diff) | |
download | CMake-10f39ca7f7c9b2396101d4ebd7b5933276017b85.zip CMake-10f39ca7f7c9b2396101d4ebd7b5933276017b85.tar.gz CMake-10f39ca7f7c9b2396101d4ebd7b5933276017b85.tar.bz2 |
Merge topic 'msvc-parallel-build-17696'
a1dee224 CMake: Enable /MP for MSVC toolchain
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1718
-rw-r--r-- | CompileFlags.cmake | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/CompileFlags.cmake b/CompileFlags.cmake index 32e7005..ec9b31b 100644 --- a/CompileFlags.cmake +++ b/CompileFlags.cmake @@ -82,3 +82,26 @@ endif () if (CMAKE_ANSI_CFLAGS) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}") endif () + +# Allow per-translation-unit parallel builds when using MSVC +if(CMAKE_GENERATOR MATCHES "Visual Studio" AND + (CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel" OR + CMAKE_CXX_COMPILER_ID MATCHES "MSVC|Intel")) + + set(CMake_MSVC_PARALLEL ON CACHE STRING "\ +Enables /MP flag for parallel builds using MSVC. Specify an \ +integer value to control the number of threads used (Only \ +works on some older versions of Visual Studio). Setting to \ +ON lets the toolchain decide how many threads to use. Set to \ +OFF to disable /MP completely." ) + + if(CMake_MSVC_PARALLEL) + if(CMake_MSVC_PARALLEL GREATER 0) + string(APPEND CMAKE_C_FLAGS " /MP${CMake_MSVC_PARALLEL}") + string(APPEND CMAKE_CXX_FLAGS " /MP${CMake_MSVC_PARALLEL}") + else() + string(APPEND CMAKE_C_FLAGS " /MP") + string(APPEND CMAKE_CXX_FLAGS " /MP") + endif() + endif() +endif() |