-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
209 lines (176 loc) · 9.35 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
# Usage:
#
# cmake <...> -DJJB_TARGET_PLATFORM=Linux
# cmake <...> -DJJB_TARGET_PLATFORM=Windows
# cmake <...> -DJJB_TARGET_PLATFORM=macOS
# cmake <...> -DJJB_TARGET_PLATFORM=Android -DANDROID_ABI=x86_64 -DNDK_PATH=<...>
# cmake <...> -DJJB_TARGET_PLATFORM=Android -DANDROID_ABI=x86 -DNDK_PATH=<...>
# cmake <...> -DJJB_TARGET_PLATFORM=Android -DANDROID_ABI=arm64-v8a -DNDK_PATH=<...>
# cmake <...> -DJJB_TARGET_PLATFORM=Android -DANDROID_ABI=armeabi-v7a -DNDK_PATH=<...>
cmake_minimum_required(VERSION 3.17.0)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
if(JJB_TARGET_PLATFORM STREQUAL "Android")
set(CMAKE_TOOLCHAIN_FILE "${NDK_PATH}/build/cmake/android.toolchain.cmake")
set(CMAKE_ANDROID_NDK "${NDK_PATH}")
set(ANDROID_NATIVE_API_LEVEL 21)
set(CMAKE_SYSTEM_VERSION 21)
endif()
# WARNING:
# Keep all the previous settings before project() otherwise they will be ignored!
project(JJBridge_V8)
set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp")
set(V8_DIR "${CMAKE_CURRENT_SOURCE_DIR}/jni/v8")
if(JJB_TARGET_PLATFORM STREQUAL "Linux")
message("Building Linux x86_64")
set(CLANG_ARCH_TRIPLE x86_64-pc-linux-gnu)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
add_definitions(-DV8_COMPRESS_POINTERS)
set(V8_BINARIES "${V8_DIR}/platforms/linux-x86_64")
elseif(JJB_TARGET_PLATFORM STREQUAL "Windows")
message("Building Windows x86_64")
set(CLANG_ARCH_TRIPLE x86_64-pc-windows)
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
add_definitions(-DV8_COMPRESS_POINTERS)
set(V8_BINARIES "${V8_DIR}/platforms/windows-x86_64")
elseif(JJB_TARGET_PLATFORM STREQUAL "macOS")
message("Building macOS x86_64")
set(CLANG_ARCH_TRIPLE x86_64-apple-darwin)
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
add_definitions(-DV8_COMPRESS_POINTERS)
set(V8_BINARIES "${V8_DIR}/platforms/macos-x86_64")
elseif(JJB_TARGET_PLATFORM STREQUAL "Android")
message("Building Android ${ANDROID_ABI}")
set(CMAKE_SYSTEM_NAME Android)
if((ANDROID_ABI STREQUAL "x86_64") OR (ANDROID_ABI STREQUAL "arm64-v8a"))
add_definitions(-DV8_COMPRESS_POINTERS)
elseif((ANDROID_ABI STREQUAL "x86") OR (ANDROID_ABI STREQUAL "armeabi-v7a"))
# nothing to do here
else()
if(ANDROID_ABI)
message(FATAL_ERROR "Invalid Android ABI: ${ANDROID_ABI}")
else()
message(FATAL_ERROR "Missing Android ABI. Please specify using -DANDROID_ABI")
endif()
endif()
set(CMAKE_ANDROID_ARCH_ABI "${ANDROID_ABI}")
set(V8_BINARIES "${V8_DIR}/platforms/android-${ANDROID_ABI}")
else()
if(JJB_TARGET_PLATFORM)
message(FATAL_ERROR "Invalid platform: ${JJB_TARGET_PLATFORM}")
else()
message(FATAL_ERROR "Missing target platform. Please specify using -DJJB_TARGET_PLATFORM")
endif()
endif()
if(JJB_TARGET_PLATFORM STREQUAL "Windows")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++14 /Wall /O2")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wno-unused-function -Wno-unused-variable -Wno-unused-result -O3 -fvisibility=hidden -fexceptions -ffunction-sections -fno-data-sections")
endif()
if(JJB_TARGET_PLATFORM STREQUAL "Linux")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath,'$ORIGIN'")
set(CMAKE_SKIP_BUILD_RPATH TRUE)
elseif(JJB_TARGET_PLATFORM STREQUAL "macOS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --verbose")
set(CMAKE_BUILD_TYPE Release)
if(NOT (JJB_TARGET_PLATFORM STREQUAL "Android"))
set(CMAKE_C_COMPILER_TARGET ${CLANG_ARCH_TRIPLE})
set(CMAKE_CXX_COMPILER_TARGET ${CLANG_ARCH_TRIPLE})
# TODO: bisogna avere gli header java per queste piattaforme target!
# Vedi: https://bsideup.github.io/posts/jni-cross-compilation/
# Vedi: https://adoptopenjdk.net/installation.html?variant=openjdk8&jvmVariant=hotspot#archives
# Sarà da risolvere qualora cross-compileremo da e verso tutte le piattaforme
# Per il momento è sufficiente avere la JDK installata.
find_package(Java 1.8 COMPONENTS Development)
find_package(JNI REQUIRED)
include_directories("${JNI_INCLUDE_DIRS}")
else()
set(CMAKE_ANDROID_STL_TYPE c++_shared)
set(ANDROID_ALLOW_UNDEFINED_SYMBOLS FALSE)
endif()
find_program(CLANG_TIDY_COMMAND NAMES clang-tidy)
if(NOT CLANG_TIDY_COMMAND)
message(WARNING "clang-tidy executable not found - skipped")
set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "" FORCE)
else()
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-config;")
endif()
##############################################################################
# Add all source files and external libraries
include_directories("${V8_DIR}/headers/include")
add_library(V8-wrapper SHARED
"${SRC_DIR}/V8/Environment.cpp"
"${SRC_DIR}/V8/Runtime.cpp"
"${SRC_DIR}/V8/InspectorClient.cpp"
"${SRC_DIR}/V8-wrapper.cpp")
if(JJB_TARGET_PLATFORM STREQUAL "Linux")
add_library(icui18n SHARED IMPORTED)
set_target_properties(icui18n PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libicui18n.so)
add_library(icuuc SHARED IMPORTED)
set_target_properties(icuuc PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libicuuc.so)
add_library(zlib SHARED IMPORTED)
set_target_properties(zlib PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libchrome_zlib.so)
add_library(v8 SHARED IMPORTED)
set_target_properties(v8 PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libv8.so)
add_library(v8-base SHARED IMPORTED)
set_target_properties(v8-base PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libv8_libbase.so)
add_library(v8-platform SHARED IMPORTED)
set_target_properties(v8-platform PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libv8_libplatform.so)
target_link_libraries(V8-wrapper v8 v8-base v8-platform icui18n icuuc zlib)
elseif(JJB_TARGET_PLATFORM STREQUAL "macOS")
add_library(icui18n SHARED IMPORTED)
set_target_properties(icui18n PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libicui18n.dylib)
add_library(icuuc SHARED IMPORTED)
set_target_properties(icuuc PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libicuuc.dylib)
add_library(zlib SHARED IMPORTED)
set_target_properties(zlib PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libchrome_zlib.dylib)
add_library(v8 SHARED IMPORTED)
set_target_properties(v8 PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libv8.dylib)
add_library(v8-base SHARED IMPORTED)
set_target_properties(v8-base PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libv8_libbase.dylib)
add_library(v8-platform SHARED IMPORTED)
set_target_properties(v8-platform PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libv8_libplatform.dylib)
target_link_libraries(V8-wrapper v8 v8-base v8-platform icui18n icuuc zlib)
elseif(JJB_TARGET_PLATFORM STREQUAL "Android")
add_library(icui18n SHARED IMPORTED)
set_target_properties(icui18n PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libicui18n.cr.so)
add_library(icuuc SHARED IMPORTED)
set_target_properties(icuuc PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libicuuc.cr.so)
add_library(cpp-shared SHARED IMPORTED)
set_target_properties(cpp-shared PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libc++_shared.so)
add_library(v8 SHARED IMPORTED)
set_target_properties(v8 PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libv8.cr.so)
add_library(v8-base SHARED IMPORTED)
set_target_properties(v8-base PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libv8_libbase.cr.so)
add_library(v8-platform SHARED IMPORTED)
set_target_properties(v8-platform PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libv8_libplatform.cr.so)
add_library(zlib SHARED IMPORTED)
set_target_properties(zlib PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/libchrome_zlib.cr.so)
target_link_libraries(V8-wrapper v8 v8-base v8-platform icui18n icuuc cpp-shared zlib)
elseif(JJB_TARGET_PLATFORM STREQUAL "Windows")
add_library(v8 SHARED IMPORTED)
set_target_properties(v8 PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/v8.dll
IMPORTED_IMPLIB ${V8_BINARIES}/v8.dll.lib)
add_library(v8-base SHARED IMPORTED)
set_target_properties(v8-base PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/v8_libbase.dll
IMPORTED_IMPLIB ${V8_BINARIES}/v8_libbase.dll.lib)
add_library(v8-platform SHARED IMPORTED)
set_target_properties(v8-platform PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/v8_libplatform.dll
IMPORTED_IMPLIB ${V8_BINARIES}/v8_libplatform.dll.lib)
add_library(zlib SHARED IMPORTED)
set_target_properties(zlib PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/zlib.dll
IMPORTED_IMPLIB ${V8_BINARIES}/zlib.dll.lib)
add_library(icui18n SHARED IMPORTED)
set_target_properties(icui18n PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/icui18n.dll
IMPORTED_IMPLIB ${V8_BINARIES}/icui18n.dll.lib)
add_library(icuuc SHARED IMPORTED)
set_target_properties(icuuc PROPERTIES IMPORTED_LOCATION ${V8_BINARIES}/icuuc.dll
IMPORTED_IMPLIB ${V8_BINARIES}/icuuc.dll.lib)
target_link_libraries(V8-wrapper v8 v8-base v8-platform icui18n icuuc zlib)
endif()