-
Notifications
You must be signed in to change notification settings - Fork 453
/
CMakeLists.txt
320 lines (278 loc) · 10.1 KB
/
CMakeLists.txt
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
project(RNSkia)
cmake_minimum_required(VERSION 3.4.1)
set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 17)
set(SK_GRAPHITE OFF)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSK_BUILD_FOR_ANDROID -DSK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API -DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID -DONANDROID")
set (PACKAGE_NAME "rnskia")
set (SKIA_LIB "skia")
set (SKIA_SVG_LIB "svg")
set (SKIA_SKSHAPER_LIB "skshaper")
set (SKIA_SKPARAGRAPH_LIB "skparagraph")
set (SKIA_SKUNICODE_CORE_LIB "skunicode_core")
set (SKIA_SKUNICODE_ICU_LIB "skunicode_icu")
# Clear some variables
unset(LIBRN_DIR CACHE)
unset(libfbjni_link_DIRS CACHE)
unset(libfbjni_include_DIRS CACHE)
set(build_DIR ${CMAKE_SOURCE_DIR}/build)
file(GLOB LIBRN_DIR "${PREBUILT_DIR}/${ANDROID_ABI}")
file(GLOB libfbjni_link_DIRS "${build_DIR}/fbjni*.aar/jni/${ANDROID_ABI}")
file(GLOB libfbjni_include_DIRS "${build_DIR}/fbjni-*-headers.jar/")
message("-- ABI : " ${ANDROID_ABI})
message("-- PREBUILT: " ${PREBUILT_DIR})
message("-- BUILD : " ${build_DIR})
message("-- LIBRN : " ${LIBRN_DIR})
link_directories(../libs/android/${ANDROID_ABI}/)
# Import prebuilt SKIA libraries
set (SKIA_LIBS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../libs/android/${ANDROID_ABI}")
if(SK_GRAPHITE)
add_definitions(-DSK_GRAPHITE)
set(DAWN_NATIVE_LIB "libdawn_native_static")
set(DAWN_PLATFORM_LIB "libdawn_platform_static")
set(DAWN_PROC_LIB "libdawn_proc_static")
set(BACKEND_SOURCES
#TODO: is this source needed to be added?
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/DawnWindowContext.cpp"
)
add_library(libdawn_native_static STATIC IMPORTED)
set_property(TARGET libdawn_native_static PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libdawn_native_static.a")
add_library(libdawn_platform_static STATIC IMPORTED)
set_property(TARGET libdawn_platform_static PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libdawn_platform_static.a")
add_library(libdawn_proc_static STATIC IMPORTED)
set_property(TARGET libdawn_proc_static PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libdawn_proc_static.a")
else()
add_definitions(-DSK_GL -DSK_GANESH)
set(BACKEND_SOURCES
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/OpenGLWindowContext.cpp"
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/GrAHardwareBufferUtils.cpp"
)
endif()
if(${REACT_NATIVE_VERSION} LESS 66)
file(
TO_CMAKE_PATH
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp"
INCLUDE_JSI_CPP
)
endif()
add_library(
${PACKAGE_NAME}
SHARED
"${PROJECT_SOURCE_DIR}/cpp/jni/JniLoad.cpp"
"${PROJECT_SOURCE_DIR}/cpp/jni/JniSkiaManager.cpp"
"${PROJECT_SOURCE_DIR}/cpp/jni/JniPlatformContext.cpp"
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/gl/Error.cpp"
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp"
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/AHardwareBufferUtils.cpp"
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkAndroidVideo.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiHostObject.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiValue.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/jsi/RuntimeLifecycleMonitor.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/jsi/RuntimeAwareCache.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiPromises.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkManager.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkDomView.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base/DrawingContext.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base/ConcatablePaint.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/api/third_party/CSSColorParser.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/api/third_party/base64.cpp"
${BACKEND_SOURCES}
)
target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
"${NODE_MODULES_DIR}/react-native/ReactCommon"
"${NODE_MODULES_DIR}/react-native/ReactCommon/react/nativemodule/core"
"${NODE_MODULES_DIR}/react-native/ReactCommon/runtimeexecutor"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
cpp/jni/include
cpp/rnskia-android
# Skia headers have to be included with "fully"-qualified paths,
# so "include/core/SkRef.h" instead of "SkRef.h", as otherwise
# the prefab cannot be shipped.
../cpp/skia
../cpp/dawn/include
../cpp/api
../cpp/jsi
../cpp/rnskia
../cpp/rnskia/values
../cpp/rnskia/dom
../cpp/rnskia/dom/base
../cpp/rnskia/dom/nodes
../cpp/rnskia/dom/props
../cpp/utils
${libfbjni_include_DIRS}
)
add_library(skia STATIC IMPORTED)
set_property(TARGET skia PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskia.a")
add_library(svg STATIC IMPORTED)
set_property(TARGET svg PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libsvg.a")
add_library(skshaper STATIC IMPORTED)
set_property(TARGET skshaper PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskshaper.a")
add_library(skparagraph STATIC IMPORTED)
set_property(TARGET skparagraph PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskparagraph.a")
add_library(skunicode_core STATIC IMPORTED)
set_property(TARGET skunicode_core PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskunicode_core.a")
add_library(skunicode_icu STATIC IMPORTED)
set_property(TARGET skunicode_icu PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskunicode_icu.a")
find_library(
LOG_LIB
log
)
message("-- LOG : " ${LOG_LIB})
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
# We need to find packages since from RN 0.71 binaries are prebuilt
find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)
endif()
unset(JSI_LIB CACHE)
if(${REACT_NATIVE_VERSION} LESS 66)
# JSI lib didn't exist on RN 0.65 and before. Simply omit it.
set (JSI_LIB "")
elseif(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
# RN 0.71 distributes prebuilt binaries.
set (JSI_LIB ReactAndroid::jsi)
else()
# RN 0.66 distributes libjsi.so, can be used instead of compiling jsi.cpp manually.
find_library(
JSI_LIB
jsi
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()
message("-- JSI : " ${JSI_LIB})
unset(REACT_LIB CACHE)
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
# RN 0.76 packs react_nativemodule_core into ReactAndroid::reactnative
set (REACT_LIB ReactAndroid::reactnative)
elseif(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
# RN 0.71 distributes prebuilt binaries.
set (REACT_LIB ReactAndroid::react_nativemodule_core)
else()
find_library(
REACT_LIB
react_nativemodule_core
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()
message("-- REACT : " ${REACT_LIB})
unset(FBJNI_LIBRARY CACHE)
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
# RN 0.71 distributes prebuilt binaries.
set (FBJNI_LIBRARY fbjni::fbjni)
else()
find_library(
FBJNI_LIBRARY
fbjni
PATHS ${libfbjni_link_DIRS}
NO_CMAKE_FIND_ROOT_PATH
)
endif()
message("-- FBJNI : " ${FBJNI_LIBRARY})
unset(REACTNATIVEJNI_LIB CACHE)
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
# RN 0.76 doesn't have reactnativejni
# DO NOTHING, we'll not link these libraries
elseif(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
# RN 0.71 distributes prebuilt binaries.
set (REACTNATIVEJNI_LIB "ReactAndroid::reactnativejni")
else()
find_library(
REACTNATIVEJNI_LIB
reactnativejni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()
message("-- REACTNATIVEJNI : " ${REACTNATIVEJNI_LIB})
unset(RUNTIMEEXECUTOR_LIB CACHE)
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
# RN 0.76 doesn't have runtimeexecutor
# DO NOTHING, we'll not link these libraries
elseif(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
# RN 0.71 distributes prebuilt binaries.
set (RUNTIMEEXECUTOR_LIB "ReactAndroid::runtimeexecutor")
else()
find_library(
RUNTIMEEXECUTOR_LIB
runtimeexecutor
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()
message("-- RUNTIMEEXECUTOR : " ${RUNTIMEEXECUTOR_LIB})
unset(TURBOMODULES_LIB CACHE)
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
# RN 0.76 doesn't have turbomodulejsijni
# DO NOTHING, we'll not link these libraries
elseif(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
# RN 0.71 distributes prebuilt binaries.
set (TURBOMODULES_LIB "ReactAndroid::turbomodulejsijni")
else()
find_library(
TURBOMODULES_LIB
turbomodulejsijni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()
message("-- TURBO : " ${TURBOMODULES_LIB})
add_definitions(-DREACT_NATIVE_VERSION=${REACT_NATIVE_VERSION})
# Link
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 76)
set(COMMON_LIBS
${LOG_LIB}
${REACT_LIB}
${FBJNI_LIBRARY}
${JSI_LIB}
${SKIA_SVG_LIB}
${SKIA_SKSHAPER_LIB}
${SKIA_SKPARAGRAPH_LIB}
${SKIA_SKUNICODE_CORE_LIB}
${SKIA_SKUNICODE_ICU_LIB}
${SKIA_LIB}
-ljnigraphics
-lGLESv2
-lEGL
-landroid
)
else()
set(COMMON_LIBS
${LOG_LIB}
${FBJNI_LIBRARY}
${REACT_LIB}
${JSI_LIB}
${REACTNATIVEJNI_LIB}
${RUNTIMEEXECUTOR_LIB}
${TURBOMODULES_LIB}
${SKIA_SVG_LIB}
${SKIA_SKSHAPER_LIB}
${SKIA_SKPARAGRAPH_LIB}
${SKIA_SKUNICODE_CORE_LIB}
${SKIA_SKUNICODE_ICU_LIB}
${SKIA_LIB}
-ljnigraphics
-lGLESv2
-lEGL
-landroid
)
endif()
if(SK_GRAPHITE)
target_link_libraries(${PACKAGE_NAME}
${COMMON_LIBS}
${DAWN_NATIVE_LIB}
${DAWN_PLATFORM_LIB}
${DAWN_PROC_LIB}
)
else()
target_link_libraries(${PACKAGE_NAME}
${COMMON_LIBS}
-lGLESv2
-lEGL
)
endif()