blob: d0d2c42eb61fd8ff8445c00e695d56f5bbaa75da (
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
|
set(USE_GLES2 ON)
include(cmake/sqlite.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>")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections")
if ((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()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--version-script=${CMAKE_SOURCE_DIR}/platform/android/version-script")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--version-script=${CMAKE_SOURCE_DIR}/platform/android/version-script")
# Use LTO in Release builds. Due to a toolchain issue, -O2 is also required for the link step (https://github.com/android-ndk/ndk/issues/721)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -flto")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -flto")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto -O2")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -flto -O2")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} -flto -O2")
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} -flto -O2")
## mbgl core ##
macro(mbgl_platform_core)
# Modify platform/android/core-files.json to change the source files for this target.
target_sources_from_file(mbgl-core PRIVATE platform/android/core-files.json)
target_include_directories(mbgl-core
PUBLIC platform/default/include
PRIVATE platform/android/include
)
target_link_libraries(mbgl-core
PUBLIC jni.hpp
PUBLIC -llog
PUBLIC -landroid
PUBLIC -ljnigraphics
PUBLIC -lEGL
PUBLIC -lGLESv2
PUBLIC -lstdc++
PUBLIC -latomic
PUBLIC -lz
)
endmacro()
macro(mbgl_filesource)
# Modify platform/android/filesource-files.json to change the source files for this target.
target_sources_from_file(mbgl-filesource PRIVATE platform/android/filesource-files.json)
target_link_libraries(mbgl-filesource
PUBLIC sqlite
PUBLIC jni.hpp
PUBLIC -llog
PUBLIC -landroid
PUBLIC -lstdc++
PUBLIC -latomic
)
endmacro()
## Shared library
add_library(mapbox-gl SHARED
platform/android/src/main.cpp
)
target_include_directories(mapbox-gl
PRIVATE src
)
target_link_libraries(mapbox-gl
PRIVATE mbgl-core
PRIVATE mbgl-filesource
)
## Test executable ##
macro(mbgl_platform_test)
target_sources(mbgl-test
PRIVATE platform/android/src/test/test_runner.cpp
PRIVATE platform/android/src/test/runtime.cpp
)
target_include_directories(mbgl-test
PRIVATE platform/android/include
)
set_target_properties(mbgl-test
PROPERTIES
LINK_FLAGS
"-fPIE -pie \
-Wl,--export-dynamic \
-Wl,--version-script=${CMAKE_SOURCE_DIR}/platform/android/src/test/version-script")
target_link_libraries(mbgl-test
PRIVATE mbgl-filesource
)
endmacro()
## Benchmark ##
macro(mbgl_platform_benchmark)
target_sources(mbgl-benchmark
PRIVATE platform/android/src/test/benchmark_runner.cpp
PRIVATE platform/android/src/test/runtime.cpp
)
set_target_properties(mbgl-benchmark
PROPERTIES
LINK_FLAGS
"-fPIE -pie \
-Wl,--export-dynamic \
-Wl,--version-script=${CMAKE_SOURCE_DIR}/platform/android/src/test/version-script")
target_link_libraries(mbgl-benchmark
PRIVATE mbgl-filesource
)
endmacro()
## Custom layer example ##
add_library(example-custom-layer SHARED
platform/android/src/example_custom_layer.cpp
)
target_include_directories(example-custom-layer
PRIVATE include
)
target_link_libraries(example-custom-layer
PRIVATE -llog
PRIVATE -lGLESv2
)
|