annotate Platforms/Wasm/CMakeLists.txt @ 255:65562a28fe05 am-2

fixes for WASM
author am@osimis.io
date Tue, 03 Jul 2018 13:19:56 +0200
parents 313903066093
children 9afafb192180
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
128
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 115
diff changeset
1 # Usage (Linux):
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 115
diff changeset
2 # source ~/Downloads/emsdk/emsdk_env.sh && cmake -DCMAKE_TOOLCHAIN_FILE=${EMSCRIPTEN}/cmake/Modules/Platform/Emscripten.cmake ..
114
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 cmake_minimum_required(VERSION 2.8.3)
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 #####################################################################
115
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
8 ## Configuration of the Emscripten compiler for WebAssembly target
114
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 #####################################################################
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 set(WASM_FLAGS "-s WASM=1")
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
12 set(WASM_MODULE_NAME "StoneFrameworkModule" CACHE STRING "Name of the WebAssembly module")
114
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WASM_FLAGS}")
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WASM_FLAGS}")
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
15 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --js-library ${STONE_SOURCES_DIR}/Applications/Samples/samples-library.js --js-library ${STONE_SOURCES_DIR}/Platforms/Wasm/WasmWebService.js --js-library ${STONE_SOURCES_DIR}/Platforms/Wasm/default-library.js -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'")
114
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 # Handling of memory
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1") # Resize
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s TOTAL_MEMORY=536870912") # 512MB
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
20 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s EXPORT_NAME='\"${WASM_MODULE_NAME}\"' -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=536870912 -s TOTAL_STACK=128000000") # 512MB + resize
114
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=1073741824") # 1GB + resize
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 # To debug exceptions
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=2")
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #####################################################################
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 ## Build a static library containing the Orthanc Stone framework
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #####################################################################
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
115
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
31 include(../../Resources/CMake/OrthancStoneParameters.cmake)
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
32
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
33 SET(ORTHANC_SANDBOXED ON)
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
34 SET(ENABLE_SDL OFF)
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
35
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
36 include(../../Resources/CMake/OrthancStoneConfiguration.cmake)
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
37
114
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 add_library(OrthancStone STATIC ${ORTHANC_STONE_SOURCES})
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
115
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
40
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
41
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
42 # Regenerate a dummy "WasmWebService.c" file each time the "WasmWebService.js" file
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
43 # is modified, so as to force a new execution of the linking
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
44 add_custom_command(
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
45 OUTPUT "${AUTOGENERATED_DIR}/WasmWebService.c"
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
46 COMMAND ${CMAKE_COMMAND} -E touch "${AUTOGENERATED_DIR}/WasmWebService.c" ""
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
47 DEPENDS "${ORTHANC_STONE_ROOT}/Platforms/WebAssembly/WasmWebService.js")
115
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
48
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
49 add_custom_command(
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
50 OUTPUT "${AUTOGENERATED_DIR}/default-library.c"
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
51 COMMAND ${CMAKE_COMMAND} -E touch "${AUTOGENERATED_DIR}/default-library.c" ""
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
52 DEPENDS "${ORTHANC_STONE_ROOT}/Platforms/WebAssembly/default-library.js")
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
53
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
54
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
55 #####################################################################
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
56 ## Build all the sample applications
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
57 #####################################################################
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
58
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
59 include_directories(${ORTHANC_STONE_ROOT})
115
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
60
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
61
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
62 macro(BuildSample Target Header Sample)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
63 add_executable(${Target}
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 244
diff changeset
64 ${STONE_WASM_SOURCES}
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
65
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
66 ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleMainWasm.cpp
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
67 # ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleApplicationContext.cpp
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
68 ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleInteractor.h
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
69 ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleApplicationBase.h
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
70 ${ORTHANC_STONE_ROOT}/Applications/Samples/${Header}
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
71 )
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
72 set_target_properties(${Target} PROPERTIES COMPILE_DEFINITIONS ORTHANC_STONE_SAMPLE=${Sample})
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
73 target_link_libraries(${Target} OrthancStone)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
74 endmacro()
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
75
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
76 #BuildSample(OrthancStoneEmpty EmptyApplication.h 1)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
77 #BuildSample(OrthancStoneTestPattern TestPatternApplication.h 2)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
78 #BuildSample(OrthancStoneSingleFrame SingleFrameApplication.h 3)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
79 #BuildSample(OrthancStoneSingleVolume SingleVolumeApplication.h 4)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
80 #BuildSample(OrthancStoneBasicPetCtFusion 5)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
81 #BuildSample(OrthancStoneSynchronizedSeries 6)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
82 #BuildSample(OrthancStoneLayoutPetCtFusion 7)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
83 BuildSample(OrthancStoneSimpleViewer SimpleViewerApplication.h 8)