-
Notifications
You must be signed in to change notification settings - Fork 362
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
40 lines (33 loc) · 1.28 KB
/
CMakeLists.txt
File metadata and controls
40 lines (33 loc) · 1.28 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
# Emscripten/WebAssembly build for ChaiScript
# Based on work by Rob Loach: https://github.com/RobLoach/ChaiScript.js
#
# Usage:
# emcmake cmake -B build-em -S emscripten
# cmake --build build-em
cmake_minimum_required(VERSION 3.12)
project(chaiscript_em)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Emscripten-specific compiler/linker flags
add_definitions(-DCHAISCRIPT_NO_THREADS -DCHAISCRIPT_NO_DYNLOAD)
add_executable(chaiscript chaiscript_em.cpp)
target_include_directories(chaiscript PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
# Enable WASM exception handling — ChaiScript relies on C++ exceptions for
# error propagation; without this flag exceptions cause an abort in WASM.
target_compile_options(chaiscript PRIVATE -fwasm-exceptions)
# Emscripten link flags: enable embind, allow memory growth, export as ES module-compatible
target_link_options(chaiscript PRIVATE
--bind
-fwasm-exceptions
-sALLOW_MEMORY_GROWTH=1
-sEXPORT_ES6=0
-sMODULARIZE=0
-sINVOKE_RUN=0
)
# Copy the HTML shell to the build output directory
add_custom_command(TARGET chaiscript POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/chaiscript.html
${CMAKE_CURRENT_BINARY_DIR}/chaiscript.html
COMMENT "Copying HTML frontend to build directory"
)