2018-03-26 19:30:49 +08:00
|
|
|
# Compilers:
|
|
|
|
# - CV_GCC - GNU compiler (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
# - 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)
|
|
|
|
# - MINGW / CYGWIN / CMAKE_COMPILER_IS_MINGW / CMAKE_COMPILER_IS_CYGWIN (CMake original variables)
|
|
|
|
#
|
|
|
|
# CPU Platforms:
|
|
|
|
# - X86 / X86_64
|
|
|
|
# - ARM - ARM CPU, not defined for AArch64
|
|
|
|
# - AARCH64 - ARMv8+ (64-bit)
|
|
|
|
# - PPC64 / PPC64LE - PowerPC
|
2019-12-11 06:35:36 +08:00
|
|
|
# - MIPS
|
2018-03-26 19:30:49 +08:00
|
|
|
#
|
|
|
|
# OS:
|
|
|
|
# - WIN32 - Windows | MINGW
|
|
|
|
# - UNIX - Linux | MacOSX | ANDROID
|
|
|
|
# - ANDROID
|
|
|
|
# - IOS
|
|
|
|
# - APPLE - MacOSX | iOS
|
2012-02-03 19:26:49 +08:00
|
|
|
# ----------------------------------------------------------------------------
|
2018-03-26 19:30:49 +08:00
|
|
|
|
2019-12-11 06:35:36 +08:00
|
|
|
ocv_declare_removed_variables(MINGW64 MSVC64)
|
|
|
|
# do not use (CMake variables): CMAKE_CL_64
|
2012-02-03 19:26:49 +08:00
|
|
|
|
2018-03-26 19:30:49 +08:00
|
|
|
if(NOT DEFINED CV_GCC AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|
|
|
set(CV_GCC 1)
|
2013-03-01 16:17:05 +08:00
|
|
|
endif()
|
2018-03-26 19:30:49 +08:00
|
|
|
if(NOT DEFINED CV_CLANG AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Clang or AppleClang (see CMP0025)
|
|
|
|
set(CV_CLANG 1)
|
|
|
|
set(CMAKE_COMPILER_IS_CLANGCXX 1) # TODO next release: remove this
|
|
|
|
set(CMAKE_COMPILER_IS_CLANGCC 1) # TODO next release: remove this
|
2015-07-28 23:32:41 +08:00
|
|
|
endif()
|
2013-03-01 16:17:05 +08:00
|
|
|
|
2018-03-26 19:30:49 +08:00
|
|
|
function(access_CMAKE_COMPILER_IS_CLANGCXX)
|
|
|
|
if(NOT OPENCV_SUPPRESS_DEPRECATIONS)
|
|
|
|
message(WARNING "DEPRECATED: CMAKE_COMPILER_IS_CLANGCXX support is deprecated in OpenCV.
|
|
|
|
Consider using:
|
|
|
|
- CV_GCC # GCC
|
|
|
|
- CV_CLANG # Clang or AppleClang (see CMP0025)
|
|
|
|
")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
variable_watch(CMAKE_COMPILER_IS_CLANGCXX access_CMAKE_COMPILER_IS_CLANGCXX)
|
|
|
|
variable_watch(CMAKE_COMPILER_IS_CLANGCC access_CMAKE_COMPILER_IS_CLANGCXX)
|
|
|
|
|
|
|
|
|
2012-02-03 19:26:49 +08:00
|
|
|
# ----------------------------------------------------------------------------
|
2018-03-26 19:30:49 +08:00
|
|
|
# Detect Intel ICC compiler
|
2012-02-03 19:26:49 +08:00
|
|
|
# ----------------------------------------------------------------------------
|
|
|
|
if(UNIX)
|
2019-12-11 06:35:36 +08:00
|
|
|
if(__ICL)
|
2013-04-07 00:11:40 +08:00
|
|
|
set(CV_ICC __ICL)
|
|
|
|
elseif(__ICC)
|
|
|
|
set(CV_ICC __ICC)
|
|
|
|
elseif(__ECL)
|
|
|
|
set(CV_ICC __ECL)
|
|
|
|
elseif(__ECC)
|
|
|
|
set(CV_ICC __ECC)
|
|
|
|
elseif(__INTEL_COMPILER)
|
|
|
|
set(CV_ICC __INTEL_COMPILER)
|
|
|
|
elseif(CMAKE_C_COMPILER MATCHES "icc")
|
|
|
|
set(CV_ICC icc_matches_c_compiler)
|
|
|
|
endif()
|
2012-02-03 19:26:49 +08:00
|
|
|
endif()
|
|
|
|
|
2016-12-01 21:41:21 +08:00
|
|
|
if(MSVC AND CMAKE_C_COMPILER MATCHES "icc|icl")
|
2013-04-07 00:11:40 +08:00
|
|
|
set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS)
|
2012-02-03 19:26:49 +08:00
|
|
|
endif()
|
|
|
|
|
2019-12-11 06:35:36 +08:00
|
|
|
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")
|
2017-08-21 22:43:56 +08:00
|
|
|
endif()
|
2019-12-11 06:35:36 +08:00
|
|
|
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")
|
2012-02-03 19:26:49 +08:00
|
|
|
endif()
|
|
|
|
|
2019-06-28 06:17:26 +08:00
|
|
|
message(STATUS "Detected processor: ${CMAKE_SYSTEM_PROCESSOR}")
|
2019-12-11 06:35:36 +08:00
|
|
|
if(OPENCV_SKIP_SYSTEM_PROCESSOR_DETECTION)
|
|
|
|
# custom setup: required variables are passed through cache / CMake's command-line
|
2013-04-07 00:11:40 +08:00
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
|
|
|
|
set(X86_64 1)
|
2019-12-11 06:35:36 +08:00
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*")
|
2013-04-07 00:11:40 +08:00
|
|
|
set(X86 1)
|
2019-12-11 06:35:36 +08:00
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)")
|
|
|
|
set(AARCH64 1)
|
2015-02-26 17:53:37 +08:00
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
|
2013-04-07 00:11:40 +08:00
|
|
|
set(ARM 1)
|
2017-12-15 10:47:52 +08:00
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le")
|
2017-10-03 06:54:31 +08:00
|
|
|
set(PPC64LE 1)
|
2017-12-15 10:47:52 +08:00
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
|
|
|
|
set(PPC64 1)
|
2019-09-21 00:52:48 +08:00
|
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(mips.*|MIPS.*)")
|
|
|
|
set(MIPS 1)
|
2019-12-11 06:35:36 +08:00
|
|
|
else()
|
|
|
|
if(NOT OPENCV_SUPPRESS_MESSAGE_UNRECOGNIZED_SYSTEM_PROCESSOR)
|
|
|
|
message(WARNING "OpenCV: unrecognized target processor configuration")
|
|
|
|
endif()
|
2012-02-03 19:26:49 +08:00
|
|
|
endif()
|
2013-08-07 16:53:48 +08:00
|
|
|
|
2019-12-11 06:35:36 +08:00
|
|
|
# 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
|
|
|
|
)
|
2019-06-28 06:17:26 +08:00
|
|
|
message(STATUS "sizeof(void) = 4 on 64 bit processor. Assume 32-bit compilation mode")
|
2019-12-11 06:35:36 +08:00
|
|
|
if(X86_64)
|
2019-06-28 06:17:26 +08:00
|
|
|
unset(X86_64)
|
|
|
|
set(X86 1)
|
|
|
|
endif()
|
2019-12-11 06:35:36 +08:00
|
|
|
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)
|
2019-06-28 06:17:26 +08:00
|
|
|
unset(AARCH64)
|
|
|
|
set(ARM 1)
|
|
|
|
endif()
|
2015-10-07 01:42:21 +08:00
|
|
|
endif()
|
2013-08-07 16:53:48 +08:00
|
|
|
|
2019-12-11 06:35:36 +08:00
|
|
|
|
2015-04-07 16:08:21 +08:00
|
|
|
# Similar code exists in OpenCVConfig.cmake
|
2013-08-07 16:53:48 +08:00
|
|
|
if(NOT DEFINED OpenCV_STATIC)
|
|
|
|
# look for global setting
|
|
|
|
if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
|
|
|
|
set(OpenCV_STATIC OFF)
|
|
|
|
else()
|
|
|
|
set(OpenCV_STATIC ON)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-11-07 18:55:13 +08:00
|
|
|
if(DEFINED OpenCV_ARCH AND DEFINED OpenCV_RUNTIME)
|
2018-02-07 19:59:15 +08:00
|
|
|
# custom overridden values
|
2017-11-07 18:55:13 +08:00
|
|
|
elseif(MSVC)
|
2019-12-11 06:35:36 +08:00
|
|
|
# see Modules/CMakeGenericSystem.cmake
|
|
|
|
if("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)")
|
2019-12-14 23:02:43 +08:00
|
|
|
set(OpenCV_ARCH "x64")
|
2019-12-11 06:35:36 +08:00
|
|
|
elseif("${CMAKE_GENERATOR_PLATFORM}" MATCHES "ARM64")
|
2019-12-14 23:02:43 +08:00
|
|
|
set(OpenCV_ARCH "ARM64")
|
2019-12-11 06:35:36 +08:00
|
|
|
elseif("${CMAKE_GENERATOR}" MATCHES "ARM")
|
2019-12-14 23:02:43 +08:00
|
|
|
set(OpenCV_ARCH "ARM")
|
2019-12-11 06:35:36 +08:00
|
|
|
elseif("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
|
2019-12-14 23:02:43 +08:00
|
|
|
set(OpenCV_ARCH "x64")
|
2013-08-07 16:53:48 +08:00
|
|
|
else()
|
|
|
|
set(OpenCV_ARCH x86)
|
|
|
|
endif()
|
2019-12-11 06:35:36 +08:00
|
|
|
|
2013-08-07 16:53:48 +08:00
|
|
|
if(MSVC_VERSION EQUAL 1400)
|
|
|
|
set(OpenCV_RUNTIME vc8)
|
|
|
|
elseif(MSVC_VERSION EQUAL 1500)
|
|
|
|
set(OpenCV_RUNTIME vc9)
|
|
|
|
elseif(MSVC_VERSION EQUAL 1600)
|
|
|
|
set(OpenCV_RUNTIME vc10)
|
|
|
|
elseif(MSVC_VERSION EQUAL 1700)
|
|
|
|
set(OpenCV_RUNTIME vc11)
|
2013-11-18 23:39:39 +08:00
|
|
|
elseif(MSVC_VERSION EQUAL 1800)
|
|
|
|
set(OpenCV_RUNTIME vc12)
|
2015-05-02 22:24:14 +08:00
|
|
|
elseif(MSVC_VERSION EQUAL 1900)
|
|
|
|
set(OpenCV_RUNTIME vc14)
|
2017-11-07 18:52:06 +08:00
|
|
|
elseif(MSVC_VERSION MATCHES "^191[0-9]$")
|
2016-12-06 08:04:24 +08:00
|
|
|
set(OpenCV_RUNTIME vc15)
|
2019-03-05 18:38:47 +08:00
|
|
|
elseif(MSVC_VERSION MATCHES "^192[0-9]$")
|
|
|
|
set(OpenCV_RUNTIME vc16)
|
2017-09-20 06:00:25 +08:00
|
|
|
else()
|
|
|
|
message(WARNING "OpenCV does not recognize MSVC_VERSION \"${MSVC_VERSION}\". Cannot set OpenCV_RUNTIME")
|
2013-08-07 16:53:48 +08:00
|
|
|
endif()
|
|
|
|
elseif(MINGW)
|
|
|
|
set(OpenCV_RUNTIME mingw)
|
|
|
|
|
2019-12-11 06:35:36 +08:00
|
|
|
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
|
2013-08-07 16:53:48 +08:00
|
|
|
set(OpenCV_ARCH x64)
|
|
|
|
else()
|
|
|
|
set(OpenCV_ARCH x86)
|
|
|
|
endif()
|
|
|
|
endif()
|
2017-01-18 23:37:52 +08:00
|
|
|
|
|
|
|
# Fix handling of duplicated files in the same static library:
|
|
|
|
# https://public.kitware.com/Bug/view.php?id=14874
|
|
|
|
if(CMAKE_VERSION VERSION_LESS "3.1")
|
|
|
|
foreach(var CMAKE_C_ARCHIVE_APPEND CMAKE_CXX_ARCHIVE_APPEND)
|
|
|
|
if(${var} MATCHES "^<CMAKE_AR> r")
|
|
|
|
string(REPLACE "<CMAKE_AR> r" "<CMAKE_AR> q" ${var} "${${var}}")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2017-07-03 19:39:25 +08:00
|
|
|
|
2020-02-20 19:18:43 +08:00
|
|
|
if(NOT OPENCV_SKIP_CMAKE_CXX_STANDARD)
|
|
|
|
ocv_update(CMAKE_CXX_STANDARD 11)
|
|
|
|
ocv_update(CMAKE_CXX_STANDARD_REQUIRED TRUE)
|
|
|
|
ocv_update(CMAKE_CXX_EXTENSIONS OFF) # use -std=c++11 instead of -std=gnu++11
|
|
|
|
if(CMAKE_CXX11_COMPILE_FEATURES)
|
|
|
|
set(HAVE_CXX11 ON)
|
|
|
|
endif()
|
2017-07-03 19:39:25 +08:00
|
|
|
endif()
|
|
|
|
if(NOT HAVE_CXX11)
|
|
|
|
ocv_check_compiler_flag(CXX "" HAVE_CXX11 "${OpenCV_SOURCE_DIR}/cmake/checks/cxx11.cpp")
|
2019-04-16 01:00:55 +08:00
|
|
|
if(NOT HAVE_CXX11)
|
2017-07-03 19:39:25 +08:00
|
|
|
ocv_check_compiler_flag(CXX "-std=c++11" HAVE_STD_CXX11 "${OpenCV_SOURCE_DIR}/cmake/checks/cxx11.cpp")
|
|
|
|
if(HAVE_STD_CXX11)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
|
|
set(HAVE_CXX11 ON)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
2019-08-20 21:19:37 +08:00
|
|
|
|
2018-03-23 17:07:10 +08:00
|
|
|
if(NOT HAVE_CXX11)
|
|
|
|
message(FATAL_ERROR "OpenCV 4.x requires C++11")
|
|
|
|
endif()
|
2019-08-24 00:24:37 +08:00
|
|
|
|
2019-08-20 21:19:37 +08:00
|
|
|
if((HAVE_CXX11
|
|
|
|
AND NOT MSVC
|
|
|
|
AND NOT (X86 OR X86_64)
|
|
|
|
AND NOT OPENCV_SKIP_LIBATOMIC_COMPILER_CHECK)
|
|
|
|
OR OPENCV_FORCE_LIBATOMIC_COMPILER_CHECK
|
|
|
|
)
|
|
|
|
ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITHOUT_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp")
|
|
|
|
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
|
|
|
|
list(APPEND CMAKE_REQUIRED_LIBRARIES atomic)
|
|
|
|
ocv_check_compiler_flag(CXX "" HAVE_CXX_ATOMICS_WITH_LIB "${OpenCV_SOURCE_DIR}/cmake/checks/atomic_check.cpp")
|
|
|
|
if(HAVE_CXX_ATOMICS_WITH_LIB)
|
|
|
|
list(APPEND OPENCV_LINKER_LIBS atomic)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "C++11 compiler must support std::atomic")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|