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