Merge pull request #16559 from alalek:cmake_msvc_mp_customize

pull/16580/head
Alexander Alekhin 5 years ago
commit c41f50f5f7
  1. 9
      cmake/OpenCVCRTLinkage.cmake
  2. 35
      cmake/OpenCVCompilerOptions.cmake

@ -64,12 +64,3 @@ else()
endif()
endforeach(flag_var)
endif()
if(CMAKE_VERSION VERSION_GREATER "2.8.6")
include(ProcessorCount)
ProcessorCount(N)
if(NOT N EQUAL 0)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP${N} ")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP${N} ")
endif()
endif()

@ -442,3 +442,38 @@ if(OPENCV_EXTRA_RPATH_LINK_PATH)
message(WARNING "OPENCV_EXTRA_RPATH_LINK_PATH may not work properly because CMAKE_EXECUTABLE_RPATH_LINK_CXX_FLAG is not defined (not supported)")
endif()
endif()
# Control MSVC /MP flag
# Input variables: OPENCV_MSVC_PARALLEL (ON,1,2,3,...) + OPENCV_SKIP_MSVC_PARALLEL
# Details:
# - https://docs.microsoft.com/en-us/cpp/build/reference/mp-build-with-multiple-processes
# - https://docs.microsoft.com/en-us/cpp/build/reference/cl-environment-variables
# - https://gitlab.kitware.com/cmake/cmake/merge_requests/1718/diffs
if(CMAKE_GENERATOR MATCHES "Visual Studio" AND CMAKE_CXX_COMPILER_ID MATCHES "MSVC|Intel")
ocv_check_environment_variables(OPENCV_SKIP_MSVC_PARALLEL)
if(OPENCV_SKIP_MSVC_PARALLEL)
# nothing
elseif(" ${CMAKE_CXX_FLAGS}" MATCHES "/MP")
# nothing, already defined in compiler flags
elseif(DEFINED ENV{CL} AND " $ENV{CL}" MATCHES "/MP")
# nothing, compiler will use CL environment variable
elseif(DEFINED ENV{_CL_} AND " $ENV{_CL_}" MATCHES "/MP")
# nothing, compiler will use _CL_ environment variable
else()
ocv_check_environment_variables(OPENCV_MSVC_PARALLEL)
set(_mp_value "ON")
if(DEFINED OPENCV_MSVC_PARALLEL)
set(_mp_value "${OPENCV_MSVC_PARALLEL}")
endif()
set(OPENCV_MSVC_PARALLEL "${_mp_value}" CACHE STRING "Control MSVC /MP flag")
if(_mp_value)
if(_mp_value GREATER 0)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP${_mp_value}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP${_mp_value}")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()
endif()
endif()
endif()

Loading…
Cancel
Save