1*35238bceSAndroid Build Coastguard Worker#------------------------------------------------------------------------- 2*35238bceSAndroid Build Coastguard Worker# drawElements CMake utilities 3*35238bceSAndroid Build Coastguard Worker# ---------------------------- 4*35238bceSAndroid Build Coastguard Worker# 5*35238bceSAndroid Build Coastguard Worker# Copyright 2014 The Android Open Source Project 6*35238bceSAndroid Build Coastguard Worker# 7*35238bceSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 8*35238bceSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 9*35238bceSAndroid Build Coastguard Worker# You may obtain a copy of the License at 10*35238bceSAndroid Build Coastguard Worker# 11*35238bceSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 12*35238bceSAndroid Build Coastguard Worker# 13*35238bceSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 14*35238bceSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 15*35238bceSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16*35238bceSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 17*35238bceSAndroid Build Coastguard Worker# limitations under the License. 18*35238bceSAndroid Build Coastguard Worker# 19*35238bceSAndroid Build Coastguard Worker#------------------------------------------------------------------------- 20*35238bceSAndroid Build Coastguard Worker 21*35238bceSAndroid Build Coastguard Worker# \note Always include this file in main project file, with NO_POLICY_SCOPE 22*35238bceSAndroid Build Coastguard Worker# AFTER project(name) statement. 23*35238bceSAndroid Build Coastguard Worker# 24*35238bceSAndroid Build Coastguard Worker# project(deproject) 25*35238bceSAndroid Build Coastguard Worker# include(delibs/cmake/Defs.cmake NO_POLICY_SCOPE) 26*35238bceSAndroid Build Coastguard Worker 27*35238bceSAndroid Build Coastguard Workercmake_policy(VERSION 3.10.2) 28*35238bceSAndroid Build Coastguard Worker 29*35238bceSAndroid Build Coastguard Worker# \todo [pyry] More intelligent detection, perhaps use some script? 30*35238bceSAndroid Build Coastguard Worker 31*35238bceSAndroid Build Coastguard Worker# cmake files can use DE_DEFS variable to check that this file has been included 32*35238bceSAndroid Build Coastguard Workerset(DE_DEFS 1) 33*35238bceSAndroid Build Coastguard Worker 34*35238bceSAndroid Build Coastguard Workermacro (DE_MAKE_ENV_BOOL BASE VALUE) 35*35238bceSAndroid Build Coastguard Worker if (${BASE} STREQUAL ${BASE}_${VALUE}) 36*35238bceSAndroid Build Coastguard Worker set(${BASE}_IS_${VALUE} 1) 37*35238bceSAndroid Build Coastguard Worker else () 38*35238bceSAndroid Build Coastguard Worker set(${BASE}_IS_${VALUE} 0) 39*35238bceSAndroid Build Coastguard Worker endif () 40*35238bceSAndroid Build Coastguard Workerendmacro () 41*35238bceSAndroid Build Coastguard Worker 42*35238bceSAndroid Build Coastguard Worker# Add build type RelWithAsserts 43*35238bceSAndroid Build Coastguard Workerset(CMAKE_CXX_FLAGS_RELWITHASSERTS ${CMAKE_CXX_FLAGS_RELEASE}) 44*35238bceSAndroid Build Coastguard Workerset(CMAKE_C_FLAGS_RELWITHASSERTS ${CMAKE_C_FLAGS_RELEASE}) 45*35238bceSAndroid Build Coastguard Workerset(CMAKE_EXE_LINKER_FLAGS_RELWITHASSERTS ${CMAKE_EXE_LINKER_FLAGS_RELEASE}) 46*35238bceSAndroid Build Coastguard Workerset(CMAKE_SHARED_LINKER_FLAGS_RELWITHASSERTS ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}) 47*35238bceSAndroid Build Coastguard Worker 48*35238bceSAndroid Build Coastguard Worker# Os detection 49*35238bceSAndroid Build Coastguard Workerif (NOT DEFINED DE_OS) 50*35238bceSAndroid Build Coastguard Worker if (WIN32) 51*35238bceSAndroid Build Coastguard Worker set(DE_OS "DE_OS_WIN32") 52*35238bceSAndroid Build Coastguard Worker elseif (APPLE) 53*35238bceSAndroid Build Coastguard Worker set(DE_OS "DE_OS_OSX") 54*35238bceSAndroid Build Coastguard Worker elseif (UNIX) 55*35238bceSAndroid Build Coastguard Worker set(DE_OS "DE_OS_UNIX") 56*35238bceSAndroid Build Coastguard Worker else () 57*35238bceSAndroid Build Coastguard Worker set(DE_OS "DE_OS_VANILLA") 58*35238bceSAndroid Build Coastguard Worker endif () 59*35238bceSAndroid Build Coastguard Workerendif () 60*35238bceSAndroid Build Coastguard Worker 61*35238bceSAndroid Build Coastguard Worker# DE_OS_IS_{PLATFORM} definitions 62*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_OS" "VANILLA") 63*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_OS" "WIN32") 64*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_OS" "UNIX") 65*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_OS" "WINCE") 66*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_OS" "OSX") 67*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_OS" "ANDROID") 68*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_OS" "IOS") 69*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_OS" "FUCHSIA") 70*35238bceSAndroid Build Coastguard Worker 71*35238bceSAndroid Build Coastguard Worker# Prevent mixed compile with GCC and Clang 72*35238bceSAndroid Build Coastguard Workerif (NOT (CMAKE_C_COMPILER_ID MATCHES "GNU") EQUAL (CMAKE_CXX_COMPILER_ID MATCHES "GNU")) 73*35238bceSAndroid Build Coastguard Worker message(FATAL_ERROR "CMake C and CXX compilers do not match. Both or neither must be GNU.") 74*35238bceSAndroid Build Coastguard Workerelseif (NOT (CMAKE_C_COMPILER_ID MATCHES "Clang") EQUAL (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) 75*35238bceSAndroid Build Coastguard Worker message(FATAL_ERROR "CMake C and CXX compilers do not match. Both or neither must be Clang.") 76*35238bceSAndroid Build Coastguard Workerendif () 77*35238bceSAndroid Build Coastguard Worker 78*35238bceSAndroid Build Coastguard Worker# Compiler detection 79*35238bceSAndroid Build Coastguard Workerif (NOT DEFINED DE_COMPILER) 80*35238bceSAndroid Build Coastguard Worker if ((CMAKE_C_COMPILER_ID MATCHES "MSVC") OR MSVC) 81*35238bceSAndroid Build Coastguard Worker set(DE_COMPILER "DE_COMPILER_MSC") 82*35238bceSAndroid Build Coastguard Worker elseif (CMAKE_C_COMPILER_ID MATCHES "GNU") 83*35238bceSAndroid Build Coastguard Worker set(DE_COMPILER "DE_COMPILER_GCC") 84*35238bceSAndroid Build Coastguard Worker elseif (CMAKE_C_COMPILER_ID MATCHES "Clang") 85*35238bceSAndroid Build Coastguard Worker set(DE_COMPILER "DE_COMPILER_CLANG") 86*35238bceSAndroid Build Coastguard Worker 87*35238bceSAndroid Build Coastguard Worker # Guess based on OS 88*35238bceSAndroid Build Coastguard Worker elseif (DE_OS_IS_WIN32) 89*35238bceSAndroid Build Coastguard Worker set(DE_COMPILER "DE_COMPILER_MSC") 90*35238bceSAndroid Build Coastguard Worker elseif (DE_OS_IS_UNIX OR DE_OS_IS_ANDROID) 91*35238bceSAndroid Build Coastguard Worker set(DE_COMPILER "DE_COMPILER_GCC") 92*35238bceSAndroid Build Coastguard Worker elseif (DE_OS_IS_OSX OR DE_OS_IS_IOS) 93*35238bceSAndroid Build Coastguard Worker set(DE_COMPILER "DE_COMPILER_CLANG") 94*35238bceSAndroid Build Coastguard Worker 95*35238bceSAndroid Build Coastguard Worker else () 96*35238bceSAndroid Build Coastguard Worker set(DE_COMPILER "DE_COMPILER_VANILLA") 97*35238bceSAndroid Build Coastguard Worker endif () 98*35238bceSAndroid Build Coastguard Workerendif () 99*35238bceSAndroid Build Coastguard Worker 100*35238bceSAndroid Build Coastguard Worker# DE_COMPILER_IS_{COMPILER} definitions 101*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_COMPILER" "VANILLA") 102*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_COMPILER" "MSC") 103*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_COMPILER" "GCC") 104*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_COMPILER" "CLANG") 105*35238bceSAndroid Build Coastguard Worker 106*35238bceSAndroid Build Coastguard Worker# Pointer size detection 107*35238bceSAndroid Build Coastguard Workerif (NOT DEFINED DE_PTR_SIZE) 108*35238bceSAndroid Build Coastguard Worker if (DEFINED CMAKE_SIZEOF_VOID_P) 109*35238bceSAndroid Build Coastguard Worker set(DE_PTR_SIZE ${CMAKE_SIZEOF_VOID_P}) 110*35238bceSAndroid Build Coastguard Worker else () 111*35238bceSAndroid Build Coastguard Worker set(DE_PTR_SIZE 4) 112*35238bceSAndroid Build Coastguard Worker endif () 113*35238bceSAndroid Build Coastguard Workerendif () 114*35238bceSAndroid Build Coastguard Worker 115*35238bceSAndroid Build Coastguard Worker# CPU detection 116*35238bceSAndroid Build Coastguard Workerif (NOT DEFINED DE_CPU) 117*35238bceSAndroid Build Coastguard Worker if (DE_PTR_SIZE EQUAL 8) 118*35238bceSAndroid Build Coastguard Worker set(DE_CPU "DE_CPU_X86_64") 119*35238bceSAndroid Build Coastguard Worker else () 120*35238bceSAndroid Build Coastguard Worker set(DE_CPU "DE_CPU_X86") 121*35238bceSAndroid Build Coastguard Worker endif () 122*35238bceSAndroid Build Coastguard Workerendif () 123*35238bceSAndroid Build Coastguard Worker 124*35238bceSAndroid Build Coastguard Worker# DE_CPU_IS_{CPU} definitions 125*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_CPU" "VANILLA") 126*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_CPU" "X86") 127*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_CPU" "ARM") 128*35238bceSAndroid Build Coastguard WorkerDE_MAKE_ENV_BOOL("DE_CPU" "ARM_64") 129*35238bceSAndroid Build Coastguard Worker 130*35238bceSAndroid Build Coastguard Worker# \note [petri] Re-wrote in this ugly manner, because CMake 2.6 seems to 131*35238bceSAndroid Build Coastguard Worker# barf about the parenthesis in the previous way. Ugh. 132*35238bceSAndroid Build Coastguard Worker#if (NOT ((DE_PTR_SIZE EQUAL 4) OR (DE_PTR_SIZE EQUAL 8))) 133*35238bceSAndroid Build Coastguard Workerif (DE_PTR_SIZE EQUAL 4) 134*35238bceSAndroid Build Coastguard Workerelseif (DE_PTR_SIZE EQUAL 8) 135*35238bceSAndroid Build Coastguard Workerelse () 136*35238bceSAndroid Build Coastguard Worker message(FATAL_ERROR "DE_PTR_SIZE (${DE_PTR_SIZE}) is invalid") 137*35238bceSAndroid Build Coastguard Workerendif () 138*35238bceSAndroid Build Coastguard Worker 139*35238bceSAndroid Build Coastguard Worker# Debug definitions 140*35238bceSAndroid Build Coastguard Workerif (NOT DEFINED DE_DEBUG) 141*35238bceSAndroid Build Coastguard Worker if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithAsserts") 142*35238bceSAndroid Build Coastguard Worker set(DE_DEBUG 1) 143*35238bceSAndroid Build Coastguard Worker else () 144*35238bceSAndroid Build Coastguard Worker set(DE_DEBUG 0) 145*35238bceSAndroid Build Coastguard Worker endif () 146*35238bceSAndroid Build Coastguard Workerendif () 147*35238bceSAndroid Build Coastguard Worker 148*35238bceSAndroid Build Coastguard Worker# Android API version 149*35238bceSAndroid Build Coastguard Workerif (DE_OS_IS_ANDROID AND NOT DEFINED DE_ANDROID_API) 150*35238bceSAndroid Build Coastguard Worker set(DE_ANDROID_API 5) 151*35238bceSAndroid Build Coastguard Workerendif () 152*35238bceSAndroid Build Coastguard Worker 153*35238bceSAndroid Build Coastguard Worker# MinGW 154*35238bceSAndroid Build Coastguard Workerif (CMAKE_CXX_COMPILER MATCHES ".*-mingw32-.*") 155*35238bceSAndroid Build Coastguard Worker set(DE_MINGW 1) 156*35238bceSAndroid Build Coastguard Worker set(BUILD_SHARED_LIBS OFF) 157*35238bceSAndroid Build Coastguard Workerelse() 158*35238bceSAndroid Build Coastguard Worker set(DE_MINGW 0) 159*35238bceSAndroid Build Coastguard Workerendif() 160*35238bceSAndroid Build Coastguard Worker 161*35238bceSAndroid Build Coastguard Workermessage(STATUS "DE_OS = ${DE_OS}") 162*35238bceSAndroid Build Coastguard Workermessage(STATUS "DE_COMPILER = ${DE_COMPILER}") 163*35238bceSAndroid Build Coastguard Workermessage(STATUS "DE_CPU = ${DE_CPU}") 164*35238bceSAndroid Build Coastguard Workermessage(STATUS "DE_PTR_SIZE = ${DE_PTR_SIZE}") 165*35238bceSAndroid Build Coastguard Workermessage(STATUS "DE_DEBUG = ${DE_DEBUG}") 166*35238bceSAndroid Build Coastguard Workerif (DE_OS_IS_ANDROID) 167*35238bceSAndroid Build Coastguard Worker message(STATUS "DE_ANDROID_API = ${DE_ANDROID_API}") 168*35238bceSAndroid Build Coastguard Workerendif () 169*35238bceSAndroid Build Coastguard Workermessage(STATUS "DE_MINGW = ${DE_MINGW}") 170*35238bceSAndroid Build Coastguard Worker 171*35238bceSAndroid Build Coastguard Worker# Expose definitions 172*35238bceSAndroid Build Coastguard Workerif (DE_DEBUG) 173*35238bceSAndroid Build Coastguard Worker add_definitions(-DDE_DEBUG) 174*35238bceSAndroid Build Coastguard Workerendif () 175*35238bceSAndroid Build Coastguard Worker 176*35238bceSAndroid Build Coastguard Workeradd_definitions("-DDE_OS=${DE_OS}") 177*35238bceSAndroid Build Coastguard Workeradd_definitions("-DDE_COMPILER=${DE_COMPILER}") 178*35238bceSAndroid Build Coastguard Workeradd_definitions("-DDE_CPU=${DE_CPU}") 179*35238bceSAndroid Build Coastguard Workeradd_definitions("-DDE_PTR_SIZE=${DE_PTR_SIZE}") 180*35238bceSAndroid Build Coastguard Workeradd_definitions("-DDE_MINGW=${DE_MINGW}") 181*35238bceSAndroid Build Coastguard Worker 182*35238bceSAndroid Build Coastguard Worker 183*35238bceSAndroid Build Coastguard Workerinclude(CheckCSourceCompiles) 184*35238bceSAndroid Build Coastguard Workerset(FENV_ACCESS_PRAGMA "") 185*35238bceSAndroid Build Coastguard Worker 186*35238bceSAndroid Build Coastguard Workermacro(check_fenv_access_support PRAGMA) 187*35238bceSAndroid Build Coastguard Worker if (DE_COMPILER_IS_CLANG OR DE_COMPILER_IS_GCC) 188*35238bceSAndroid Build Coastguard Worker set(CMAKE_REQUIRED_FLAGS "-Wall") 189*35238bceSAndroid Build Coastguard Worker endif () 190*35238bceSAndroid Build Coastguard Worker # In addition to failing the test if "unknown-pragmas" is 191*35238bceSAndroid Build Coastguard Worker # given, also fail if "ignored-pragmas" is generated, 192*35238bceSAndroid Build Coastguard Worker # indicating the platform does not support the pragma, which 193*35238bceSAndroid Build Coastguard Worker # currently happens on 32-bit ARM builds with Clang. 194*35238bceSAndroid Build Coastguard Worker check_c_source_compiles(" 195*35238bceSAndroid Build Coastguard Worker#include <fenv.h> 196*35238bceSAndroid Build Coastguard Worker${PRAGMA} 197*35238bceSAndroid Build Coastguard Workerint main() { 198*35238bceSAndroid Build Coastguard Worker#ifdef FE_INEXACT 199*35238bceSAndroid Build Coastguard Worker return 0; 200*35238bceSAndroid Build Coastguard Worker#else 201*35238bceSAndroid Build Coastguard Worker #error \"FENV_ACCESS not available\" 202*35238bceSAndroid Build Coastguard Worker#endif 203*35238bceSAndroid Build Coastguard Worker}" HAVE_FENV_ACCESS FAIL_REGEX "unknown-pragmas" "ignored-pragmas") 204*35238bceSAndroid Build Coastguard Worker if (HAVE_FENV_ACCESS) 205*35238bceSAndroid Build Coastguard Worker set(FENV_ACCESS_PRAGMA ${PRAGMA}) 206*35238bceSAndroid Build Coastguard Worker endif() 207*35238bceSAndroid Build Coastguard Workerendmacro() 208*35238bceSAndroid Build Coastguard Worker 209*35238bceSAndroid Build Coastguard Workerif (DE_COMPILER_IS_MSC) 210*35238bceSAndroid Build Coastguard Worker check_fenv_access_support("__pragma(fenv_access (on))") 211*35238bceSAndroid Build Coastguard Workerelseif (DE_COMPILER_IS_CLANG OR DE_COMPILER_IS_GCC) 212*35238bceSAndroid Build Coastguard Worker # Note that GCC does not provide a way to inform the implementation of FP environment access. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34678. 213*35238bceSAndroid Build Coastguard Worker # Until that is implemented this check will never enable the FENV_ACCESS pragma. 214*35238bceSAndroid Build Coastguard Worker check_fenv_access_support("_Pragma(\"STDC FENV_ACCESS ON\")") 215*35238bceSAndroid Build Coastguard Workerelse () 216*35238bceSAndroid Build Coastguard Worker message(FATAL_ERROR "Unsupported compiler!") 217*35238bceSAndroid Build Coastguard Workerendif () 218*35238bceSAndroid Build Coastguard Worker 219*35238bceSAndroid Build Coastguard Workeradd_definitions("-DDE_FENV_ACCESS_ON=${FENV_ACCESS_PRAGMA}") 220*35238bceSAndroid Build Coastguard Worker 221*35238bceSAndroid Build Coastguard Workerif (DE_OS_IS_ANDROID) 222*35238bceSAndroid Build Coastguard Worker add_definitions("-DDE_ANDROID_API=${DE_ANDROID_API}") 223*35238bceSAndroid Build Coastguard Workerendif () 224