Home | History | Annotate | Download | only in cmake
      1 # ----------------------------------------------------------------------------
      2 # Detect Microsoft compiler:
      3 # ----------------------------------------------------------------------------
      4 if(CMAKE_CL_64)
      5     set(MSVC64 1)
      6 endif()
      7 
      8 if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
      9   set(CMAKE_COMPILER_IS_GNUCXX 1)
     10   set(CMAKE_COMPILER_IS_CLANGCXX 1)
     11 endif()
     12 if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
     13   set(CMAKE_COMPILER_IS_GNUCC 1)
     14   set(CMAKE_COMPILER_IS_CLANGCC 1)
     15 endif()
     16 
     17 if((CMAKE_COMPILER_IS_CLANGCXX OR CMAKE_COMPILER_IS_CLANGCC) AND NOT CMAKE_GENERATOR MATCHES "Xcode")
     18   set(ENABLE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
     19 endif()
     20 
     21 # ----------------------------------------------------------------------------
     22 # Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ):
     23 #  see  include/opencv/cxtypes.h file for related   ICC & CV_ICC defines.
     24 # NOTE: The system needs to determine if the '-fPIC' option needs to be added
     25 #  for the 3rdparty static libs being compiled.  The CMakeLists.txt files
     26 #  in 3rdparty use the CV_ICC definition being set here to determine if
     27 #  the -fPIC flag should be used.
     28 # ----------------------------------------------------------------------------
     29 if(UNIX)
     30   if  (__ICL)
     31     set(CV_ICC   __ICL)
     32   elseif(__ICC)
     33     set(CV_ICC   __ICC)
     34   elseif(__ECL)
     35     set(CV_ICC   __ECL)
     36   elseif(__ECC)
     37     set(CV_ICC   __ECC)
     38   elseif(__INTEL_COMPILER)
     39     set(CV_ICC   __INTEL_COMPILER)
     40   elseif(CMAKE_C_COMPILER MATCHES "icc")
     41     set(CV_ICC   icc_matches_c_compiler)
     42   endif()
     43 endif()
     44 
     45 if(MSVC AND CMAKE_C_COMPILER MATCHES "icc")
     46   set(CV_ICC   __INTEL_COMPILER_FOR_WINDOWS)
     47 endif()
     48 
     49 # ----------------------------------------------------------------------------
     50 # Detect GNU version:
     51 # ----------------------------------------------------------------------------
     52 if(CMAKE_COMPILER_IS_CLANGCXX)
     53   set(CMAKE_GCC_REGEX_VERSION "4.2.1")
     54   set(CMAKE_OPENCV_GCC_VERSION_MAJOR 4)
     55   set(CMAKE_OPENCV_GCC_VERSION_MINOR 2)
     56   set(CMAKE_OPENCV_GCC_VERSION 42)
     57   set(CMAKE_OPENCV_GCC_VERSION_NUM 402)
     58 
     59   execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v
     60                   ERROR_VARIABLE CMAKE_OPENCV_CLANG_VERSION_FULL
     61                   ERROR_STRIP_TRAILING_WHITESPACE)
     62 
     63   string(REGEX MATCH "version.*$" CMAKE_OPENCV_CLANG_VERSION_FULL "${CMAKE_OPENCV_CLANG_VERSION_FULL}")
     64   string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_CLANG_REGEX_VERSION "${CMAKE_OPENCV_CLANG_VERSION_FULL}")
     65 
     66 elseif(CMAKE_COMPILER_IS_GNUCXX)
     67   execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
     68                 OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL
     69                 OUTPUT_STRIP_TRAILING_WHITESPACE)
     70 
     71   execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v
     72                 ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL
     73                 OUTPUT_STRIP_TRAILING_WHITESPACE)
     74 
     75   # Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)"
     76   # Look for the version number
     77   string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
     78   if(NOT CMAKE_GCC_REGEX_VERSION)
     79     string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
     80   endif()
     81 
     82   # Split the three parts:
     83   string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}")
     84 
     85   list(GET CMAKE_OPENCV_GCC_VERSIONS 0 CMAKE_OPENCV_GCC_VERSION_MAJOR)
     86   list(GET CMAKE_OPENCV_GCC_VERSIONS 1 CMAKE_OPENCV_GCC_VERSION_MINOR)
     87 
     88   set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR})
     89   math(EXPR CMAKE_OPENCV_GCC_VERSION_NUM "${CMAKE_OPENCV_GCC_VERSION_MAJOR}*100 + ${CMAKE_OPENCV_GCC_VERSION_MINOR}")
     90   message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION} (${CMAKE_OPENCV_GCC_VERSION_NUM})")
     91 
     92   if(WIN32)
     93     execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
     94               OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE
     95               OUTPUT_STRIP_TRAILING_WHITESPACE)
     96     if(OPENCV_GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64")
     97       set(MINGW64 1)
     98     endif()
     99   endif()
    100 endif()
    101 
    102 if(MSVC64 OR MINGW64)
    103   set(X86_64 1)
    104 elseif(MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING))
    105   set(X86 1)
    106 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
    107   set(X86_64 1)
    108 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*|amd64.*|AMD64.*")
    109   set(X86 1)
    110 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
    111   set(ARM 1)
    112 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
    113   set(AARCH64 1)
    114 endif()
    115 
    116 
    117 # Similar code exists in OpenCVConfig.cmake
    118 if(NOT DEFINED OpenCV_STATIC)
    119   # look for global setting
    120   if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
    121     set(OpenCV_STATIC OFF)
    122   else()
    123     set(OpenCV_STATIC ON)
    124   endif()
    125 endif()
    126 
    127 if(MSVC)
    128   if(CMAKE_CL_64)
    129     set(OpenCV_ARCH x64)
    130   elseif((CMAKE_GENERATOR MATCHES "ARM") OR ("${arch_hint}" STREQUAL "ARM") OR (CMAKE_VS_EFFECTIVE_PLATFORMS MATCHES "ARM|arm"))
    131     # see Modules/CmakeGenericSystem.cmake
    132     set(OpenCV_ARCH ARM)
    133   else()
    134     set(OpenCV_ARCH x86)
    135   endif()
    136   if(MSVC_VERSION EQUAL 1400)
    137     set(OpenCV_RUNTIME vc8)
    138   elseif(MSVC_VERSION EQUAL 1500)
    139     set(OpenCV_RUNTIME vc9)
    140   elseif(MSVC_VERSION EQUAL 1600)
    141     set(OpenCV_RUNTIME vc10)
    142   elseif(MSVC_VERSION EQUAL 1700)
    143     set(OpenCV_RUNTIME vc11)
    144   elseif(MSVC_VERSION EQUAL 1800)
    145     set(OpenCV_RUNTIME vc12)
    146   elseif(MSVC_VERSION EQUAL 1900)
    147     set(OpenCV_RUNTIME vc14)
    148   endif()
    149 elseif(MINGW)
    150   set(OpenCV_RUNTIME mingw)
    151 
    152   if(MINGW64)
    153     set(OpenCV_ARCH x64)
    154   else()
    155     set(OpenCV_ARCH x86)
    156   endif()
    157 endif()
    158