-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
385 lines (324 loc) · 13.8 KB
/
CMakeLists.txt
File metadata and controls
385 lines (324 loc) · 13.8 KB
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Command info: https://cmake.org/cmake/help/v3.4/command/cmake_minimum_required.html
cmake_minimum_required(VERSION 3.22.1)
project(NativeScriptAndroidRuntime)
# Command info: https://cmake.org/cmake/help/v3.4/command/message.html
# we pass the android_ndk_root from gradle because for some reason
# "-DANDROID_STL=c++_static" is just not enough for clang++ to find some libraries in the ndk
MESSAGE(STATUS "## ANDROID_NDK_ROOT: " ${ANDROID_NDK_ROOT})
# Add the ccache to the build system
find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND AND (USE_CCACHE))
MESSAGE(STATUS "## Using CCache when building!")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif ()
set(COMMON_CMAKE_ARGUMENTS "-Wno-error -Wno-deprecated-declarations -Wno-unused-result -mstackrealign -fexceptions -fno-builtin-stpcpy")
set(MI_OVERRIDE OFF)
if (V8_13)
set(COMMON_CMAKE_ARGUMENTS "${COMMON_CMAKE_ARGUMENTS} -std=c++20")
elseif ()
set(COMMON_CMAKE_ARGUMENTS "${COMMON_CMAKE_ARGUMENTS} -std=c++17")
endif ()
if (SHERMES)
set(COMMON_CMAKE_ARGUMENTS "${COMMON_CMAKE_ARGUMENTS} -frtti")
else ()
set(COMMON_CMAKE_ARGUMENTS "${COMMON_CMAKE_ARGUMENTS} -fno-rtti")
endif ()
# AOSP has switched to using LLD by default and the NDK will use it by default in the next release.
# BFD and Gold will be removed once LLD has been through a release cycle with no major unresolved issues (estimated r21)
# Note: lld does not currently work on Windows: https://github.com/android-ndk/ndk/issues/888
# On MacOS using LLD seems problematic as it does not add the correct path for the libNativeScript.so dSYM.
# This issue affects debugging the C++ part of the runtime.
# Manually performing "add-dsym <lib-path>" in the LLDB console seems to fix that.
# We should try using LLD again once it's the default linker for the NDK.
#if (NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
# MESSAGE(STATUS "## Using LLD linker")
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
#else ()
# MESSAGE(STATUS "## Using default linker")
#endif ()
#add_library( v8_shared STATIC IMPORTED )
#set_target_properties( v8_shared PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libv8android.so )
# Command info: https://cmake.org/cmake/help/v3.4/command/include_directories.html
include_directories(
# zip
src/main/cpp/zip/include
# runtime
src/main/cpp/runtime
src/main/cpp/runtime/assetextractor
src/main/cpp/runtime/callbackhandlers
src/main/cpp/runtime/console
src/main/cpp/runtime/constants
src/main/cpp/runtime/conversion
src/main/cpp/runtime/exceptions
src/main/cpp/runtime/global
src/main/cpp/runtime/instrumentation
src/main/cpp/runtime/inspector
src/main/cpp/runtime/jni
src/main/cpp/runtime/messageloop
src/main/cpp/runtime/metadata
src/main/cpp/runtime/module
src/main/cpp/runtime/objectmanager
src/main/cpp/runtime/performance
src/main/cpp/runtime/profiler
src/main/cpp/runtime/sighandler
src/main/cpp/runtime/timers
src/main/cpp/runtime/util
src/main/cpp/runtime/jsonhelper
src/main/cpp/runtime/version
src/main/cpp/runtime/weakref
src/main/cpp/modules
src/main/cpp/modules/url
)
# Search for all CPP files in runtime/ directory and add them to our sources
file(GLOB_RECURSE RUNTIME_FILES
"${PROJECT_SOURCE_DIR}/src/main/cpp/runtime/*.cpp"
"${PROJECT_SOURCE_DIR}/src/main/cpp/runtime/**/*.cpp"
)
file(GLOB_RECURSE MODULE_FILES
"${PROJECT_SOURCE_DIR}/src/main/cpp/modules/*.cpp"
"${PROJECT_SOURCE_DIR}/src/main/cpp/modules/**/*.cpp"
)
set(SOURCES ${RUNTIME_FILES} ${MODULE_FILES})
if (QUICKJS OR QUICKJS_NG)
add_subdirectory(${PROJECT_SOURCE_DIR}/src/main/cpp/napi/quickjs/mimalloc-dev mimalloc)
if (QUICKJS_NG)
set(QJS_SOURCE_DIR src/main/cpp/napi/quickjs/source_ng)
else()
set(QJS_SOURCE_DIR src/main/cpp/napi/quickjs/source)
endif()
set(SOURCES ${SOURCES}
# quickjs
${QJS_SOURCE_DIR}/cutils.c
${QJS_SOURCE_DIR}/libregexp.c
${QJS_SOURCE_DIR}/libunicode.c
${QJS_SOURCE_DIR}/quickjs.c
${QJS_SOURCE_DIR}/dtoa.c
# napi
src/main/cpp/napi/quickjs/quickjs-api.c
src/main/cpp/napi/quickjs/jsr.cpp
)
include_directories(
src/main/cpp/napi/quickjs
${QJS_SOURCE_DIR}
src/main/cpp/napi/common
# mimalloc
src/main/cpp/napi/quickjs/mimalloc-dev/include
)
endif ()
if (PRIMJS)
set(SOURCES ${SOURCES}
src/main/cpp/napi/primjs/jsr.cpp
src/main/cpp/napi/primjs/code_cache.cc
src/main/cpp/napi/primjs/primjs-api.cc
src/main/cpp/napi/primjs/napi_env.cc
)
include_directories(
src/main/cpp/napi/primjs
src/main/cpp/napi/primjs/include
src/main/cpp/napi/common
)
endif ()
if (HERMES)
include_directories(
src/main/cpp/napi/hermes
src/main/cpp/napi/hermes/include
src/main/cpp/napi/common
)
set(SOURCES ${SOURCES}
src/main/cpp/napi/hermes/jsr.cpp
)
endif ()
if (SHERMES)
include_directories(
src/main/cpp/napi/hermes
src/main/cpp/napi/hermes/include_shermes
src/main/cpp/napi/common
)
set(SOURCES ${SOURCES}
src/main/cpp/napi/hermes/jsr.cpp
)
endif ()
if (JSC)
include_directories(
src/main/cpp/napi/jsc
src/main/cpp/napi/jsc/include
src/main/cpp/napi/common
)
set(SOURCES ${SOURCES}
src/main/cpp/napi/jsc/jsc-api.cpp
src/main/cpp/napi/jsc/jsr.cpp
)
endif ()
if (V8)
if (V8_10)
include_directories(
src/main/cpp/napi/v8
src/main/cpp/napi/v8-10
src/main/cpp/napi/v8-10/include
src/main/cpp/napi/common
src/main/cpp/napi/v8/v8_inspector
src/main/cpp/napi/v8-10/v8_inspector
)
elseif (V8_11)
include_directories(
src/main/cpp/napi/v8
src/main/cpp/napi/v8-11
src/main/cpp/napi/v8-11/include
src/main/cpp/napi/common
src/main/cpp/napi/v8/v8_inspector
src/main/cpp/napi/v8-11/v8_inspector
)
else ()
include_directories(
src/main/cpp/napi/v8
src/main/cpp/napi/v8-13
src/main/cpp/napi/v8-13/include
src/main/cpp/napi/common
src/main/cpp/napi/v8/v8_inspector
src/main/cpp/napi/v8-13/v8_inspector
)
endif ()
if (NOT OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD)
add_definitions(-DAPPLICATION_IN_DEBUG)
set(
SOURCES
${SOURCES}
src/main/cpp/napi/v8/v8_inspector/Utils.cpp
src/main/cpp/napi/v8/v8_inspector/ns-v8-tracing-agent-impl.cpp
)
endif ()
set(SOURCES ${SOURCES}
src/main/cpp/napi/v8/v8-api.cpp
src/main/cpp/napi/v8/jsr.cpp
src/main/cpp/napi/v8/SimpleAllocator.cpp
)
if (V8_10)
set(COMMON_CMAKE_ARGUMENTS "${COMMON_CMAKE_ARGUMENTS} -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -DV8_EMBEDDED_BUILTINS")
# Enable pointer compression on 64 bit platforms
if ("${ANDROID_ABI}" MATCHES "arm64-v8a$" OR "${ANDROID_ABI}" MATCHES "x86_64$")
set(COMMON_CMAKE_ARGUMENTS "${COMMON_CMAKE_ARGUMENTS} -DV8_COMPRESS_POINTERS")
endif ()
else ()
set(COMMON_CMAKE_ARGUMENTS "${COMMON_CMAKE_ARGUMENTS} -DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -DV8_EMBEDDED_BUILTINS")
endif ()
endif ()
if (OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD)
set(CMAKE_CXX_FLAGS "${COMMON_CMAKE_ARGUMENTS} -O3 -flto -fvisibility=hidden -ffunction-sections -fno-data-sections")
else ()
set(CMAKE_CXX_FLAGS "${COMMON_CMAKE_ARGUMENTS} -g")
endif ()
# Command info: https://cmake.org/cmake/help/v3.4/command/add_library.html
# Creates(shared static) and names a library given relative sources
# Gradle automatically packages shared libraries with your APK.
add_library(
# Sets the name of the library. When it's built you can find it with lib prefix libNativeScript.so
NativeScript
# Sets the library as a shared library.
SHARED
${SOURCES}
)
if (OPTIMIZED_BUILD OR OPTIMIZED_WITH_INSPECTOR_BUILD)
set_target_properties(
NativeScript
PROPERTIES LINK_FLAGS -Wl,--allow-multiple-definition -Wl,--exclude-libs=ALL -Wl,--gc-sections
)
else ()
set_target_properties(
NativeScript
PROPERTIES LINK_FLAGS -Wl,--allow-multiple-definition
)
# target_compile_options(NativeScript PUBLIC -fsanitize=hwaddress -fno-omit-frame-pointer)
# target_link_options(NativeScript PUBLIC -fsanitize=hwaddress)
endif ()
MESSAGE(STATUS "# General cmake Info")
MESSAGE(STATUS "# PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR})
MESSAGE(STATUS "# CMAKE_VERSION: " ${CMAKE_VERSION})
MESSAGE(STATUS "# CMAKE_C_COMPILER_ID: " ${CMAKE_C_COMPILER_ID})
MESSAGE(STATUS "# CMAKE_CXX_COMPILER_ID: " ${CMAKE_CXX_COMPILER_ID})
MESSAGE(STATUS "# CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
MESSAGE(STATUS "# CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS})
# Command info: https://cmake.org/cmake/help/v3.4/command/target_link_libraries.html
# linking custom STL libraries to the runtime (NativeScript library)
target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/common/${ANDROID_ABI}/libzip.a)
#target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/common/${ANDROID_ABI}/libclang_rt.asan-aarch64-android.so)
if (SHERMES)
target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/shermes/${ANDROID_ABI}/libhermesvm.so)
target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/shermes/${ANDROID_ABI}/libjsi.so)
add_compile_definitions(NativeScript, PRIVATE __HERMES__)
add_compile_definitions(NativeScript, PRIVATE __SHERMES__)
endif ()
if (HERMES)
target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/hermes/${ANDROID_ABI}/libhermes.so)
target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/hermes/${ANDROID_ABI}/libjsi.so)
add_compile_definitions(NativeScript, PRIVATE __HERMES__)
endif ()
if (JSC)
target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/jsc/${ANDROID_ABI}/libjsc.so)
add_compile_definitions(NativeScript, PRIVATE __JSC__)
endif ()
if (V8)
add_compile_definitions(NativeScript, PRIVATE __V8__)
endif ()
if (V8_10)
target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/v8-10/${ANDROID_ABI}/libv8_monolith.a)
add_compile_definitions(NativeScript, PRIVATE __V8_10__)
endif ()
if (V8_11)
target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/v8-11/${ANDROID_ABI}/libv8_monolith.a)
add_compile_definitions(NativeScript, PRIVATE __V8_11__)
endif ()
if (V8_13)
target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/v8-13/${ANDROID_ABI}/libv8_monolith.a)
add_compile_definitions(NativeScript, PRIVATE __V8_13__)
endif ()
if (PRIMJS)
# target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/primjs/${ANDROID_ABI}/libnapi.so)
target_link_libraries(NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/primjs/${ANDROID_ABI}/libquick.so)
add_compile_definitions(NativeScript, PRIVATE __PRIMJS__)
endif ()
if (QUICKJS OR QUICKJS_NG)
add_compile_definitions(NativeScript, PRIVATE __QJS__)
if (QUICKJS_NG)
add_compile_definitions(NativeScript, PRIVATE __QJS_NG__)
endif ()
if (USE_MIMALLOC)
add_compile_definitions(NativeScript, PRIVATE USE_MIMALLOC)
endif ()
endif ()
if (USE_HOST_OBJECTS)
add_compile_definitions(NativeScript, PRIVATE USE_HOST_OBJECT)
endif ()
if (IS_NAPI_MODULE)
add_compile_definitions(NativeScript, PRIVATE IS_NAPI_MODULE)
endif ()
# if("${ANDROID_ABI}" MATCHES "armeabi-v7a$" OR "${ANDROID_ABI}" MATCHES "x86$")
# # On API Level 19 and lower we need to link with android_support
# # because it contains some implementation of functions such as "strtoll" and "strtoul"
# MESSAGE(STATUS "# Linking with libandroid_support.a")
# target_link_libraries(NativeScript ${ANDROID_NDK_ROOT}/sources/cxx-stl/llvm-libc++/libs/${ANDROID_ABI}/libandroid_support.a)
# endif()
# Command info: https://cmake.org/cmake/help/v3.4/command/find_library.html
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library(system-log log)
find_library(system-z z)
find_library(system-android android)
# Command info: https://cmake.org/cmake/help/v3.4/command/target_link_libraries.html
# Specifies libraries CMake should link to your target library.
if (QUICKJS)
if (USE_MIMALLOC)
target_link_libraries(NativeScript ${system-log} ${system-z} ${system-android} mimalloc-static)
else ()
target_link_libraries(NativeScript ${system-log} ${system-z} ${system-android})
endif ()
elseif (HERMES OR SHERMES)
find_package(fbjni REQUIRED CONFIG)
target_link_libraries(NativeScript ${system-log} ${system-z} fbjni::fbjni ${system-android})
elseif (JSC OR V8 OR PRIMJS)
target_link_libraries(NativeScript ${system-log} ${system-z} ${system-android})
endif ()