-
Notifications
You must be signed in to change notification settings - Fork 35
/
CMakeLists.txt
374 lines (344 loc) · 13.4 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
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
cmake_minimum_required(VERSION 3.2)
project(KivaVM)
set(CMAKE_MODULE_PATH "${CMCMAKE_MODULE_PATH}" "${CMAKE_SOURCE_DIR}/cmake")
include(CheckIncludeFiles)
include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
enable_testing()
#### Check C++11
check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11)
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if (COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif (COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else ()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif ()
set(CMAKE_CXX_STANDARD 11)
#### Check C11
check_c_compiler_flag("-std=c11" COMPILER_SUPPORTS_C11)
if (COMPILER_SUPPORTS_CXX11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
else ()
message(STATUS "The compiler ${CMAKE_C_COMPILER} has no C11 support. Please use a different C compiler.")
endif ()
set(CMAKE_C_STANDARD 11)
if (DEFINED ENV{KIVM_DEBUG})
add_definitions(-DKIVM_DEBUG)
endif ()
if (DEFINED ENV{KIVM_DEBUG_ALL})
add_definitions(-DKIVM_DEBUG)
add_definitions(-DKIVM_INTERPRETER_DEBUG)
add_definitions(-DKIVM_CLASSPATH_DEBUG)
endif ()
#### check os
if (WIN32)
add_definitions(-DKIVM_PLATFORM_WINDOWS)
elseif (UNIX)
if (APPLE)
add_definitions(-DKIVM_PLATFORM_APPLE)
else ()
add_definitions(-DKIVM_PLATFORM_UNIX)
endif ()
else ()
message(STATUS "Cannot detect current system, disabling platform related features.")
endif ()
#### check arch
if (CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86_64|(amd|AMD)64")
set(KIVM_ARCH_x86_64 1)
set(ARCH_NAME x86_64)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86|i.86")
set(KIVM_ARCH_x86 1)
set(ARCH_NAME x86)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "arm(v.*)?")
set(KIVM_ARCH_arm 1)
set(ARCH_NAME arm)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "(AARCH|aarch)64")
set(KIVM_ARCH_aarch64 1)
set(ARCH_NAME aarch64)
endif ()
aux_source_directory(include/shared/arch/${ARCH_NAME} KIVM_ARCH_SRC)
message(STATUS "System arch: ${ARCH_NAME}")
#### libffi
find_package(FFI REQUIRED)
include_directories(${FFI_INCLUDE_DIRS})
link_libraries(${FFI_LIBRARIES})
message(STATUS "libffi include: ${FFI_INCLUDE_DIRS}")
message(STATUS "libffi libs: ${FFI_LIBRARIES}")
#### libzip
find_package(ZIP REQUIRED)
if (ZIP_FOUND)
set(HAVE_ZIP_H true)
message(STATUS "libzip include: ${ZIP_INCLUDE_DIRS}")
message(STATUS "libzip libs: ${ZIP_LIBRARIES}")
include_directories(${ZIP_INCLUDE_DIRS})
link_libraries(${ZIP_LIBRARIES})
check_c_source_compiles("#include <zip.h>
int main(int argc, char *argv[]) { zip_flags_t flag = 0; }" HAVE_ZIP_FLAGS_T)
check_c_source_compiles("#include <zip.h>
int main(int argc, char *argv[]) { unsigned int flag = ZIP_FL_ENC_GUESS; }" HAVE_ZIP_FL_ENC_GUESS)
check_c_source_compiles("#include <zip.h>
int main(int argc, char *argv[]) { zip_source_t *src; }" HAVE_ZIP_SOURCE_T)
# check libz if libzip is required
if (NOT EXISTS "/system/framework/framework-res.apk")
find_package(ZLIB REQUIRED)
if (!ZLIB_FOUND)
message(FATAL_ERROR "libz not found")
endif ()
include_directories(${ZLIB_INCLUDE_DIR})
set(CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIR})
message(STATUS "zlib version: ${ZLIB_VERSION_STRING}")
message(STATUS "zlib include: ${ZLIB_INCLUDE_DIR}")
if (ZLIB_VERSION_STRING VERSION_LESS "1.1.2")
message(FATAL_ERROR "zlib version too old, please install at least v1.1.2 to enable jar class loading.")
endif ()
message(STATUS "Jar class loading enabled")
else ()
message(STATUS "Detected building on Android, skipping zlib check")
endif ()
else ()
message(STATUS "libzip not found: jar class loading disabled")
endif ()
#### threaded interpretation
try_run(IS_THREADED COMPILE_RESULT ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/cmake/check-threaded.cpp)
if (IS_THREADED)
set(KIVM_THREADED 1)
endif ()
#### post configuration
add_definitions("-DHAVE_CONFIG_H")
configure_file(${CMAKE_SOURCE_DIR}/cmake/cmake-config.h.in ${CMAKE_BINARY_DIR}/compileTimeConfig.h)
#### kivm
include_directories(${CMAKE_BINARY_DIR})
include_directories(include)
set(SOURCE_FILES
include/kivm/classfile/classFile.h
include/kivm/kivm.h
include/kivm/bytecode/bytecodeInterpreter.h
include/kivm/bytecode/threadedInterpreter.h
include/kivm/oop/oop.h
include/kivm/oop/klass.h
include/kivm/oop/instanceKlass.h
include/shared/monitor.h
include/shared/lock.h
include/shared/string.h
include/kivm/classfile/constantPool.h
include/shared/types.h
include/kivm/classfile/classFileStream.h
include/kivm/classfile/classFileParser.h
include/kivm/classfile/attributeInfo.h
include/kivm/classpath/classLoader.h
include/kivm/oop/method.h
include/kivm/oop/field.h
include/kivm/oop/mirrorKlass.h
include/kivm/oop/oopfwd.h
include/kivm/oop/instanceOop.h
include/kivm/oop/primitiveOop.h
include/kivm/oop/mirrorOop.h
include/kivm/oop/arrayKlass.h
include/kivm/oop/arrayOop.h
include/kivm/runtime/slot.h
include/kivm/runtime/stack.h
include/kivm/runtime/frame.h
include/kivm/oop/reflection.h
include/kivm/runtime/abstractThread.h
include/kivm/oop/helper.h
include/kivm/runtime/runtimeConfig.h
include/kivm/bytecode/bytecodes.h
include/kivm/bytecode/execution.h
include/kivm/native/java_lang_Class.h
include/kivm/native/classNames.h
include/kivm/native/java_lang_Thread.h
include/kivm/native/java_lang_String.h
include/kivm/classpath/system.h
include/kivm/bytecode/codeBlob.h
include/kivm/runtime/constantPool.h
include/kivm/bytecode/javaCall.h
include/kivm/jni/jni_md.h
include/kivm/jni/jni.h
include/kivm/jni/jniJavaVM.h
include/kivm/jni/jniEnv.h
include/kivm/memory/collectedHeap.h
include/kivm/memory/copyingHeap.h
include/kivm/memory/universe.h
include/kivm/memory/heapRegion.h
include/shared/zip/libzippp.h
include/kivm/classpath/classPathManager.h
include/shared/filesystem.h
include/shared/zip.h
include/shared/atomic.h
include/shared/dl.h
include/shared/mmap.h
include/kivm/native/java_lang_reflect_Constructor.h
include/kivm/native/java_lang_reflect_Method.h
include/kivm/runtime/vmThread.h
include/kivm/runtime/threadState.h
include/kivm/runtime/javaThread.h
include/kivm/classfile/annotation.h
include/kivm/bytecode/interpreter.h
include/kivm/memory/gcThread.h
include/kivm/runtime/frameWalker.h
include/shared/osInfo.h
include/sparsepp/spp.h
include/sparsepp/spp_config.h
include/sparsepp/spp_dlalloc.h
include/sparsepp/spp_memory.h
include/sparsepp/spp_smartptr.h
include/sparsepp/spp_stdint.h
include/sparsepp/spp_timer.h
include/sparsepp/spp_traits.h
include/sparsepp/spp_utils.h
include/shared/hashMap.h
include/kivm/jni/nativeLibrariy.h
include/kivm/jni/nativeMethod.h
include/kivm/cfg/block.h
include/kivm/bytecode2/defs.h
include/kivm/cfg/edge.h
src/kivm/native/java_lang_ClassLoader.cpp
src/shared/string.cpp
src/kivm/oop/oopBase.cpp
src/kivm/classfile/classFileStream.cpp
src/kivm/oop/oop.cpp
src/kivm/classfile/constantPool.cpp
src/kivm/classfile/classFileParser.cpp
src/kivm/classfile/classFile.cpp
src/kivm/classfile/attributeInfo.cpp
src/kivm/oop/klass.cpp
src/kivm/classpath/classLoader.cpp
src/kivm/oop/instanceKlass.cpp
src/kivm/oop/method.cpp
src/kivm/bytecode/bytecodeInterpreter.cpp
src/kivm/bytecode/threadedInterpreter.cpp
src/kivm/bytecode/scratchInterpreter.cpp
src/kivm/oop/field.cpp
src/kivm/classpath/baseClassLoader.cpp
src/kivm/oop/mirrorKlass.cpp
src/kivm/oop/instanceOop.cpp
src/kivm/oop/primitiveOop.cpp
src/kivm/oop/mirrorOop.cpp
src/kivm/oop/arrayOop.cpp
src/kivm/oop/arrayKlass.cpp
src/kivm/runtime/stack.cpp
src/kivm/runtime/frame.cpp
src/kivm/runtime/abstractThread.cpp
src/kivm/runtime/runtimeConfig.cpp
src/kivm/bytecode/execution.cpp
src/kivm/native/java_lang_Class.cpp
src/kivm/runtime/init.cpp
src/kivm/classpath/system.cpp
src/kivm/native/java_lang_String.cpp
src/kivm/runtime/constantPool.cpp
src/kivm/bytecode/resolver.cpp
src/kivm/bytecode/javaCall.cpp
src/kivm/bytecode/nativeMethodCall.cpp
src/kivm/native/java_lang_Thread.cpp
src/kivm/jni/jniGlobal.cpp
src/kivm/jni/jniJavaVM.cpp
src/kivm/kivm.cpp
src/kivm/jni/jniEnv.cpp
src/kivm/bytecode/executionInvoke.cpp
src/kivm/bytecode/javaMethodCall.cpp
src/kivm/bytecode/dynamicCall.cpp
src/kivm/memory/copyingHeap.cpp
src/kivm/memory/universe.cpp
src/kivm/native/java_lang_System.cpp
src/shared/zip/libzippp.cpp
src/kivm/classpath/classPathManager.cpp
src/kivm/bytecode/virtualMethodResolver.cpp
src/kivm/native/java_lang_Object.cpp
src/kivm/native/java_lang_Float.cpp
src/kivm/native/java_lang_Double.cpp
src/kivm/native/sun_misc_VM.cpp
src/kivm/native/java_io_FileInputStream.cpp
src/kivm/native/java_io_FileOutputStream.cpp
src/kivm/native/java_io_FileDescriptor.cpp
src/kivm/native/sun_misc_Unsafe.cpp
src/kivm/native/sun_reflect_Reflection.cpp
src/kivm/native/java_security_AccessController.cpp
src/kivm/native/java_lang_Throwable.cpp
src/kivm/oop/reflection.cpp
src/kivm/classfile/annotation.cpp
src/kivm/native/sun_reflect_NativeConstructorAccessorImpl.cpp
src/kivm/native/java_lang_reflect_Constructor.cpp
src/kivm/native/java_lang_reflect_Method.cpp
src/kivm/native/sun_nio_cs_StreamEncoder.cpp
src/kivm/native/java_util_concurrent_atomic_AtomicLong.cpp
src/kivm/native/java_io_UnixFileSystem.cpp
src/kivm/native/sun_misc_Signal.cpp
src/kivm/runtime/javaThread.cpp
src/kivm/bytecode/sharedInterpreter.h
src/kivm/memory/gcThread.cpp
src/kivm/memory/copyingCollector.cpp
src/kivm/native/java_lang_Runtime.cpp
src/kivm/jni/nativeLibrary.cpp
src/kivm/jni/nativeMethod.cpp
src/shared/filesystem.cpp
src/kivm/native/java_lang_invoke_MethodHandleNatives.cpp
src/kivm/native/java_lang_reflect_Array.cpp
src/kivm/native/sun_misc_URLClassPath.cpp
include/kivm/bytecode2/bytecodes.h
include/kivm/bytecode2/template.h
include/kivm/bytecode2/interpreterMacroAssembler.h
src/kivm/bytecode2/template.cpp
include/kivm/asm/address.h
include/kivm/asm/register.h
src/kivm/bytecode2/templateTable.cpp
src/kivm/bytecode2/interpreterMacroAssembler.cpp
include/kivm/bytecode2/templateTable.h src/kivm/native/sun_reflect_NativeMethodAccessorImpl.cpp)
set(KIVM_PLATFORM_SRC
include/shared/os/common/dl.h
include/shared/os/unix/osInfo.h
include/shared/os/unix/dl.h
include/shared/os/windows/dl.h
include/shared/os/windows/osInfo.h
include/shared/os/macos/osInfo.h
src/shared/os/unix/osInfo.cpp
src/shared/os/unix/dl.cpp
src/shared/os/macos/osInfo.cpp
src/shared/os/windows/dl.cpp
src/shared/os/windows/mmap.cpp
src/shared/os/windows/osInfo.cpp)
#### libkivm
add_library(kivm SHARED ${SOURCE_FILES} ${KIVM_PLATFORM_SRC} ${KIVM_ARCH_SRC})
target_link_libraries(kivm ffi)
IF (UNIX)
target_link_libraries(kivm pthread)
target_link_libraries(kivm dl)
if (HAVE_ZIP_H)
target_link_libraries(kivm z)
target_link_libraries(kivm ${ZIP_LIBRARIES})
target_link_libraries(kivm ${FFI_LIBRARIES})
endif ()
ENDIF ()
#### Executables
add_executable(java src/bin/java.cpp include/bin/clipp.h)
target_link_libraries(java kivm)
#### Tests
macro(add_test_target name)
add_executable(test-${name} tests/test-${name}.cpp)
target_link_libraries(test-${name} kivm)
add_test(${name} test-${name})
endmacro()
add_test_target(stack-and-locals)
add_test_target(encode-decode-offset)
add_test_target(oop-size)
add_test_target(args-parser)
add_test_target(native-image)
#### Benchmarks
add_executable(bench-allocation tests/bench-allocation.cpp)
target_link_libraries(bench-allocation kivm)
add_executable(bench-map tests/bench-map.cpp)
target_link_libraries(bench-map kivm)
#### CovScript extension
if (DEFINED ENV{CS_SRC})
set(CS_SRC $ENV{CS_SRC})
include_directories(${CS_SRC}/include)
add_library(covscript-kivm SHARED
ext/covscript-kivm.cpp
ext/extension-helper.h ext/objectConverter.cpp)
target_link_libraries(covscript-kivm kivm)
set_target_properties(covscript-kivm PROPERTIES OUTPUT_NAME "kivm")
set_target_properties(covscript-kivm PROPERTIES PREFIX "")
set_target_properties(covscript-kivm PROPERTIES SUFFIX ".cse")
endif ()