2 # - CV_GCC - GNU compiler (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
3 # - CV_CLANG - Clang-compatible compiler (CMAKE_CXX_COMPILER_ID MATCHES "Clang" - Clang or AppleClang, see CMP0025)
4 # - CV_ICC - Intel compiler
5 # - MSVC - Microsoft Visual Compiler (CMake variable)
6 # - MSVC64 - additional flag, 64-bit
7 # - MINGW / CYGWIN / CMAKE_COMPILER_IS_MINGW / CMAKE_COMPILER_IS_CYGWIN (CMake original variables)
12 # - ARM - ARM CPU, not defined for AArch64
13 # - AARCH64 - ARMv8+ (64-bit)
14 # - PPC64 / PPC64LE - PowerPC
17 # - WIN32 - Windows | MINGW
18 # - UNIX - Linux | MacOSX | ANDROID
21 # - APPLE - MacOSX | iOS
22 # ----------------------------------------------------------------------------
28 if(NOT DEFINED CV_GCC AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
31 if(NOT DEFINED CV_CLANG AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Clang or AppleClang (see CMP0025)
33 set(CMAKE_COMPILER_IS_CLANGCXX 1) # TODO next release: remove this
34 set(CMAKE_COMPILER_IS_CLANGCC 1) # TODO next release: remove this
37 function(access_CMAKE_COMPILER_IS_CLANGCXX)
38 if(NOT OPENCV_SUPPRESS_DEPRECATIONS)
39 message(WARNING "DEPRECATED: CMAKE_COMPILER_IS_CLANGCXX support is deprecated in OpenCV.
42 - CV_CLANG # Clang or AppleClang (see CMP0025)
46 variable_watch(CMAKE_COMPILER_IS_CLANGCXX access_CMAKE_COMPILER_IS_CLANGCXX)
47 variable_watch(CMAKE_COMPILER_IS_CLANGCC access_CMAKE_COMPILER_IS_CLANGCXX)
50 # ----------------------------------------------------------------------------
51 # Detect Intel ICC compiler
52 # ----------------------------------------------------------------------------
62 elseif(__INTEL_COMPILER)
63 set(CV_ICC __INTEL_COMPILER)
64 elseif(CMAKE_C_COMPILER MATCHES "icc")
65 set(CV_ICC icc_matches_c_compiler)
69 if(MSVC AND CMAKE_C_COMPILER MATCHES "icc|icl")
70 set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS)
73 if(NOT DEFINED CMAKE_CXX_COMPILER_VERSION)
74 message(WARNING "Compiler version is not available: CMAKE_CXX_COMPILER_VERSION is not set")
78 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
79 OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE
80 OUTPUT_STRIP_TRAILING_WHITESPACE)
81 if(OPENCV_GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64")
88 elseif(MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING))
90 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
92 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*|amd64.*|AMD64.*")
94 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
96 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
98 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le")
100 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
104 # Workaround for 32-bit operating systems on 64-bit x86_64 processor
105 if(X86_64 AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT FORCE_X86_64)
106 message(STATUS "sizeof(void) = 4 on x86 / x86_64 processor. Assume 32-bit compilation mode (X86=1)")
111 # Similar code exists in OpenCVConfig.cmake
112 if(NOT DEFINED OpenCV_STATIC)
113 # look for global setting
114 if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
115 set(OpenCV_STATIC OFF)
117 set(OpenCV_STATIC ON)
121 if(DEFINED OpenCV_ARCH AND DEFINED OpenCV_RUNTIME)
122 # custom overridden values
126 elseif((CMAKE_GENERATOR MATCHES "ARM") OR ("${arch_hint}" STREQUAL "ARM") OR (CMAKE_VS_EFFECTIVE_PLATFORMS MATCHES "ARM|arm"))
127 # see Modules/CmakeGenericSystem.cmake
132 if(MSVC_VERSION EQUAL 1400)
133 set(OpenCV_RUNTIME vc8)
134 elseif(MSVC_VERSION EQUAL 1500)
135 set(OpenCV_RUNTIME vc9)
136 elseif(MSVC_VERSION EQUAL 1600)
137 set(OpenCV_RUNTIME vc10)
138 elseif(MSVC_VERSION EQUAL 1700)
139 set(OpenCV_RUNTIME vc11)
140 elseif(MSVC_VERSION EQUAL 1800)
141 set(OpenCV_RUNTIME vc12)
142 elseif(MSVC_VERSION EQUAL 1900)
143 set(OpenCV_RUNTIME vc14)
144 elseif(MSVC_VERSION MATCHES "^191[0-9]$")
145 set(OpenCV_RUNTIME vc15)
147 message(WARNING "OpenCV does not recognize MSVC_VERSION \"${MSVC_VERSION}\". Cannot set OpenCV_RUNTIME")
150 set(OpenCV_RUNTIME mingw)
159 # Fix handling of duplicated files in the same static library:
160 # https://public.kitware.com/Bug/view.php?id=14874
161 if(CMAKE_VERSION VERSION_LESS "3.1")
162 foreach(var CMAKE_C_ARCHIVE_APPEND CMAKE_CXX_ARCHIVE_APPEND)
163 if(${var} MATCHES "^<CMAKE_AR> r")
164 string(REPLACE "<CMAKE_AR> r" "<CMAKE_AR> q" ${var} "${${var}}")
170 #cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
171 set(CMAKE_CXX_STANDARD 11)
172 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
173 set(CMAKE_CXX_EXTENSIONS OFF) # use -std=c++11 instead of -std=gnu++11
174 if(CMAKE_CXX11_COMPILE_FEATURES)
179 ocv_check_compiler_flag(CXX "" HAVE_CXX11 "${OpenCV_SOURCE_DIR}/cmake/checks/cxx11.cpp")
180 if(NOT HAVE_CXX11 AND ENABLE_CXX11)
181 ocv_check_compiler_flag(CXX "-std=c++11" HAVE_STD_CXX11 "${OpenCV_SOURCE_DIR}/cmake/checks/cxx11.cpp")
183 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")