@@ -7,197 +7,9 @@ cmake_minimum_required(VERSION 3.20)
7
7
cmake_policy (SET CMP0072 OLD ) #not yet, would need to get pointers to all OpenGL functions
8
8
set (OpenGL_GL_PREFERENCE LEGACY )
9
9
#cmake_policy(SET CMP )
10
- set (NBL_BUILD_ANDROID OFF )
11
10
12
- if (DEFINED CMAKE_TOOLCHAIN_FILE )
13
-
14
- if (EXISTS "${CMAKE_TOOLCHAIN_FILE} " )
15
- cmake_path (GET CMAKE_TOOLCHAIN_FILE FILENAME _NBL_CMAKE_TOOLCHAIN_FILENAME_ )
16
- else ()
17
- message (FATAL_ERROR "CMAKE_TOOLCHAIN_FILE as '${CMAKE_TOOLCHAIN_FILE} ' is invalid!" )
18
- endif ()
19
-
20
- if (${_NBL_CMAKE_TOOLCHAIN_FILENAME_} STREQUAL "android.toolchain.cmake" )
21
- message (STATUS "Found Android toolchain! Validating..." )
22
-
23
- set (_NBL_SUPPORTED_ABI_
24
- "x86_64"
25
- # "arm64-v8a" in future
26
- )
27
-
28
- if (DEFINED ANDROID_ABI ) # see _NBL_SUPPORTED_ABI_
29
- set (FOUND 0 )
30
- foreach (CURRENT_ABI IN LISTS _NBL_SUPPORTED_ABI_ )
31
- if ("${CURRENT_ABI} " STREQUAL ${ANDROID_ABI} )
32
- message (STATUS "Selecting found ${CURRENT_ABI} ABI!" )
33
- set (FOUND 1 )
34
- break ()
35
- endif ()
36
- endforeach ()
37
-
38
- if (NOT FOUND )
39
- message (FATAL_ERROR "Selected ${ANDROID_ABI} isn't appropriate. Supported ABIs: ${_NBL_SUPPORTED_ABI_} !" )
40
- else ()
41
- unset (FOUND )
42
- endif ()
43
- else ()
44
- message (FATAL_ERROR "ANDROID_ABI must be specified at the very beginning of execution!" )
45
- endif ()
46
-
47
- if (NOT DEFINED ANDROID_PLATFORM ) # android-28
48
- message (FATAL_ERROR "ANDROID_PLATFORM must be specified at the very beginning of execution!" )
49
- endif ()
50
-
51
- include (${CMAKE_TOOLCHAIN_FILE} )
52
-
53
- if (${ANDROID_NDK_MAJOR} LESS 22 )
54
- message (FATAL_ERROR "Update your NDK to at least 22. We don't support ${ANDROID_NDK_REVISION} NDK version!" )
55
- endif ()
56
-
57
- # note that we assume NDK has been installed using Android Studio, so the existing paths should look as followning:
58
- # ${ANDROID_SDK_ROOT_PATH}/ndk/${ANDROID_NDK_REVISION}/build/cmake/android.toolchain.cmake
59
-
60
- set (ANDROID_NDK_ROOT_PATH ${CMAKE_ANDROID_NDK} )
61
- get_filename_component (ANDROID_SDK_ROOT_PATH "${ANDROID_NDK_ROOT_PATH} /../../" ABSOLUTE )
62
-
63
- if (EXISTS "${ANDROID_SDK_ROOT_PATH} /build-tools" )
64
- message (STATUS "Building Nabla with ${ANDROID_NDK_REVISION} NDK!" )
65
- endif ()
66
-
67
- set (NBL_BUILD_ANDROID ON )
68
- set (_NBL_ANDROID_VALIDATED_ ON )
69
- endif ()
70
-
71
- # TODO - another toolchains in future
72
-
73
- endif ()
74
-
75
- if (NBL_BUILD_ANDROID )
76
- if (NOT DEFINED _NBL_ANDROID_VALIDATED_ )
77
- message (FATAL_ERROR "Android toolchain hasn't been validated properly. Pass an appropriate path to CMAKE_TOOLCHAIN_FILE!" )
78
- endif ()
79
-
80
- if ("${CMAKE_HOST_SYSTEM_NAME} " STREQUAL "Linux" )
81
- message (STATUS "Using Linux as a host OS for Android cross-compiling!" )
82
- elseif ("${CMAKE_HOST_SYSTEM_NAME} " STREQUAL "Windows" )
83
- message (STATUS "Using Windows as a host OS for Android cross-compiling!" )
84
- else ()
85
- message (FATAL_ERROR "Current host OS for Android cross-compiling isn't allowed!" )
86
- endif ()
87
-
88
- # TODO - remove those bellow in future
89
- set (_NBL_COMPILE_WITH_OPEN_EXR_ OFF CACHE BOOL "Off for Android purposes at the moment" FORCE ) # TODO - check it out
90
- set (_NBL_COMPILE_WITH_BAW_LOADER_ OFF CACHE BOOL "Off for Android purposes at the moment" FORCE ) # TODO - remove when BAW-v4 is done
91
- set (_NBL_COMPILE_WITH_BAW_WRITER_ OFF CACHE BOOL "Off for Android purposes at the moment" FORCE ) # TODO - remove when BAW-v4 is done
92
- set (_NBL_COMPILE_WITH_OBJ_LOADER_ ON CACHE BOOL "Off for Android purposes at the moment" FORCE )
93
- set (NBL_BUILD_MITSUBA_LOADER OFF CACHE BOOL "Off for Android purposes at the moment" FORCE ) # TODO - compile/linker errors
94
-
95
- find_package (Java 1.8 )
96
-
97
- if (DEFINED Java_JAVA_EXECUTABLE )
98
- message (STATUS "Found Java executable!: ${Java_JAVA_EXECUTABLE} " )
99
- else ()
100
- message (FATAL_ERROR "Could not find java executable for Android build!" )
101
- endif ()
102
-
103
- string (LENGTH ${Java_JAVA_EXECUTABLE} Java_JAVA_EXECUTABLE_LENGTH )
104
- if (MSVC )
105
- set (Java_JAVA_EXE_BIN_LENGTH 13 )
106
- else ()
107
- set (Java_JAVA_EXE_BIN_LENGTH 9 )
108
- endif ()
109
- math (EXPR JAVA_HOME_LENGTH "${Java_JAVA_EXECUTABLE_LENGTH} - ${Java_JAVA_EXE_BIN_LENGTH} " OUTPUT_FORMAT DECIMAL )
110
- string (SUBSTRING ${Java_JAVA_EXECUTABLE} 0 ${JAVA_HOME_LENGTH} JAVA_HOME )
111
-
112
- message (STATUS "Using JAVA_HOME = ${JAVA_HOME} " )
113
-
114
- execute_process (COMMAND ${JAVA_HOME} /bin/java -version
115
- RESULT_VARIABLE _result
116
- OUTPUT_VARIABLE _output
117
- ERROR_VARIABLE _output
118
- OUTPUT_STRIP_TRAILING_WHITESPACE
119
- ERROR_STRIP_TRAILING_WHITESPACE )
120
-
121
- if (NOT _result AND _output MATCHES "version \" ([0-9]+).([0-9]+)" )
122
- message (STATUS "Java in JAVA_HOME is ${CMAKE_MATCH_1} .${CMAKE_MATCH_2} " )
123
- else ()
124
- message (STATUS "Java in JAVA_HOME is unknown version ${_output} ${_result} " )
125
- endif ()
126
-
127
- #option(STRIP_ANDROID_LIBRARY "Strip the resulting android library" OFF)
128
-
129
- string (SUBSTRING
130
- "${ANDROID_PLATFORM} "
131
- 8 # length of "android-"
132
- -1 # take remainder
133
- ANDROID_API_LEVEL
134
- )
135
-
136
- # default to libc++_static as the other options can cause crashes
137
- if (NOT ANDROID_STL )
138
- set (ANDROID_STL "c++_static" )
139
- endif ()
140
-
141
- # Choose clang if the NDK has both gcc and clang, since gcc sometimes fails
142
- # iirc api levels > 21 have only clang available
143
- set (CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION "clang" )
144
-
145
- #
146
- # android-specific utils and build tools
147
- #
148
- set (ANDROID_BUILD_TOOLS_VERSION "" CACHE STRING "Version of Android build-tools to use instead of the default" )
149
- # take most recent version of build tools, if not set explicitely
150
- if (ANDROID_BUILD_TOOLS_VERSION STREQUAL "" )
151
- file (GLOB __buildTools RELATIVE "${ANDROID_SDK_ROOT_PATH} /build-tools" "${ANDROID_SDK_ROOT_PATH} /build-tools/*" )
152
- list (SORT __buildTools )
153
-
154
- list (GET __buildTools -1 ANDROID_BUILD_TOOLS_VERSION )
155
-
156
- unset (__buildTools )
157
- endif ()
158
- set (ANDROID_BUILD_TOOLS "${ANDROID_SDK_ROOT_PATH} /build-tools/${ANDROID_BUILD_TOOLS_VERSION} " )
159
- if (MSVC )
160
- set (ANDROID_JAVA_BIN "${JAVA_HOME} " )
161
- else ()
162
- set (ANDROID_JAVA_BIN "${JAVA_HOME} /bin" )
163
- endif ()
164
- set (ANDROID_JAVA_RT_JAR "${JAVA_HOME} /jre/lib/rt.jar" )
165
-
166
- set (ANDROID_APK_TARGET_ID "" CACHE STRING "The Target ID to build the APK for like 'android-99', use <android list targets> to choose another one." )
167
- if (ANDROID_APK_TARGET_ID STREQUAL "" )
168
- # This seems different from the platform we're targetting,
169
- # default to the latest available that's greater or equal to our target platform
170
- file (GLOB __platforms RELATIVE "${ANDROID_SDK_ROOT_PATH} /platforms" "${ANDROID_SDK_ROOT_PATH} /platforms/*" )
171
- list (SORT __platforms )
172
-
173
- # In case we don't find one, target the latest platform
174
- list (GET __platforms -1 ANDROID_APK_TARGET_ID )
175
-
176
- string (REPLACE "android-" "" __targetPlat "${ANDROID_PLATFORM} " )
177
-
178
- # TODO we might want to adjust min version in the future
179
- # We require at least android 23 for Activity.requestPermissions
180
- if (__targetPlat LESS 23 )
181
- set (__targetPlat 23 )
182
- endif ()
183
-
184
- foreach ( __plat ${__platforms} )
185
- string (REPLACE "android-" "" __curPlat "${__plat} " )
186
-
187
- if (NOT (__curPlat LESS __targetPlat ) )
188
- set (ANDROID_APK_TARGET_ID "android-${__curPlat} " )
189
- break ()
190
- endif ()
191
- endforeach ()
192
-
193
- unset (__platforms )
194
- unset (__targetPlat )
195
- unset (__curPlat )
196
- endif ()
197
-
198
- message (STATUS "Using android.jar from platform ${ANDROID_APK_TARGET_ID} " )
199
- set (ANDROID_JAR "${ANDROID_SDK_ROOT_PATH} /platforms/${ANDROID_APK_TARGET_ID} /android.jar" )
200
- endif ()
11
+ include (ExternalProject )
12
+ include (${CMAKE_CURRENT_SOURCE_DIR} /cmake/toolchains/android/build.cmake )
201
13
202
14
project (Nabla LANGUAGES CXX C )
203
15
0 commit comments