opencv/cmake/OpenCVDetectCXXCompiler.cmake

97 lines
3.8 KiB
CMake
Raw Normal View History

# ----------------------------------------------------------------------------
# Detect Microsoft compiler:
# ----------------------------------------------------------------------------
if(CMAKE_CL_64)
set(MSVC64 1)
endif()
2012-04-30 16:33:52 +02:00
if(NOT APPLE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_COMPILER_IS_GNUCXX 1)
2012-05-23 21:28:41 +02:00
set(ENABLE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
2012-04-30 16:33:52 +02:00
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
2012-05-15 09:43:00 +02:00
set(CMAKE_COMPILER_IS_GNUCC 1)
2012-05-23 21:28:41 +02:00
set(ENABLE_PRECOMPILED_HEADERS OFF CACHE BOOL "" FORCE)
2012-04-30 16:33:52 +02:00
endif()
endif()
# ----------------------------------------------------------------------------
# Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ):
# see include/opencv/cxtypes.h file for related ICC & CV_ICC defines.
# NOTE: The system needs to determine if the '-fPIC' option needs to be added
# for the 3rdparty static libs being compiled. The CMakeLists.txt files
# in 3rdparty use the CV_ICC definition being set here to determine if
# the -fPIC flag should be used.
# ----------------------------------------------------------------------------
if(UNIX)
if (__ICL)
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()
endif()
if(MSVC AND CMAKE_C_COMPILER MATCHES "icc")
set(CV_ICC __INTEL_COMPILER_FOR_WINDOWS)
endif()
2012-06-08 05:15:08 +02:00
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR (UNIX AND CV_ICC))
set(CV_COMPILER_IS_GNU TRUE)
else()
set(CV_COMPILER_IS_GNU FALSE)
endif()
# ----------------------------------------------------------------------------
# Detect GNU version:
# ----------------------------------------------------------------------------
if(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} --version
OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v
ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)"
# Look for the version number
2012-07-28 11:05:40 +02:00
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
if(NOT CMAKE_GCC_REGEX_VERSION)
2012-07-28 11:05:40 +02:00
string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
endif()
# Split the three parts:
string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}")
list(GET CMAKE_OPENCV_GCC_VERSIONS 0 CMAKE_OPENCV_GCC_VERSION_MAJOR)
list(GET CMAKE_OPENCV_GCC_VERSIONS 1 CMAKE_OPENCV_GCC_VERSION_MINOR)
set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR})
math(EXPR CMAKE_OPENCV_GCC_VERSION_NUM "${CMAKE_OPENCV_GCC_VERSION_MAJOR}*100 + ${CMAKE_OPENCV_GCC_VERSION_MINOR}")
message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION} (${CMAKE_OPENCV_GCC_VERSION_NUM})")
if(WIN32)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
OUTPUT_VARIABLE CMAKE_OPENCV_GCC_TARGET_MACHINE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(CMAKE_OPENCV_GCC_TARGET_MACHINE MATCHES "64")
set(MINGW64 1)
endif()
endif()
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*" OR CMAKE_GENERATOR MATCHES "Visual Studio.*Win64")
set(X86_64 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*|amd64.*|AMD64.*")
set(X86 1)
endif()