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