-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
109 lines (87 loc) · 3.89 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
cmake_minimum_required(VERSION 3.25)
project(bjvm)
enable_testing()
set(CMAKE_C_STANDARD 23)
set(CMAKE_CXX_STANDARD 20)
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
)
FetchContent_MakeAvailable(Catch2)
if (NOT EMSCRIPTEN)
FetchContent_Declare(
zlib
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG v1.3.1
)
FetchContent_MakeAvailable(zlib)
endif()
# If doing emscripten
set(BASE_C_FLAGS "-foptimize-sibling-calls -g -O2 -fms-extensions -Wno-pragmas -Wall -Wno-pragmas -Wno-unused-parameter -fno-strict-aliasing -Wno-missing-field-initializers")
set(BASE_CXX_FLAGS "-g -O2 -Wall -Wno-c99-extensions -Wno-extra-semi")
if (EMSCRIPTEN)
set(PLATFORM_C_FLAGS "-sUSE_ZLIB=1 -mtail-call")
set(PLATFORM_CXX_FLAGS "-O2 -Wall -Wpedantic")
set(EmscriptenFlags "-s EXPORTED_FUNCTIONS=\"['_malloc','_free','_main']\" -gsource-map -sSTACK_SIZE=500000 -sWASMFS -sFORCE_FILESYSTEM=1 -sALLOW_MEMORY_GROWTH=1 --emit-tsd bjvm_main.d.ts -s ALLOW_TABLE_GROWTH=1 -s EXPORTED_RUNTIME_METHODS='\"ccall\",\"wasmMemory\",\"cwrap\",\"addFunction\",\"removeFunction\",\"wasmTable\",\"FS\",\"UTF8ToString\",\"getValue\",\"setValue\"'")
elseif (APPLE)
set(PLATFORM_C_FLAGS "-Werror")
set(PLATFORM_CXX_FLAGS "-Werror -O2 -Wall -Wextra -Wimplicit-fallthrough -g -Wno-missing-field-initializers") # -openmp -Xclang -fopenmp -L/opt/homebrew/opt/libomp/lib -I/opt/homebrew/opt/libomp/include -lomp -g")
else ()
set(PLATFORM_C_FLAGS "-march=native")
set(PLATFORM_CXX_FLAGS "-O2 -fms-extensions -Wall -g -fopenmp -march=native -fno-strict-aliasing")
endif ()
set(CMAKE_C_FLAGS "${BASE_C_FLAGS} ${PLATFORM_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${BASE_CXX_FLAGS} ${PLATFORM_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_DEBUG} -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
if (TRUE AND NOT EMSCRIPTEN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif ()
file(GLOB bjvm_SRC CONFIGURE_DEPENDS "src/*.c" "src/*.h")
file(GLOB_RECURSE bjvm_NATIVES CONFIGURE_DEPENDS "src/natives/*.c" "src/natives/*.h")
file(GLOB bjvm_wasm_SRC CONFIGURE_DEPENDS "src/wasm/*.c" "src/wasm/*.h")
if (EMSCRIPTEN)
list(APPEND bjvm_SRC ${bjvm_wasm_SRC})
endif()
add_library(bjvm OBJECT ${bjvm_SRC} ${bjvm_NATIVES}
vendor/stb_ds.h
vendor/stb_ds.c
)
target_include_directories(bjvm PUBLIC src ${CMAKE_CURRENT_SOURCE_DIR})
if (NOT EMSCRIPTEN)
target_link_libraries(bjvm PRIVATE zlibstatic)
else()
target_link_libraries(bjvm PRIVATE z)
endif()
target_link_libraries(bjvm PRIVATE m)
add_executable(bjvm_async_test src/bin/async.c) # for now
target_link_libraries(bjvm_async_test PRIVATE bjvm)
if (EMSCRIPTEN)
add_executable(bjvm_main src/bin/main.c) # for now
target_link_libraries(bjvm_main PRIVATE bjvm)
set_target_properties(bjvm_main PROPERTIES LINK_FLAGS "${EmscriptenFlags} -sMODULARIZE -sEXPORT_ES6=1")
endif()
if (NOT APPLE)
set_target_properties(bjvm PROPERTIES LINK_DEPENDS ${CMAKE_SOURCE_DIR}/natives_table.ld)
endif ()
add_executable(gen_natives codegen/gen_natives.c)
target_link_libraries(gen_natives PRIVATE bjvm)
add_executable(tests test/tests.cc test/arrays-test.cc test/tests-common.cc test/wasm-tests.cc
test/async-tests.cc
test/analysis-tests.cc
test/classpath-tests.cc
test/natives-test.cc
test/benches.cc)
if (NOT EMSCRIPTEN)
target_sources(tests PRIVATE ${bjvm_wasm_SRC})
endif()
target_link_libraries(tests PRIVATE bjvm)
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
set_target_properties(tests PROPERTIES LINK_FLAGS "${EmscriptenFlags}")
add_test(NAME tests
COMMAND tests --skip-benchmarks
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/test")
set_tests_properties(tests PROPERTIES ENVIRONMENT "ASAN_OPTIONS=detect_leaks=1,detect_container_overflow=0")