summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2018-02-20 16:44:51 (GMT)
committerKitware Robot <kwrobot@kitware.com>2018-02-20 16:44:59 (GMT)
commit10f39ca7f7c9b2396101d4ebd7b5933276017b85 (patch)
tree8e79bcc90e4880a471aa7e66356624b4928f31f6
parent3bc3762c7c54ba0280413b3782473e078e1b00c8 (diff)
parenta1dee224b8f92a16a84ac285620136d04adb880a (diff)
downloadCMake-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.cmake23
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()