summaryrefslogtreecommitdiff
path: root/platform/android/config.cmake
blob: 3dd8e7f67d84938fdd0159b238d864b81356d499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
add_definitions(-DMBGL_USE_GLES2=1)

include(cmake/test-files.cmake)

# Build thin archives.
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> cruT <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> cruT <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> ruT <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> ruT <TARGET> <LINK_FLAGS> <OBJECTS>")

if ((ANDROID_ABI STREQUAL "armeabi") OR (ANDROID_ABI STREQUAL "armeabi-v7a") OR (ANDROID_ABI STREQUAL "arm64-v8a") OR
    (ANDROID_ABI STREQUAL "x86") OR (ANDROID_ABI STREQUAL "x86_64"))
    # Use Identical Code Folding on platforms that support the gold linker.
    set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=gold -Wl,--icf=safe ${CMAKE_EXE_LINKER_FLAGS}")
    set(CMAKE_SHARED_LINKER_FLAGS "-fuse-ld=gold -Wl,--icf=safe ${CMAKE_SHARED_LINKER_FLAGS}")
endif()

mason_use(jni.hpp VERSION 3.0.0 HEADER_ONLY)
mason_use(libzip VERSION 1.1.3)
mason_use(nunicode VERSION 1.7.1)
mason_use(sqlite VERSION 3.14.2)
mason_use(gtest VERSION 1.8.0)
mason_use(icu VERSION 58.1-min-size)

set(ANDROID_SDK_PROJECT_DIR ${CMAKE_SOURCE_DIR}/platform/android/MapboxGLAndroidSDK)
set(ANDROID_JNI_TARGET_DIR ${ANDROID_SDK_PROJECT_DIR}/src/main/jniLibs/${ANDROID_ABI})
set(ANDROID_ASSETS_TARGET_DIR ${ANDROID_SDK_PROJECT_DIR}/src/main/assets)
set(ANDROID_TEST_APP_JNI_TARGET_DIR ${CMAKE_SOURCE_DIR}/platform/android/MapboxGLAndroidSDKTestApp/src/main/jniLibs/${ANDROID_ABI})

if (NOT DEFINED ANDROID_TOOLCHAIN_PREFIX)
    set(ANDROID_TOOLCHAIN_PREFIX "${MASON_XC_ROOT}/bin/${ANDROID_TOOLCHAIN}-")
endif()

## mbgl core ##

macro(mbgl_platform_core)

    target_sources(mbgl-core
        # Loop
        PRIVATE platform/android/src/thread.cpp
        PRIVATE platform/android/src/async_task.cpp
        PRIVATE platform/android/src/run_loop.cpp
        PRIVATE platform/android/src/run_loop_impl.hpp
        PRIVATE platform/android/src/timer.cpp

        # File source
        PRIVATE platform/android/src/asset_file_source.cpp
        PRIVATE platform/android/src/http_file_source.cpp
        PRIVATE platform/default/default_file_source.cpp
        PRIVATE platform/default/local_file_source.cpp
        PRIVATE platform/default/online_file_source.cpp

        # Offline
        # PRIVATE include/mbgl/storage/offline.hpp
        PRIVATE platform/default/mbgl/storage/offline.cpp
        PRIVATE platform/default/mbgl/storage/offline_database.cpp
        PRIVATE platform/default/mbgl/storage/offline_database.hpp
        PRIVATE platform/default/mbgl/storage/offline_download.cpp
        PRIVATE platform/default/mbgl/storage/offline_download.hpp
        PRIVATE platform/default/sqlite3.cpp
        PRIVATE platform/default/sqlite3.hpp

        # Misc
        PRIVATE platform/android/src/logging_android.cpp
        PRIVATE platform/default/string_stdlib.cpp
        PRIVATE platform/default/bidi.cpp
        PRIVATE platform/default/utf.cpp

        # Image handling
        PRIVATE platform/default/png_writer.cpp
        PRIVATE platform/android/src/bitmap.cpp
        PRIVATE platform/android/src/bitmap.hpp
        PRIVATE platform/android/src/bitmap_factory.cpp
        PRIVATE platform/android/src/bitmap_factory.hpp
        PRIVATE platform/android/src/image.cpp

        # Thread pool
        PRIVATE platform/default/mbgl/util/shared_thread_pool.cpp
        PRIVATE platform/default/mbgl/util/shared_thread_pool.hpp
        PRIVATE platform/default/mbgl/util/default_thread_pool.cpp
        PRIVATE platform/default/mbgl/util/default_thread_pool.hpp

        # Conversion C++ -> Java
        platform/android/src/conversion/constant.hpp
        platform/android/src/conversion/conversion.hpp
        platform/android/src/style/conversion/function.hpp
        platform/android/src/style/conversion/property_value.hpp
        platform/android/src/style/conversion/types.hpp
        platform/android/src/style/conversion/types_string_values.hpp

        # Style conversion Java -> C++
        platform/android/src/style/android_conversion.hpp
        platform/android/src/style/conversion/geojson.hpp
        platform/android/src/style/value.cpp
        platform/android/src/style/value.hpp
        platform/android/src/style/conversion/url_or_tileset.hpp

        # Style
        platform/android/src/style/layers/background_layer.cpp
        platform/android/src/style/layers/background_layer.hpp
        platform/android/src/style/layers/circle_layer.cpp
        platform/android/src/style/layers/circle_layer.hpp
        platform/android/src/style/layers/custom_layer.cpp
        platform/android/src/style/layers/custom_layer.hpp
        platform/android/src/style/layers/fill_layer.cpp
        platform/android/src/style/layers/fill_layer.hpp
        platform/android/src/style/layers/layer.cpp
        platform/android/src/style/layers/layer.hpp
        platform/android/src/style/layers/layers.cpp
        platform/android/src/style/layers/layers.hpp
        platform/android/src/style/layers/line_layer.cpp
        platform/android/src/style/layers/line_layer.hpp
        platform/android/src/style/layers/raster_layer.cpp
        platform/android/src/style/layers/raster_layer.hpp
        platform/android/src/style/layers/symbol_layer.cpp
        platform/android/src/style/layers/symbol_layer.hpp
        platform/android/src/style/layers/unknown_layer.cpp
        platform/android/src/style/layers/unknown_layer.hpp
        platform/android/src/style/sources/geojson_source.cpp
        platform/android/src/style/sources/geojson_source.hpp
        platform/android/src/style/sources/source.cpp
        platform/android/src/style/sources/source.hpp
        platform/android/src/style/sources/sources.cpp
        platform/android/src/style/sources/sources.hpp
        platform/android/src/style/sources/raster_source.cpp
        platform/android/src/style/sources/raster_source.hpp
        platform/android/src/style/sources/unknown_source.cpp
        platform/android/src/style/sources/unknown_source.hpp
        platform/android/src/style/sources/vector_source.cpp
        platform/android/src/style/sources/vector_source.hpp
        platform/android/src/style/functions/stop.cpp
        platform/android/src/style/functions/stop.hpp
        platform/android/src/style/functions/categorical_stops.cpp
        platform/android/src/style/functions/categorical_stops.hpp
        platform/android/src/style/functions/exponential_stops.cpp
        platform/android/src/style/functions/exponential_stops.hpp
        platform/android/src/style/functions/identity_stops.cpp
        platform/android/src/style/functions/identity_stops.hpp
        platform/android/src/style/functions/interval_stops.cpp
        platform/android/src/style/functions/interval_stops.hpp

        # FileSource holder
        platform/android/src/file_source.cpp
        platform/android/src/file_source.hpp

        # Connectivity
        platform/android/src/connectivity_listener.cpp
        platform/android/src/connectivity_listener.hpp

        # Native map
        platform/android/src/native_map_view.cpp
        platform/android/src/native_map_view.hpp

        # Java core classes
        platform/android/src/java/util.cpp
        platform/android/src/java/util.hpp

        # Graphics
        platform/android/src/graphics/pointf.cpp
        platform/android/src/graphics/pointf.hpp
        platform/android/src/graphics/rectf.cpp
        platform/android/src/graphics/rectf.hpp

        # Geometry
        platform/android/src/geometry/feature.cpp
        platform/android/src/geometry/feature.hpp
        platform/android/src/geometry/lat_lng.cpp
        platform/android/src/geometry/lat_lng.hpp
        platform/android/src/geometry/lat_lng_bounds.cpp
        platform/android/src/geometry/lat_lng_bounds.hpp
        platform/android/src/geometry/projected_meters.cpp
        platform/android/src/geometry/projected_meters.hpp

        # Annotation
        platform/android/src/annotation/marker.cpp
        platform/android/src/annotation/marker.hpp
        platform/android/src/annotation/polygon.cpp
        platform/android/src/annotation/polygon.hpp
        platform/android/src/annotation/polyline.cpp
        platform/android/src/annotation/polyline.hpp

        # Offline
        platform/android/src/offline/offline_manager.cpp
        platform/android/src/offline/offline_manager.hpp
        platform/android/src/offline/offline_region.cpp
        platform/android/src/offline/offline_region.hpp
        platform/android/src/offline/offline_region_definition.cpp
        platform/android/src/offline/offline_region_definition.hpp
        platform/android/src/offline/offline_region_error.cpp
        platform/android/src/offline/offline_region_error.hpp
        platform/android/src/offline/offline_region_status.cpp
        platform/android/src/offline/offline_region_status.hpp

        # Main jni bindings
        platform/android/src/attach_env.cpp
        platform/android/src/attach_env.hpp
        platform/android/src/java_types.cpp
        platform/android/src/java_types.hpp

        # Main entry point
        platform/android/src/jni.hpp
        platform/android/src/jni.cpp
    )

    target_include_directories(mbgl-core
        PUBLIC platform/default
    )

    target_add_mason_package(mbgl-core PUBLIC sqlite)
    target_add_mason_package(mbgl-core PUBLIC nunicode)
    target_add_mason_package(mbgl-core PUBLIC libzip)
    target_add_mason_package(mbgl-core PUBLIC geojson)
    target_add_mason_package(mbgl-core PUBLIC jni.hpp)
    target_add_mason_package(mbgl-core PUBLIC rapidjson)
    target_add_mason_package(mbgl-core PUBLIC icu)

    target_compile_options(mbgl-core
        PRIVATE -fvisibility=hidden
        PRIVATE -ffunction-sections
        PRIVATE -fdata-sections
    )

    target_link_libraries(mbgl-core
        PUBLIC -llog
        PUBLIC -landroid
        PUBLIC -ljnigraphics
        PUBLIC -lEGL
        PUBLIC -lGLESv2
        PUBLIC -lstdc++
        PUBLIC -latomic
        PUBLIC -lz
        PUBLIC -Wl,--gc-sections
    )
endmacro()

## Main library ##

add_library(mapbox-gl SHARED
    platform/android/src/main.cpp
)

target_compile_options(mapbox-gl
    PRIVATE -fvisibility=hidden
    PRIVATE -ffunction-sections
    PRIVATE -fdata-sections
)

target_link_libraries(mapbox-gl
    PUBLIC mbgl-core
    PUBLIC -Wl,--gc-sections
)

# Create a stripped version of the library and copy it to the JNIDIR.
add_custom_command(TARGET mapbox-gl POST_BUILD
                   COMMAND ${CMAKE_COMMAND} -E make_directory ${ANDROID_JNI_TARGET_DIR}
                   COMMAND ${ANDROID_TOOLCHAIN_PREFIX}strip $<TARGET_FILE:mapbox-gl> -o ${ANDROID_JNI_TARGET_DIR}/$<TARGET_FILE_NAME:mapbox-gl>)

## Test library ##

add_library(mbgl-test SHARED
    # Actual tests
    ${MBGL_TEST_FILES}

    # Main test entry point
    platform/android/src/test/main.jni.cpp

)

add_dependencies(mbgl-test
    mapbox-gl
)

target_sources(mbgl-test
    # Headless view
    PRIVATE platform/default/mbgl/gl/headless_backend.cpp
    PRIVATE platform/default/mbgl/gl/headless_backend.hpp
    PRIVATE platform/default/mbgl/gl/offscreen_view.cpp
    PRIVATE platform/default/mbgl/gl/offscreen_view.hpp

    PRIVATE platform/linux/src/headless_backend_egl.cpp
    PRIVATE platform/linux/src/headless_display_egl.cpp
)

target_compile_options(mbgl-test
    PRIVATE -fvisibility=hidden
)

target_compile_definitions(mbgl-test
    PRIVATE MBGL_ASSET_ZIP=1
)

target_include_directories(mbgl-test
    PRIVATE include
    PRIVATE src # TODO: eliminate
    PRIVATE test/include
    PRIVATE test/src
    PRIVATE platform/default
)

target_link_libraries(mbgl-test
    PRIVATE mbgl-core
)

target_add_mason_package(mbgl-test PRIVATE geometry)
target_add_mason_package(mbgl-test PRIVATE variant)
target_add_mason_package(mbgl-test PRIVATE unique_resource)
target_add_mason_package(mbgl-test PRIVATE rapidjson)
target_add_mason_package(mbgl-test PRIVATE gtest)
target_add_mason_package(mbgl-test PRIVATE pixelmatch)
target_add_mason_package(mbgl-test PRIVATE boost)
target_add_mason_package(mbgl-test PRIVATE geojson)
target_add_mason_package(mbgl-test PRIVATE geojsonvt)

add_custom_command(TARGET mbgl-test POST_BUILD
                   COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/stripped
                   COMMAND ${ANDROID_TOOLCHAIN_PREFIX}strip $<TARGET_FILE:mapbox-gl> -o ${CMAKE_CURRENT_BINARY_DIR}/stripped/$<TARGET_FILE_NAME:mapbox-gl>
                   COMMAND ${ANDROID_TOOLCHAIN_PREFIX}strip $<TARGET_FILE:mbgl-test> -o ${CMAKE_CURRENT_BINARY_DIR}/stripped/$<TARGET_FILE_NAME:mbgl-test>)

## Custom layer example ##

add_library(example-custom-layer SHARED
    platform/android/src/example_custom_layer.cpp
)

target_compile_options(example-custom-layer
    PRIVATE -fvisibility=hidden
    PRIVATE -ffunction-sections
    PRIVATE -fdata-sections
)

target_link_libraries(example-custom-layer
    PRIVATE mapbox-gl
    PUBLIC -Wl,--gc-sections
)

add_custom_command(TARGET example-custom-layer POST_BUILD
                   COMMAND ${CMAKE_COMMAND} -E make_directory ${ANDROID_TEST_APP_JNI_TARGET_DIR}
                   COMMAND ${ANDROID_TOOLCHAIN_PREFIX}strip $<TARGET_FILE:example-custom-layer> -o ${ANDROID_TEST_APP_JNI_TARGET_DIR}/$<TARGET_FILE_NAME:example-custom-layer>)