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" "SYMBIAN") 63 DE_MAKE_ENV_BOOL("DE_OS" "IOS") 64 65 # Compiler detection 66 if (NOT DEFINED DE_COMPILER) 67 # \note " x" postfix is to work around bug in CMake that causes 68 # "MSVC" to translate to something completely different 69 if (("${CMAKE_C_COMPILER_ID} x" MATCHES "MSVC") OR MSVC) 70 set(DE_COMPILER "DE_COMPILER_MSC") 71 elseif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU") 72 set(DE_COMPILER "DE_COMPILER_GCC") 73 elseif ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang") 74 set(DE_COMPILER "DE_COMPILER_CLANG") 75 76 # Guess based on OS 77 elseif (DE_OS_IS_WIN32) 78 set(DE_COMPILER "DE_COMPILER_MSC") 79 elseif (DE_OS_IS_UNIX OR DE_OS_IS_ANDROID) 80 set(DE_COMPILER "DE_COMPILER_GCC") 81 elseif (DE_OS_IS_OSX OR DE_OS_IS_IOS) 82 set(DE_COMPILER "DE_COMPILER_CLANG") 83 84 else () 85 set(DE_COMPILER "DE_COMPILER_VANILLA") 86 endif () 87 endif () 88 89 # DE_COMPILER_IS_{COMPILER} definitions 90 DE_MAKE_ENV_BOOL("DE_COMPILER" "VANILLA") 91 DE_MAKE_ENV_BOOL("DE_COMPILER" "MSC") 92 DE_MAKE_ENV_BOOL("DE_COMPILER" "GCC") 93 DE_MAKE_ENV_BOOL("DE_COMPILER" "CLANG") 94 95 # Pointer size detection 96 if (NOT DEFINED DE_PTR_SIZE) 97 if (DEFINED CMAKE_SIZEOF_VOID_P) 98 set(DE_PTR_SIZE ${CMAKE_SIZEOF_VOID_P}) 99 else () 100 set(DE_PTR_SIZE 4) 101 endif () 102 endif () 103 104 # CPU detection 105 if (NOT DEFINED DE_CPU) 106 if (DE_PTR_SIZE EQUAL 8) 107 set(DE_CPU "DE_CPU_X86_64") 108 else () 109 set(DE_CPU "DE_CPU_X86") 110 endif () 111 endif () 112 113 # DE_CPU_IS_{CPU} definitions 114 DE_MAKE_ENV_BOOL("DE_CPU" "VANILLA") 115 DE_MAKE_ENV_BOOL("DE_CPU" "X86") 116 DE_MAKE_ENV_BOOL("DE_CPU" "ARM") 117 DE_MAKE_ENV_BOOL("DE_CPU" "ARM_64") 118 119 # \note [petri] Re-wrote in this ugly manner, because CMake 2.6 seems to 120 # barf about the parenthesis in the previous way. Ugh. 121 #if (NOT ((DE_PTR_SIZE EQUAL 4) OR (DE_PTR_SIZE EQUAL 8))) 122 if (DE_PTR_SIZE EQUAL 4) 123 elseif (DE_PTR_SIZE EQUAL 8) 124 else () 125 message(FATAL_ERROR "DE_PTR_SIZE (${DE_PTR_SIZE}) is invalid") 126 endif () 127 128 # Debug definitions 129 if (NOT DEFINED DE_DEBUG) 130 if (CMAKE_BUILD_TYPE STREQUAL "Debug") 131 set(DE_DEBUG 1) 132 else () 133 set(DE_DEBUG 0) 134 endif () 135 endif () 136 137 # Android API version 138 if (DE_OS_IS_ANDROID AND NOT DEFINED DE_ANDROID_API) 139 set(DE_ANDROID_API 5) 140 endif () 141 142 message(STATUS "DE_OS = ${DE_OS}") 143 message(STATUS "DE_COMPILER = ${DE_COMPILER}") 144 message(STATUS "DE_CPU = ${DE_CPU}") 145 message(STATUS "DE_PTR_SIZE = ${DE_PTR_SIZE}") 146 message(STATUS "DE_DEBUG = ${DE_DEBUG}") 147 if (DE_OS_IS_ANDROID) 148 message(STATUS "DE_ANDROID_API = ${DE_ANDROID_API}") 149 endif () 150 151 # Expose definitions 152 if (DE_DEBUG) 153 add_definitions(-DDE_DEBUG) 154 endif () 155 156 add_definitions("-DDE_OS=${DE_OS}") 157 add_definitions("-DDE_COMPILER=${DE_COMPILER}") 158 add_definitions("-DDE_CPU=${DE_CPU}") 159 add_definitions("-DDE_PTR_SIZE=${DE_PTR_SIZE}") 160 161 if (DE_OS_IS_ANDROID) 162 add_definitions("-DDE_ANDROID_API=${DE_ANDROID_API}") 163 endif () 164