From bc4244e0990af31ff326a72e2152fed662fca3e9 Mon Sep 17 00:00:00 2001 From: ruevs Date: Sat, 9 Jul 2022 00:11:24 +0300 Subject: [PATCH] Win32, MSVC: Enable Multi-processor Compilation (/MP) with Visual Studio Makes compiling from the Visual Studio IDE much faster when using the solution and projects generated by cmake. For the externals I hijack the `disable_warnings` function. --- CMakeLists.txt | 4 ++++ cmake/DisableWarnings.cmake | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d50a1f4a..8dd29d06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -377,6 +377,10 @@ if(MSVC) # Same for the (C99) __func__ special variable; we use it only in C++ code. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D__func__=__FUNCTION__") + # Multi-processor Compilation + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") + # We rely on these /we flags. They correspond to the GNU-style flags below as # follows: /w4062=-Wswitch set(WARNING_FLAGS "${WARNING_FLAGS} /we4062") diff --git a/cmake/DisableWarnings.cmake b/cmake/DisableWarnings.cmake index b79ef9cd..34925c80 100644 --- a/cmake/DisableWarnings.cmake +++ b/cmake/DisableWarnings.cmake @@ -4,12 +4,12 @@ function(disable_warnings) if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w" PARENT_SCOPE) elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0" PARENT_SCOPE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0 /MP" PARENT_SCOPE) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w" PARENT_SCOPE) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0" PARENT_SCOPE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0 /MP" PARENT_SCOPE) endif() endfunction()