mips: implement MB and WMB
[platform/upstream/openblas.git] / cmake / c_check.cmake
1 ##
2 ## Author: Hank Anderson <hank@statease.com>
3 ## Description: Ported from the OpenBLAS/c_check perl script.
4 ##              This is triggered by prebuild.cmake and runs before any of the code is built.
5 ##              Creates config.h and Makefile.conf.
6
7 # CMake vars set by this file:
8 # OSNAME (use CMAKE_SYSTEM_NAME)
9 # ARCH
10 # C_COMPILER (use CMAKE_C_COMPILER)
11 # BINARY32
12 # BINARY64
13 # FU
14 # CROSS_SUFFIX
15 # CROSS
16 # CEXTRALIB
17
18 # Defines set by this file:
19 # OS_
20 # ARCH_
21 # C_
22 # __32BIT__
23 # __64BIT__
24 # FUNDERSCORE
25 # PTHREAD_CREATE_FUNC
26
27 # N.B. c_check (and ctest.c) is not cross-platform, so instead try to use CMake variables.
28 set(FU "")
29 if(APPLE)
30 set(FU "_")
31 elseif(MSVC)
32 set(FU "_")
33 elseif(UNIX)
34 set(FU "")
35 endif()
36
37 # Convert CMake vars into the format that OpenBLAS expects
38 string(TOUPPER ${CMAKE_SYSTEM_NAME} HOST_OS)
39 if (${HOST_OS} STREQUAL "WINDOWS")
40   set(HOST_OS WINNT)
41 endif ()
42
43 # added by hpa - check size of void ptr to detect 64-bit compile
44 if (NOT DEFINED BINARY)
45   set(BINARY 32)
46   if (CMAKE_SIZEOF_VOID_P EQUAL 8)
47     set(BINARY 64)
48   endif ()
49 endif ()
50
51 if (BINARY EQUAL 64)
52   set(BINARY64 1)
53 else ()
54   set(BINARY32 1)
55 endif ()
56
57 # CMake docs define these:
58 # CMAKE_SYSTEM_PROCESSOR - The name of the CPU CMake is building for.
59 # CMAKE_HOST_SYSTEM_PROCESSOR - The name of the CPU CMake is running on.
60 #
61 # TODO: CMAKE_SYSTEM_PROCESSOR doesn't seem to be correct - instead get it from the compiler a la c_check
62 set(ARCH ${CMAKE_SYSTEM_PROCESSOR})
63 if (${ARCH} STREQUAL "AMD64")
64   set(ARCH "x86_64")
65 endif ()
66
67 # If you are using a 32-bit compiler on a 64-bit system CMAKE_SYSTEM_PROCESSOR will be wrong
68 if (${ARCH} STREQUAL "x86_64" AND BINARY EQUAL 32)
69   set(ARCH x86)
70 endif ()
71
72 if (${ARCH} STREQUAL "X86")
73   set(ARCH x86)
74 endif ()
75
76 if (${ARCH} MATCHES "ppc")
77   set(ARCH power)
78 endif ()
79
80 set(COMPILER_ID ${CMAKE_CXX_COMPILER_ID})
81 if (${COMPILER_ID} STREQUAL "GNU")
82   set(COMPILER_ID "GCC")
83 endif ()
84
85 string(TOUPPER ${ARCH} UC_ARCH)
86
87 file(WRITE ${TARGET_CONF}
88   "#define OS_${HOST_OS}\t1\n"
89   "#define ARCH_${UC_ARCH}\t1\n"
90   "#define C_${COMPILER_ID}\t1\n"
91   "#define __${BINARY}BIT__\t1\n"
92   "#define FUNDERSCORE\t${FU}\n")
93