-
Notifications
You must be signed in to change notification settings - Fork 70
/
CMakeLists.txt
183 lines (144 loc) · 6.37 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
cmake_minimum_required(VERSION 3.0)
file(STRINGS ${CMAKE_CURRENT_LIST_DIR}/VERSION SCRIPTX_VERSION)
if ("${PROJECT_NAME}" STREQUAL "")
project(ScriptX VERSION ${SCRIPTX_VERSION} LANGUAGES CXX C)
endif ()
if ("${CMAKE_CXX_STANDARD}" STREQUAL "")
message(WARNING "CMAKE_CXX_STANDARD not set, please set to 17 or latter")
endif ()
set(SCRIPTX_DIR ${CMAKE_CURRENT_LIST_DIR})
# supported targets
set(SCRIPTX_BACKEND_V8 V8)
set(SCRIPTX_BACKEND_JAVASCRIPTCORE JavaScriptCore)
set(SCRIPTX_BACKEND_SPIDERMONKEY SpiderMonkey)
set(SCRIPTX_BACKEND_QUICKJS QuickJs)
set(SCRIPTX_BACKEND_WEBASSEMBLY WebAssembly)
set(SCRIPTX_BACKEND_WKWEBVIEW WKWebView)
set(SCRIPTX_BACKEND_LUA Lua)
set(SCRIPTX_BACKEND_PYTHON Python)
set(SCRIPTX_BACKEND_RUBY Ruby)
# Empty is for you to compile against ScriptX but don't keep any real implementations
set(SCRIPTX_BACKEND_EMPTY Empty)
set(SCRIPTX_BACKEND_LIST
${SCRIPTX_BACKEND_V8}
${SCRIPTX_BACKEND_JAVASCRIPTCORE}
${SCRIPTX_BACKEND_SPIDERMONKEY}
${SCRIPTX_BACKEND_QUICKJS}
${SCRIPTX_BACKEND_WEBASSEMBLY}
${SCRIPTX_BACKEND_WKWEBVIEW}
${SCRIPTX_BACKEND_LUA}
${SCRIPTX_BACKEND_PYTHON}
${SCRIPTX_BACKEND_RUBY}
${SCRIPTX_BACKEND_EMPTY}
)
# set options, choose which ScriptX Backend to use, V8 or JSC or etc...
set(SCRIPTX_BACKEND "${SCRIPTX_BACKEND}" CACHE STRING "choose which ScriptX Backend(Implementation) to use, V8 or JavaScriptCore or etc...")
set_property(CACHE SCRIPTX_BACKEND PROPERTY STRINGS "${SCRIPTX_BACKEND_LIST}")
option(SCRIPTX_NO_EXCEPTION_ON_BIND_FUNCTION "don't throw exception on defineClass generated bound function/get/set, return null & log instead. default to OFF" OFF)
option(SCRIPTX_FEATURE_INSPECTOR "enable inspector feature, default to OFF" OFF)
###### add ScriptX library target ######
# define our target first
add_library(ScriptX STATIC
${SCRIPTX_DIR}/src/Engine.h
${SCRIPTX_DIR}/src/Engine.hpp
${SCRIPTX_DIR}/src/Engine.cc
${SCRIPTX_DIR}/src/Reference.h
${SCRIPTX_DIR}/src/Reference.cc
${SCRIPTX_DIR}/src/Scope.h
${SCRIPTX_DIR}/src/Scope.cc
${SCRIPTX_DIR}/src/Value.h
${SCRIPTX_DIR}/src/Exception.h
${SCRIPTX_DIR}/src/Inspector.h
${SCRIPTX_DIR}/src/Native.h
${SCRIPTX_DIR}/src/Native.hpp
${SCRIPTX_DIR}/src/Native.cc
${SCRIPTX_DIR}/src/types.h
${SCRIPTX_DIR}/src/Utils.cc
${SCRIPTX_DIR}/src/utils/GlobalWeakBookkeeping.hpp
${SCRIPTX_DIR}/src/utils/Helper.hpp
${SCRIPTX_DIR}/src/utils/Helper.cc
${SCRIPTX_DIR}/src/utils/MemoryPool.hpp
${SCRIPTX_DIR}/src/utils/MessageQueue.cc
${SCRIPTX_DIR}/src/utils/ThreadPool.cc
${SCRIPTX_DIR}/src/utils/TypeInformation.h
)
target_include_directories(ScriptX PUBLIC ${SCRIPTX_DIR}/src/include)
###### config implementation ######
if ("${SCRIPTX_BACKEND}" STREQUAL "")
message(FATAL_ERROR "Platform not set. Please set SCRIPTX_BACKEND. Candidates: ${SCRIPTX_BACKEND_LIST}")
endif ()
if (${SCRIPTX_BACKEND} STREQUAL ${SCRIPTX_BACKEND_V8})
include(${SCRIPTX_DIR}/backend/V8/CMakeLists.txt)
add_definitions(
-DSCRIPTX_BACKEND_TRAIT_PREFIX=../backend/V8/trait/Trait
)
elseif (${SCRIPTX_BACKEND} STREQUAL ${SCRIPTX_BACKEND_JAVASCRIPTCORE})
include(${SCRIPTX_DIR}/backend/JavaScriptCore/CMakeLists.txt)
add_definitions(
-DSCRIPTX_BACKEND_TRAIT_PREFIX=../backend/JavaScriptCore/trait/Trait
)
elseif (${SCRIPTX_BACKEND} STREQUAL ${SCRIPTX_BACKEND_SPIDERMONKEY})
include(${SCRIPTX_DIR}/backend/SpiderMonkey/CMakeLists.txt)
add_definitions(
-DSCRIPTX_BACKEND_TRAIT_PREFIX=../backend/SpiderMonkey/trait/Trait
)
elseif (${SCRIPTX_BACKEND} STREQUAL ${SCRIPTX_BACKEND_QUICKJS})
include(${SCRIPTX_DIR}/backend/QuickJs/CMakeLists.txt)
add_definitions(
-DSCRIPTX_BACKEND_TRAIT_PREFIX=../backend/QuickJs/trait/Trait
)
elseif (${SCRIPTX_BACKEND} STREQUAL ${SCRIPTX_BACKEND_WEBASSEMBLY})
include(${SCRIPTX_DIR}/backend/WebAssembly/CMakeLists.txt)
add_definitions(
-DSCRIPTX_BACKEND_TRAIT_PREFIX=../backend/WebAssembly/trait/Trait
)
# see https://github.com/emscripten-core/emscripten/blob/master/src/settings.js
# -sALLOW_MEMORY_GROWTH=1
# -sINITIAL_MEMORY=167772160
# -sUSE_PTHREADS=1
target_compile_options(ScriptX PRIVATE
-sDISABLE_EXCEPTION_CATCHING=0
)
target_link_options(ScriptX INTERFACE
-sDISABLE_EXCEPTION_CATCHING=0
-sLLD_REPORT_UNDEFINED
)
elseif (${SCRIPTX_BACKEND} STREQUAL ${SCRIPTX_BACKEND_WKWEBVIEW})
include(${SCRIPTX_DIR}/backend/WKWebView/CMakeLists.txt)
add_definitions(
-DSCRIPTX_BACKEND_TRAIT_PREFIX=../backend/WKWebView/trait/Trait
)
elseif (${SCRIPTX_BACKEND} STREQUAL ${SCRIPTX_BACKEND_LUA})
include(${SCRIPTX_DIR}/backend/Lua/CMakeLists.txt)
add_definitions(
-DSCRIPTX_BACKEND_TRAIT_PREFIX=../backend/Lua/trait/Trait
)
elseif (${SCRIPTX_BACKEND} STREQUAL ${SCRIPTX_BACKEND_PYTHON})
include(${SCRIPTX_DIR}/backend/Python/CMakeLists.txt)
add_definitions(
-DSCRIPTX_BACKEND_TRAIT_PREFIX=../backend/Python/trait/Trait
)
elseif (${SCRIPTX_BACKEND} STREQUAL ${SCRIPTX_BACKEND_RUBY})
include(${SCRIPTX_DIR}/backend/Ruby/CMakeLists.txt)
add_definitions(
-DSCRIPTX_BACKEND_TRAIT_PREFIX=../backend/Ruby/trait/Trait
)
elseif (${SCRIPTX_BACKEND} STREQUAL ${SCRIPTX_BACKEND_EMPTY})
include(${SCRIPTX_DIR}/backend/Template/CMakeLists.txt)
add_definitions(
-DSCRIPTX_BACKEND_TRAIT_PREFIX=../backend/Template/trait/Trait
)
else ()
message(FATAL_ERROR "platform not supported: ${SCRIPTX_BACKEND}. please set SCRIPTX_BACKEND. Candidates: ${SCRIPTX_BACKEND_LIST}")
endif ()
if (${SCRIPTX_NO_EXCEPTION_ON_BIND_FUNCTION})
add_definitions(-DSCRIPTX_NO_EXCEPTION_ON_BIND_FUNCTION)
endif ()
if (${SCRIPTX_FEATURE_INSPECTOR})
add_definitions(-DSCRIPTX_FEATURE_INSPECTOR)
endif ()
message(STATUS "Configuring ScriptX version ${SCRIPTX_VERSION}.")
message(STATUS "Configuring ScriptX using backend ${SCRIPTX_BACKEND}.")
message(STATUS "Configuring ScriptX option SCRIPTX_NO_EXCEPTION_ON_BIND_FUNCTION ${SCRIPTX_NO_EXCEPTION_ON_BIND_FUNCTION}.")
message(STATUS "Configuring ScriptX feature SCRIPTX_FEATURE_INSPECTOR ${SCRIPTX_FEATURE_INSPECTOR}.")
include(${SCRIPTX_DIR}/docs/doxygen/CMakeLists.txt)