am 9125a6e7: (-s ours) am f61fb6b0: am 84e26791: Merge "DO NOT MERGE: Remove io_block...
[platform/upstream/VK-GL-CTS.git] / framework / delibs / cmake / Defs.cmake
1 #-------------------------------------------------------------------------
2 # drawElements CMake utilities
3 # ----------------------------
4 #
5 # Copyright 2014 The Android Open Source Project
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #      http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 #-------------------------------------------------------------------------
20
21 # \note Always include this file in main project file, with NO_POLICY_SCOPE
22 #       AFTER project(name) statement.
23 #
24 # project(deproject)
25 # include(delibs/cmake/Defs.cmake NO_POLICY_SCOPE)
26
27 cmake_policy(VERSION 2.6)
28
29 # \todo [pyry] More intelligent detection, perhaps use some script?
30
31 # cmake files can use DE_DEFS variable to check that this file has been included
32 set(DE_DEFS 1)
33
34 macro (DE_MAKE_ENV_BOOL BASE VALUE)
35         if (${BASE} STREQUAL ${BASE}_${VALUE})
36                 set(${BASE}_IS_${VALUE} 1)
37         else ()
38                 set(${BASE}_IS_${VALUE} 0)
39         endif ()
40 endmacro ()
41
42 # Os detection
43 if (NOT DEFINED DE_OS)
44         if (WIN32)
45                 set(DE_OS "DE_OS_WIN32")
46         elseif (APPLE)
47                 set(DE_OS "DE_OS_OSX")
48         elseif (UNIX)
49                 set(DE_OS "DE_OS_UNIX")
50         else ()
51                 set(DE_OS "DE_OS_VANILLA")
52         endif ()
53 endif ()
54
55 # DE_OS_IS_{PLATFORM} definitions
56 DE_MAKE_ENV_BOOL("DE_OS" "VANILLA")
57 DE_MAKE_ENV_BOOL("DE_OS" "WIN32")
58 DE_MAKE_ENV_BOOL("DE_OS" "UNIX")
59 DE_MAKE_ENV_BOOL("DE_OS" "WINCE")
60 DE_MAKE_ENV_BOOL("DE_OS" "OSX")
61 DE_MAKE_ENV_BOOL("DE_OS" "ANDROID")
62 DE_MAKE_ENV_BOOL("DE_OS" "IOS")
63
64 # Prevent mixed compile with GCC and Clang
65 if (NOT ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") EQUAL ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU"))
66         message(FATAL_ERROR "CMake C and CXX compilers do not match. Both or neither must be GNU.")
67 elseif (NOT ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") EQUAL ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
68         message(FATAL_ERROR "CMake C and CXX compilers do not match. Both or neither must be Clang.")
69 endif ()
70
71 # Compiler detection
72 if (NOT DEFINED DE_COMPILER)
73         # \note " x" postfix is to work around bug in CMake that causes
74         #       "MSVC" to translate to something completely different
75         if (("${CMAKE_C_COMPILER_ID} x" MATCHES "MSVC") OR MSVC)
76                 set(DE_COMPILER "DE_COMPILER_MSC")
77         elseif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU")
78                 set(DE_COMPILER "DE_COMPILER_GCC")
79         elseif ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
80                 set(DE_COMPILER "DE_COMPILER_CLANG")
81
82         # Guess based on OS
83         elseif (DE_OS_IS_WIN32)
84                 set(DE_COMPILER "DE_COMPILER_MSC")
85         elseif (DE_OS_IS_UNIX OR DE_OS_IS_ANDROID)
86                 set(DE_COMPILER "DE_COMPILER_GCC")
87         elseif (DE_OS_IS_OSX OR DE_OS_IS_IOS)
88                 set(DE_COMPILER "DE_COMPILER_CLANG")
89
90         else ()
91                 set(DE_COMPILER "DE_COMPILER_VANILLA")
92         endif ()
93 endif ()
94
95 # DE_COMPILER_IS_{COMPILER} definitions
96 DE_MAKE_ENV_BOOL("DE_COMPILER" "VANILLA")
97 DE_MAKE_ENV_BOOL("DE_COMPILER" "MSC")
98 DE_MAKE_ENV_BOOL("DE_COMPILER" "GCC")
99 DE_MAKE_ENV_BOOL("DE_COMPILER" "CLANG")
100
101 # Pointer size detection
102 if (NOT DEFINED DE_PTR_SIZE)
103         if (DEFINED CMAKE_SIZEOF_VOID_P)
104                 set(DE_PTR_SIZE ${CMAKE_SIZEOF_VOID_P})
105         else ()
106                 set(DE_PTR_SIZE 4)
107         endif ()
108 endif ()
109
110 # CPU detection
111 if (NOT DEFINED DE_CPU)
112         if (DE_PTR_SIZE EQUAL 8)
113                 set(DE_CPU "DE_CPU_X86_64")
114         else ()
115                 set(DE_CPU "DE_CPU_X86")
116         endif ()
117 endif ()
118
119 # DE_CPU_IS_{CPU} definitions
120 DE_MAKE_ENV_BOOL("DE_CPU" "VANILLA")
121 DE_MAKE_ENV_BOOL("DE_CPU" "X86")
122 DE_MAKE_ENV_BOOL("DE_CPU" "ARM")
123 DE_MAKE_ENV_BOOL("DE_CPU" "ARM_64")
124
125 # \note [petri] Re-wrote in this ugly manner, because CMake 2.6 seems to
126 #               barf about the parenthesis in the previous way. Ugh.
127 #if (NOT ((DE_PTR_SIZE EQUAL 4) OR (DE_PTR_SIZE EQUAL 8)))
128 if (DE_PTR_SIZE EQUAL 4)
129 elseif (DE_PTR_SIZE EQUAL 8)
130 else ()
131         message(FATAL_ERROR "DE_PTR_SIZE (${DE_PTR_SIZE}) is invalid")
132 endif ()
133
134 # Debug definitions
135 if (NOT DEFINED DE_DEBUG)
136         if (CMAKE_BUILD_TYPE STREQUAL "Debug")
137                 set(DE_DEBUG 1)
138         else ()
139                 set(DE_DEBUG 0)
140         endif ()
141 endif ()
142
143 # Android API version
144 if (DE_OS_IS_ANDROID AND NOT DEFINED DE_ANDROID_API)
145         set(DE_ANDROID_API 5)
146 endif ()
147
148 message(STATUS "DE_OS          = ${DE_OS}")
149 message(STATUS "DE_COMPILER    = ${DE_COMPILER}")
150 message(STATUS "DE_CPU         = ${DE_CPU}")
151 message(STATUS "DE_PTR_SIZE    = ${DE_PTR_SIZE}")
152 message(STATUS "DE_DEBUG       = ${DE_DEBUG}")
153 if (DE_OS_IS_ANDROID)
154         message(STATUS "DE_ANDROID_API = ${DE_ANDROID_API}")
155 endif ()
156
157 # Expose definitions
158 if (DE_DEBUG)
159         add_definitions(-DDE_DEBUG)
160 endif ()
161
162 add_definitions("-DDE_OS=${DE_OS}")
163 add_definitions("-DDE_COMPILER=${DE_COMPILER}")
164 add_definitions("-DDE_CPU=${DE_CPU}")
165 add_definitions("-DDE_PTR_SIZE=${DE_PTR_SIZE}")
166
167 if (DE_OS_IS_ANDROID)
168         add_definitions("-DDE_ANDROID_API=${DE_ANDROID_API}")
169 endif ()