Merge "Add cmake build type ReleaseWithAsserts."
[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 # Add build type release with asserts
43 set(CMAKE_CXX_FLAGS_RELEASEWITHASSERTS ${CMAKE_CXX_FLAGS_RELEASE})
44 set(CMAKE_C_FLAGS_RELEASEWITHASSERTS ${CMAKE_C_FLAGS_RELEASE})
45 set(CMAKE_EXE_LINKER_FLAGS_RELEASEWITHASSERTS ${CMAKE_EXE_LINKER_FLAGS_RELEASE})
46 set(CMAKE_SHARED_LINKER_FLAGS_RELEASEWITHASSERTS ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
47
48 # cmake doesn't validate build type.
49 if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
50         AND NOT CMAKE_BUILD_TYPE STREQUAL "Release"
51         AND NOT CMAKE_BUILD_TYPE STREQUAL "RelWithAsserts"
52         AND NOT CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"
53         AND NOT CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
54
55         message(FATAL_ERROR "Unknown build type ${CMAKE_BUILD_TYPE} available build types Debug, Release, RelWithAsserts, RelWithDebInfo and MinSizeRel")
56 endif()
57
58 # Os detection
59 if (NOT DEFINED DE_OS)
60         if (WIN32)
61                 set(DE_OS "DE_OS_WIN32")
62         elseif (APPLE)
63                 set(DE_OS "DE_OS_OSX")
64         elseif (UNIX)
65                 set(DE_OS "DE_OS_UNIX")
66         else ()
67                 set(DE_OS "DE_OS_VANILLA")
68         endif ()
69 endif ()
70
71 # DE_OS_IS_{PLATFORM} definitions
72 DE_MAKE_ENV_BOOL("DE_OS" "VANILLA")
73 DE_MAKE_ENV_BOOL("DE_OS" "WIN32")
74 DE_MAKE_ENV_BOOL("DE_OS" "UNIX")
75 DE_MAKE_ENV_BOOL("DE_OS" "WINCE")
76 DE_MAKE_ENV_BOOL("DE_OS" "OSX")
77 DE_MAKE_ENV_BOOL("DE_OS" "ANDROID")
78 DE_MAKE_ENV_BOOL("DE_OS" "IOS")
79
80 # Prevent mixed compile with GCC and Clang
81 if (NOT ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") EQUAL ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU"))
82         message(FATAL_ERROR "CMake C and CXX compilers do not match. Both or neither must be GNU.")
83 elseif (NOT ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") EQUAL ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
84         message(FATAL_ERROR "CMake C and CXX compilers do not match. Both or neither must be Clang.")
85 endif ()
86
87 # Compiler detection
88 if (NOT DEFINED DE_COMPILER)
89         # \note " x" postfix is to work around bug in CMake that causes
90         #       "MSVC" to translate to something completely different
91         if (("${CMAKE_C_COMPILER_ID} x" MATCHES "MSVC") OR MSVC)
92                 set(DE_COMPILER "DE_COMPILER_MSC")
93         elseif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU")
94                 set(DE_COMPILER "DE_COMPILER_GCC")
95         elseif ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
96                 set(DE_COMPILER "DE_COMPILER_CLANG")
97
98         # Guess based on OS
99         elseif (DE_OS_IS_WIN32)
100                 set(DE_COMPILER "DE_COMPILER_MSC")
101         elseif (DE_OS_IS_UNIX OR DE_OS_IS_ANDROID)
102                 set(DE_COMPILER "DE_COMPILER_GCC")
103         elseif (DE_OS_IS_OSX OR DE_OS_IS_IOS)
104                 set(DE_COMPILER "DE_COMPILER_CLANG")
105
106         else ()
107                 set(DE_COMPILER "DE_COMPILER_VANILLA")
108         endif ()
109 endif ()
110
111 # DE_COMPILER_IS_{COMPILER} definitions
112 DE_MAKE_ENV_BOOL("DE_COMPILER" "VANILLA")
113 DE_MAKE_ENV_BOOL("DE_COMPILER" "MSC")
114 DE_MAKE_ENV_BOOL("DE_COMPILER" "GCC")
115 DE_MAKE_ENV_BOOL("DE_COMPILER" "CLANG")
116
117 # Pointer size detection
118 if (NOT DEFINED DE_PTR_SIZE)
119         if (DEFINED CMAKE_SIZEOF_VOID_P)
120                 set(DE_PTR_SIZE ${CMAKE_SIZEOF_VOID_P})
121         else ()
122                 set(DE_PTR_SIZE 4)
123         endif ()
124 endif ()
125
126 # CPU detection
127 if (NOT DEFINED DE_CPU)
128         if (DE_PTR_SIZE EQUAL 8)
129                 set(DE_CPU "DE_CPU_X86_64")
130         else ()
131                 set(DE_CPU "DE_CPU_X86")
132         endif ()
133 endif ()
134
135 # DE_CPU_IS_{CPU} definitions
136 DE_MAKE_ENV_BOOL("DE_CPU" "VANILLA")
137 DE_MAKE_ENV_BOOL("DE_CPU" "X86")
138 DE_MAKE_ENV_BOOL("DE_CPU" "ARM")
139 DE_MAKE_ENV_BOOL("DE_CPU" "ARM_64")
140
141 # \note [petri] Re-wrote in this ugly manner, because CMake 2.6 seems to
142 #               barf about the parenthesis in the previous way. Ugh.
143 #if (NOT ((DE_PTR_SIZE EQUAL 4) OR (DE_PTR_SIZE EQUAL 8)))
144 if (DE_PTR_SIZE EQUAL 4)
145 elseif (DE_PTR_SIZE EQUAL 8)
146 else ()
147         message(FATAL_ERROR "DE_PTR_SIZE (${DE_PTR_SIZE}) is invalid")
148 endif ()
149
150 # Debug definitions
151 if (NOT DEFINED DE_DEBUG)
152         if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithAsserts")
153                 set(DE_DEBUG 1)
154         else ()
155                 set(DE_DEBUG 0)
156         endif ()
157 endif ()
158
159 # Android API version
160 if (DE_OS_IS_ANDROID AND NOT DEFINED DE_ANDROID_API)
161         set(DE_ANDROID_API 5)
162 endif ()
163
164 message(STATUS "DE_OS          = ${DE_OS}")
165 message(STATUS "DE_COMPILER    = ${DE_COMPILER}")
166 message(STATUS "DE_CPU         = ${DE_CPU}")
167 message(STATUS "DE_PTR_SIZE    = ${DE_PTR_SIZE}")
168 message(STATUS "DE_DEBUG       = ${DE_DEBUG}")
169 if (DE_OS_IS_ANDROID)
170         message(STATUS "DE_ANDROID_API = ${DE_ANDROID_API}")
171 endif ()
172
173 # Expose definitions
174 if (DE_DEBUG)
175         add_definitions(-DDE_DEBUG)
176 endif ()
177
178 add_definitions("-DDE_OS=${DE_OS}")
179 add_definitions("-DDE_COMPILER=${DE_COMPILER}")
180 add_definitions("-DDE_CPU=${DE_CPU}")
181 add_definitions("-DDE_PTR_SIZE=${DE_PTR_SIZE}")
182
183 if (DE_OS_IS_ANDROID)
184         add_definitions("-DDE_ANDROID_API=${DE_ANDROID_API}")
185 endif ()