Fix bitness detection for target platform
authorAndrey Kamaev <andrey.kamaev@itseez.com>
Sat, 6 Apr 2013 16:11:40 +0000 (20:11 +0400)
committerAndrey Kamaev <andrey.kamaev@itseez.com>
Mon, 8 Apr 2013 07:25:36 +0000 (11:25 +0400)
cmake/OpenCVDetectCXXCompiler.cmake

index 9ee23da..9b841da 100644 (file)
@@ -27,23 +27,23 @@ endif()
 #  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()
+  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)
+  set(CV_ICC   __INTEL_COMPILER_FOR_WINDOWS)
 endif()
 
 # ----------------------------------------------------------------------------
@@ -64,45 +64,49 @@ if(CMAKE_COMPILER_IS_CLANGCXX)
   string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_CLANG_REGEX_VERSION "${CMAKE_OPENCV_CLANG_VERSION_FULL}")
 
 elseif(CMAKE_COMPILER_IS_GNUCXX)
-    execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
-                  OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL
-                  OUTPUT_STRIP_TRAILING_WHITESPACE)
+  execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
+                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)
+  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
-    string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
-    if(NOT CMAKE_GCC_REGEX_VERSION)
-      string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
-    endif()
+  # Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)"
+  # Look for the version number
+  string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
+  if(NOT CMAKE_GCC_REGEX_VERSION)
+    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}")
+  # 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)
+  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})")
+  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 "amd64|x86_64|AMD64")
-            set(MINGW64 1)
-        endif()
+  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 "amd64|x86_64|AMD64")
+      set(MINGW64 1)
     endif()
+  endif()
 endif()
 
-if(MINGW64 OR CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*" OR CMAKE_GENERATOR MATCHES "Visual Studio.*Win64")
-    set(X86_64 1)
+if(MSVC64 OR MINGW64)
+  set(X86_64 1)
+elseif(MSVC AND NOT CMAKE_CROSSCOMPILING)
+  set(X86 1)
+elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
+  set(X86_64 1)
 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*|amd64.*|AMD64.*")
-    set(X86 1)
+  set(X86 1)
 elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*|ARM.*")
-    set(ARM 1)
+  set(ARM 1)
 endif()