annotate Platforms/Wasm/CMakeLists.txt @ 288:8c8da145fefa am-2

renamings and doc
author am@osimis.io
date Thu, 30 Aug 2018 16:52:40 +0200
parents dc1beee33134
children
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)
274
dc1beee33134 split SdlApplication into NativeApplication and SdlApplication
am@osimis.io
parents: 257
diff changeset
34 SET(ENABLE_QT OFF)
115
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
35 SET(ENABLE_SDL OFF)
274
dc1beee33134 split SdlApplication into NativeApplication and SdlApplication
am@osimis.io
parents: 257
diff changeset
36 add_definitions(-DORTHANC_ENABLE_WASM=1)
115
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
37
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
38 include(../../Resources/CMake/OrthancStoneConfiguration.cmake)
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
39
114
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 add_library(OrthancStone STATIC ${ORTHANC_STONE_SOURCES})
3541fc81331a starting WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
115
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
42
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
43
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
44 # 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
45 # 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
46 add_custom_command(
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
47 OUTPUT "${AUTOGENERATED_DIR}/WasmWebService.c"
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
48 COMMAND ${CMAKE_COMMAND} -E touch "${AUTOGENERATED_DIR}/WasmWebService.c" ""
257
9afafb192180 using PAM
am@osimis.io
parents: 255
diff changeset
49 DEPENDS "${ORTHANC_STONE_ROOT}/Platforms/Wasm/WasmWebService.js")
115
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
50
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
51 add_custom_command(
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
52 OUTPUT "${AUTOGENERATED_DIR}/default-library.c"
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
53 COMMAND ${CMAKE_COMMAND} -E touch "${AUTOGENERATED_DIR}/default-library.c" ""
257
9afafb192180 using PAM
am@osimis.io
parents: 255
diff changeset
54 DEPENDS "${ORTHANC_STONE_ROOT}/Platforms/Wasm/default-library.js")
237
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
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 ## Build all the sample applications
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
59 #####################################################################
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
60
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
61 include_directories(${ORTHANC_STONE_ROOT})
115
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
62
f598ffb81cda fix sandboxed build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 114
diff changeset
63
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
64 macro(BuildSample Target Header Sample)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
65 add_executable(${Target}
255
65562a28fe05 fixes for WASM
am@osimis.io
parents: 244
diff changeset
66 ${STONE_WASM_SOURCES}
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
67
257
9afafb192180 using PAM
am@osimis.io
parents: 255
diff changeset
68 ${AUTOGENERATED_DIR}/WasmWebService.c
9afafb192180 using PAM
am@osimis.io
parents: 255
diff changeset
69 ${AUTOGENERATED_DIR}/default-library.c
9afafb192180 using PAM
am@osimis.io
parents: 255
diff changeset
70
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
71 ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleMainWasm.cpp
242
092db46c6291 improved SDL/Wasm unification
am@osimis.io
parents: 237
diff changeset
72 # ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleApplicationContext.cpp
237
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
73 ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleInteractor.h
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
74 ${ORTHANC_STONE_ROOT}/Applications/Samples/SampleApplicationBase.h
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
75 ${ORTHANC_STONE_ROOT}/Applications/Samples/${Header}
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
76 )
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
77 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
78 target_link_libraries(${Target} OrthancStone)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
79 endmacro()
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
80
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
81 #BuildSample(OrthancStoneEmpty EmptyApplication.h 1)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
82 #BuildSample(OrthancStoneTestPattern TestPatternApplication.h 2)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
83 #BuildSample(OrthancStoneSingleFrame SingleFrameApplication.h 3)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
84 #BuildSample(OrthancStoneSingleVolume SingleVolumeApplication.h 4)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
85 #BuildSample(OrthancStoneBasicPetCtFusion 5)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
86 #BuildSample(OrthancStoneSynchronizedSeries 6)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
87 #BuildSample(OrthancStoneLayoutPetCtFusion 7)
b4642964c355 SimpleViewer demo running both with SDL and Wasm
am@osimis.io
parents: 236
diff changeset
88 BuildSample(OrthancStoneSimpleViewer SimpleViewerApplication.h 8)