1 #-------------------------------------------------------------------------
2 # drawElements CMake utilities
3 # ----------------------------
5 # Copyright 2014 The Android Open Source Project
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 #-------------------------------------------------------------------------
21 # \note Always include this file in main project file, with NO_POLICY_SCOPE
22 # AFTER project(name) statement.
25 # include(delibs/cmake/Defs.cmake NO_POLICY_SCOPE)
27 cmake_policy(VERSION 2.6)
29 # \todo [pyry] More intelligent detection, perhaps use some script?
31 # cmake files can use DE_DEFS variable to check that this file has been included
34 macro (DE_MAKE_ENV_BOOL BASE VALUE)
35 if (${BASE} STREQUAL ${BASE}_${VALUE})
36 set(${BASE}_IS_${VALUE} 1)
38 set(${BASE}_IS_${VALUE} 0)
43 if (NOT DEFINED DE_OS)
45 set(DE_OS "DE_OS_WIN32")
47 set(DE_OS "DE_OS_OSX")
49 set(DE_OS "DE_OS_UNIX")
51 set(DE_OS "DE_OS_VANILLA")
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")
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.")
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")
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")
91 set(DE_COMPILER "DE_COMPILER_VANILLA")
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")
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})
111 if (NOT DEFINED DE_CPU)
112 if (DE_PTR_SIZE EQUAL 8)
113 set(DE_CPU "DE_CPU_X86_64")
115 set(DE_CPU "DE_CPU_X86")
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")
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)
131 message(FATAL_ERROR "DE_PTR_SIZE (${DE_PTR_SIZE}) is invalid")
135 if (NOT DEFINED DE_DEBUG)
136 if (CMAKE_BUILD_TYPE STREQUAL "Debug")
143 # Android API version
144 if (DE_OS_IS_ANDROID AND NOT DEFINED DE_ANDROID_API)
145 set(DE_ANDROID_API 5)
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}")
159 add_definitions(-DDE_DEBUG)
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}")
167 if (DE_OS_IS_ANDROID)
168 add_definitions("-DDE_ANDROID_API=${DE_ANDROID_API}")