Merge pull request #16122 from alalek:cmake_update_cpu_compiler_detection

pull/16165/head
Alexander Alekhin 5 years ago
commit 43302c79ca
  1. 2
      cmake/OpenCVCompilerOptimizations.cmake
  2. 81
      cmake/OpenCVDetectCXXCompiler.cmake
  3. 7
      cmake/OpenCVFindIPP.cmake
  4. 2
      cmake/OpenCVFindLibsVideo.cmake
  5. 2
      cmake/OpenCVFindOpenEXR.cmake
  6. 4
      cmake/OpenCVFindOpenNI.cmake
  7. 2
      cmake/OpenCVFindOpenNI2.cmake
  8. 24
      cmake/OpenCVUtils.cmake
  9. 30
      cmake/templates/OpenCVConfig.root-WIN32.cmake.in
  10. 4
      modules/videoio/CMakeLists.txt

@ -288,7 +288,7 @@ if(X86 OR X86_64)
ocv_update(CPU_AVX2_FLAGS_ON "/arch:AVX2")
ocv_update(CPU_AVX_FLAGS_ON "/arch:AVX")
ocv_update(CPU_FP16_FLAGS_ON "/arch:AVX")
if(NOT MSVC64)
if(NOT X86_64)
# 64-bit MSVC compiler uses SSE/SSE2 by default
ocv_update(CPU_SSE_FLAGS_ON "/arch:SSE")
ocv_update(CPU_SSE_SUPPORTED ON)

@ -3,15 +3,14 @@
# - CV_CLANG - Clang-compatible compiler (CMAKE_CXX_COMPILER_ID MATCHES "Clang" - Clang or AppleClang, see CMP0025)
# - CV_ICC - Intel compiler
# - MSVC - Microsoft Visual Compiler (CMake variable)
# - MSVC64 - additional flag, 64-bit
# - MINGW / CYGWIN / CMAKE_COMPILER_IS_MINGW / CMAKE_COMPILER_IS_CYGWIN (CMake original variables)
# - MINGW64 - 64-bit
#
# CPU Platforms:
# - X86 / X86_64
# - ARM - ARM CPU, not defined for AArch64
# - AARCH64 - ARMv8+ (64-bit)
# - PPC64 / PPC64LE - PowerPC
# - MIPS
#
# OS:
# - WIN32 - Windows | MINGW
@ -21,9 +20,8 @@
# - APPLE - MacOSX | iOS
# ----------------------------------------------------------------------------
if(CMAKE_CL_64)
set(MSVC64 1)
endif()
ocv_declare_removed_variables(MINGW64 MSVC64)
# do not use (CMake variables): CMAKE_CL_64
if(NOT DEFINED CV_GCC AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CV_GCC 1)
@ -51,7 +49,7 @@ variable_watch(CMAKE_COMPILER_IS_CLANGCC access_CMAKE_COMPILER_IS_CLANGCXX)
# Detect Intel ICC compiler
# ----------------------------------------------------------------------------
if(UNIX)
if (__ICL)
if(__ICL)
set(CV_ICC __ICL)
elseif(__ICC)
set(CV_ICC __ICC)
@ -70,53 +68,65 @@ if(MSVC AND CMAKE_C_COMPILER MATCHES "icc|icl")
set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS)
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER_VERSION)
message(WARNING "Compiler version is not available: CMAKE_CXX_COMPILER_VERSION is not set")
if(NOT DEFINED CMAKE_CXX_COMPILER_VERSION
AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_COMPILER_VERSION)
message(WARNING "OpenCV: Compiler version is not available: CMAKE_CXX_COMPILER_VERSION is not set")
endif()
if(WIN32 AND CV_GCC)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(OPENCV_GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64")
set(MINGW64 1)
endif()
if((NOT DEFINED CMAKE_SYSTEM_PROCESSOR OR CMAKE_SYSTEM_PROCESSOR STREQUAL "")
AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_CMAKE_SYSTEM_PROCESSOR)
message(WARNING "OpenCV: CMAKE_SYSTEM_PROCESSOR is not defined. Perhaps CMake toolchain is broken")
endif()
if(NOT DEFINED CMAKE_SIZEOF_VOID_P
AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_CMAKE_SIZEOF_VOID_P)
message(WARNING "OpenCV: CMAKE_SIZEOF_VOID_P is not defined. Perhaps CMake toolchain is broken")
endif()
message(STATUS "Detected processor: ${CMAKE_SYSTEM_PROCESSOR}")
if(MSVC64 OR MINGW64)
set(X86_64 1)
elseif(MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING))
set(X86 1)
if(OPENCV_SKIP_SYSTEM_PROCESSOR_DETECTION)
# custom setup: required variables are passed through cache / CMake's command-line
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
set(X86_64 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*|amd64.*|AMD64.*")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*")
set(X86 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)")
set(AARCH64 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
set(ARM 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
set(AARCH64 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le")
set(PPC64LE 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
set(PPC64 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(mips.*|MIPS.*)")
set(MIPS 1)
else()
if(NOT OPENCV_SUPPRESS_MESSAGE_UNRECOGNIZED_SYSTEM_PROCESSOR)
message(WARNING "OpenCV: unrecognized target processor configuration")
endif()
endif()
# Workaround for 32-bit operating systems on x86_64/aarch64 processor
if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT FORCE_X86_64)
# Workaround for 32-bit operating systems on x86_64
if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND X86_64
AND NOT FORCE_X86_64 # deprecated (2019-12)
AND NOT OPENCV_FORCE_X86_64
)
message(STATUS "sizeof(void) = 4 on 64 bit processor. Assume 32-bit compilation mode")
if (X86_64)
if(X86_64)
unset(X86_64)
set(X86 1)
endif()
if (AARCH64)
endif()
# Workaround for 32-bit operating systems on aarch64 processor
if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND AARCH64
AND NOT OPENCV_FORCE_AARCH64
)
message(STATUS "sizeof(void) = 4 on 64 bit processor. Assume 32-bit compilation mode")
if(AARCH64)
unset(AARCH64)
set(ARM 1)
endif()
endif()
# Similar code exists in OpenCVConfig.cmake
if(NOT DEFINED OpenCV_STATIC)
# look for global setting
@ -130,14 +140,19 @@ endif()
if(DEFINED OpenCV_ARCH AND DEFINED OpenCV_RUNTIME)
# custom overridden values
elseif(MSVC)
if(CMAKE_CL_64)
set(OpenCV_ARCH x64)
elseif((CMAKE_GENERATOR MATCHES "ARM") OR ("${arch_hint}" STREQUAL "ARM") OR (CMAKE_VS_EFFECTIVE_PLATFORMS MATCHES "ARM|arm"))
# see Modules/CmakeGenericSystem.cmake
set(OpenCV_ARCH ARM)
# see Modules/CMakeGenericSystem.cmake
if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
set(arch_hint "x64")
elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64")
set(arch_hint "ARM64")
elseif("${CMAKE_GENERATOR}" MATCHES "ARM")
set(arch_hint "ARM")
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
set(arch_hint "x64")
else()
set(OpenCV_ARCH x86)
endif()
if(MSVC_VERSION EQUAL 1400)
set(OpenCV_RUNTIME vc8)
elseif(MSVC_VERSION EQUAL 1500)
@ -160,7 +175,7 @@ elseif(MSVC)
elseif(MINGW)
set(OpenCV_RUNTIME mingw)
if(MINGW64)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
set(OpenCV_ARCH x64)
else()
set(OpenCV_ARCH x86)

@ -40,11 +40,8 @@ if (X86 AND UNIX AND NOT APPLE AND NOT ANDROID AND BUILD_SHARED_LIBS)
endif()
set(IPP_X64 0)
if(CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
set(IPP_X64 1)
endif()
if(CMAKE_CL_64)
set(IPP_X64 1)
if(X86_64)
set(IPP_X64 1)
endif()
# This function detects Intel IPP version by analyzing .h file

@ -289,7 +289,7 @@ if(WIN32)
if(HAVE_VFW)
list(APPEND VIDEOIO_LIBRARIES vfw32)
endif()
if(MINGW64)
if(MINGW AND CMAKE_SIZEOF_VOID_P EQUAL 8)
list(APPEND VIDEOIO_LIBRARIES avifil32 avicap32 winmm msvfw32)
list(REMOVE_ITEM VIDEOIO_LIBRARIES vfw32)
elseif(MINGW)

@ -15,7 +15,7 @@ file(TO_CMAKE_PATH "$ENV{ProgramFiles}" ProgramFiles_ENV_PATH)
if(WIN32)
SET(OPENEXR_ROOT "C:/Deploy" CACHE STRING "Path to the OpenEXR \"Deploy\" folder")
if(CMAKE_CL_64)
if(X86_64)
SET(OPENEXR_LIBSEARCH_SUFFIXES x64/Release x64 x64/Debug)
elseif(MSVC)
SET(OPENEXR_LIBSEARCH_SUFFIXES Win32/Release Win32 Win32/Debug)

@ -18,7 +18,7 @@ if(NOT "${OPENNI_PRIME_SENSOR_MODULE_BIN_DIR}" STREQUAL "${OPENNI_PRIME_SENSOR_M
endif()
if(WIN32)
if(NOT (MSVC64 OR MINGW64))
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
find_file(OPENNI_INCLUDES "XnCppWrapper.h" PATHS "$ENV{OPEN_NI_INSTALL_PATH}Include" DOC "OpenNI c++ interface header")
find_library(OPENNI_LIBRARY "OpenNI" PATHS $ENV{OPEN_NI_LIB} DOC "OpenNI library")
else()
@ -34,7 +34,7 @@ if(OPENNI_LIBRARY AND OPENNI_INCLUDES)
set(HAVE_OPENNI TRUE)
# the check: are PrimeSensor Modules for OpenNI installed
if(WIN32)
if(NOT (MSVC64 OR MINGW64))
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
find_file(OPENNI_PRIME_SENSOR_MODULE "XnCore.dll" PATHS "$ENV{OPEN_NI_INSTALL_PATH}../PrimeSense/Sensor/Bin" "$ENV{OPEN_NI_INSTALL_PATH}../PrimeSense/SensorKinect/Bin" DOC "Core library of PrimeSensor Modules for OpenNI")
else()
find_file(OPENNI_PRIME_SENSOR_MODULE "XnCore64.dll" PATHS "$ENV{OPEN_NI_INSTALL_PATH64}../PrimeSense/Sensor/Bin64" "$ENV{OPEN_NI_INSTALL_PATH64}../PrimeSense/SensorKinect/Bin64" DOC "Core library of PrimeSensor Modules for OpenNI")

@ -13,7 +13,7 @@ if(NOT "${OPENNI2_INCLUDE_DIR}" STREQUAL "${OPENNI2_INCLUDE_DIR_INTERNAL}")
endif()
if(WIN32)
if(NOT (MSVC64 OR MINGW64))
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
find_file(OPENNI2_INCLUDES "OpenNI.h" PATHS $ENV{OPENNI2_INCLUDE} "$ENV{OPEN_NI_INSTALL_PATH}Include" DOC "OpenNI2 c++ interface header")
find_library(OPENNI2_LIBRARY "OpenNI2" PATHS $ENV{OPENNI2_LIB} DOC "OpenNI2 library")
else()

@ -100,6 +100,30 @@ macro(ocv_update VAR)
endif()
endmacro()
function(_ocv_access_removed_variable VAR ACCESS)
if(ACCESS STREQUAL "MODIFIED_ACCESS")
set(OPENCV_SUPPRESS_MESSAGE_REMOVED_VARIABLE_${VAR} 1 PARENT_SCOPE)
return()
endif()
if(ACCESS MATCHES "UNKNOWN_.*"
AND NOT OPENCV_SUPPRESS_MESSAGE_REMOVED_VARIABLE
AND NOT OPENCV_SUPPRESS_MESSAGE_REMOVED_VARIABLE_${VAR}
)
message(WARNING "OpenCV: Variable has been removed from CMake scripts: ${VAR}")
set(OPENCV_SUPPRESS_MESSAGE_REMOVED_VARIABLE_${VAR} 1 PARENT_SCOPE) # suppress similar messages
endif()
endfunction()
macro(ocv_declare_removed_variable VAR)
if(NOT DEFINED ${VAR}) # don't hit external variables
variable_watch(${VAR} _ocv_access_removed_variable)
endif()
endmacro()
macro(ocv_declare_removed_variables)
foreach(_var ${ARGN})
ocv_declare_removed_variable(${_var})
endforeach()
endmacro()
# Search packages for the host system instead of packages for the target system
# in case of cross compilation these macros should be defined by the toolchain file
if(NOT COMMAND find_host_package)

@ -84,17 +84,31 @@ endfunction()
get_filename_component(OpenCV_CONFIG_PATH "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
if((NOT DEFINED CMAKE_SYSTEM_PROCESSOR OR CMAKE_SYSTEM_PROCESSOR STREQUAL "")
AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_CMAKE_SYSTEM_PROCESSOR)
message(WARNING "OpenCV: CMAKE_SYSTEM_PROCESSOR is not defined. Perhaps CMake toolchain is broken")
endif()
if(NOT DEFINED CMAKE_SIZEOF_VOID_P
AND NOT OPENCV_SUPPRESS_MESSAGE_MISSING_CMAKE_SIZEOF_VOID_P)
message(WARNING "OpenCV: CMAKE_SIZEOF_VOID_P is not defined. Perhaps CMake toolchain is broken")
endif()
if(DEFINED OpenCV_ARCH AND DEFINED OpenCV_RUNTIME)
# custom overridden values
elseif(MSVC)
if(CMAKE_CL_64)
set(OpenCV_ARCH x64)
elseif((CMAKE_GENERATOR MATCHES "ARM") OR ("${arch_hint}" STREQUAL "ARM") OR (CMAKE_VS_EFFECTIVE_PLATFORMS MATCHES "ARM|arm"))
# see Modules/CmakeGenericSystem.cmake
set(OpenCV_ARCH ARM)
# see Modules/CMakeGenericSystem.cmake
if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
set(arch_hint "x64")
elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64")
set(arch_hint "ARM64")
elseif("${CMAKE_GENERATOR}" MATCHES "ARM")
set(arch_hint "ARM")
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
set(arch_hint "x64")
else()
set(OpenCV_ARCH x86)
endif()
if(MSVC_VERSION EQUAL 1400)
set(OpenCV_RUNTIME vc8)
elseif(MSVC_VERSION EQUAL 1500)
@ -127,11 +141,7 @@ elseif(MSVC)
elseif(MINGW)
set(OpenCV_RUNTIME mingw)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(OPENCV_GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64")
set(MINGW64 1)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
set(OpenCV_ARCH x64)
else()
set(OpenCV_ARCH x86)

@ -80,7 +80,7 @@ endif()
if (WIN32 AND HAVE_DSHOW)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_dshow.cpp)
list(APPEND videoio_hdrs ${CMAKE_CURRENT_LIST_DIR}/src/cap_dshow.hpp)
if (MINGW64)
if(MINGW AND X86_64)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTRSAFE_NO_DEPRECATE")
endif()
endif()
@ -267,7 +267,7 @@ ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-deprecated-declarations)
if(WIN32 AND HAVE_FFMPEG_WRAPPER)
#copy ffmpeg dll to the output folder
if(MSVC64 OR MINGW64)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(FFMPEG_SUFFIX _64)
endif()

Loading…
Cancel
Save