Mercurial > hg > orthanc-stone
comparison Applications/StoneWebViewer/WebAssembly/StoneModule/CMakeLists.txt @ 1549:a48ae10857b1
packaging of the WebAssembly module
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 13 Aug 2020 15:56:01 +0200 |
parents | |
children | c54bc5bffd01 |
comparison
equal
deleted
inserted
replaced
1548:65eccce95882 | 1549:a48ae10857b1 |
---|---|
1 cmake_minimum_required(VERSION 2.8.3) | |
2 | |
3 project(OrthancStone) | |
4 | |
5 set(ORTHANC_STONE_MODULE_PREFIX "${CMAKE_SOURCE_DIR}/../../../../wasm-binaries/OrthancStoneModule" CACHE PATH "Where to find the precompiled WebAssembly module of Orthanc Stone") | |
6 set(ORTHANC_STONE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../../../../wasm-binaries/StoneWebViewer" CACHE PATH "Where to put the WebAssembly binaries") | |
7 set(EMSCRIPTEN_TARGET_MODE "wasm" CACHE STRING "Sets the target mode for Emscripten (can be \"wasm\" or \"asm.js\")") | |
8 mark_as_advanced(EMSCRIPTEN_TARGET_MODE) | |
9 | |
10 | |
11 set(WASM_FLAGS "-s MAIN_MODULE=1") # Must be before "Compiler.cmake" | |
12 | |
13 # https://github.com/emscripten-core/emscripten/issues/11407 | |
14 set(WASM_FLAGS "${WASM_FLAGS} -s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[\"_emscripten_fetch_xhr\",\"_emscripten_fetch_load_cached_data\",\"_emscripten_fetch_delete_cached_data\",\"_emscripten_fetch_cache_data\"]") | |
15 | |
16 set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s RUNTIME_LINKED_LIBS='[\"OrthancStoneModule.wasm\"]'") | |
17 | |
18 | |
19 | |
20 # Configuration of the Emscripten compiler for WebAssembly target | |
21 # --------------------------------------------------------------- | |
22 set(USE_WASM ON CACHE BOOL "") | |
23 | |
24 set(EMSCRIPTEN_SET_LLVM_WASM_BACKEND ON CACHE BOOL "") | |
25 | |
26 set(WASM_FLAGS "${WASM_FLAGS} -s WASM=1 -s FETCH=1") | |
27 if (CMAKE_BUILD_TYPE STREQUAL "Debug") | |
28 set(WASM_FLAGS "${WASM_FLAGS} -s SAFE_HEAP=1") | |
29 endif() | |
30 | |
31 set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'") | |
32 set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=1") | |
33 set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ASSERTIONS=1 -s DISABLE_EXCEPTION_CATCHING=0") | |
34 set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s TOTAL_MEMORY=268435456") # 256MB + resize | |
35 set(WASM_LINKER_FLAGS "${WASM_LINKER_FLAGS} -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1") | |
36 add_definitions( | |
37 -DDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 | |
38 ) | |
39 | |
40 | |
41 | |
42 # Stone of Orthanc configuration, to be used as module | |
43 # --------------------------------------------------------------- | |
44 | |
45 | |
46 include(${CMAKE_SOURCE_DIR}/../../../../OrthancStone/Resources/Orthanc/CMake/Compiler.cmake) | |
47 | |
48 add_definitions( | |
49 -DORTHANC_STONE_MAX_TAG_LENGTH=256 # TODO => share with OrthancStone | |
50 ) | |
51 | |
52 include_directories( | |
53 ${ORTHANC_STONE_MODULE_PREFIX}/include | |
54 ${ORTHANC_STONE_MODULE_PREFIX}/include/orthanc-framework | |
55 ${ORTHANC_STONE_MODULE_PREFIX}/include/orthanc-stone | |
56 ) | |
57 | |
58 | |
59 | |
60 ################################################################################ | |
61 | |
62 | |
63 # Create the wrapper to call C++ from JavaScript | |
64 # --------------------------------------------------------------- | |
65 | |
66 set(LIBCLANG "libclang-4.0.so.1" CACHE PATH "Version of clang to generate the code model") | |
67 set(STONE_WRAPPER ${CMAKE_CURRENT_BINARY_DIR}/stone.js) | |
68 | |
69 add_custom_command( | |
70 COMMAND | |
71 ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/../ParseWebAssemblyExports.py --libclang=${LIBCLANG} ${CMAKE_SOURCE_DIR}/../StoneWebViewer.cpp > ${STONE_WRAPPER} | |
72 DEPENDS | |
73 ${CMAKE_SOURCE_DIR}/../StoneWebViewer.cpp | |
74 ${CMAKE_SOURCE_DIR}/../ParseWebAssemblyExports.py | |
75 OUTPUT | |
76 ${STONE_WRAPPER} | |
77 ) | |
78 | |
79 add_custom_target(StoneWrapper | |
80 DEPENDS | |
81 ${STONE_WRAPPER} | |
82 ) | |
83 | |
84 | |
85 # Define the WASM module | |
86 # --------------------------------------------------------------- | |
87 | |
88 aux_source_directory( | |
89 ${ORTHANC_STONE_MODULE_PREFIX}/src/orthanc-stone/ | |
90 ORTHANC_STONE_SOURCES) | |
91 | |
92 add_executable(StoneWebViewer | |
93 ${AUTOGENERATED_SOURCES} | |
94 ${ORTHANC_STONE_SOURCES} | |
95 ../StoneWebViewer.cpp | |
96 ) | |
97 | |
98 set_target_properties(StoneWebViewer | |
99 PROPERTIES | |
100 COMPILE_FLAGS "${WASM_FLAGS}" | |
101 LINK_FLAGS "${WASM_LINKER_FLAGS}" | |
102 ) | |
103 | |
104 # Make sure to have the wrapper generated | |
105 add_dependencies(StoneWebViewer StoneWrapper) | |
106 | |
107 | |
108 # Declare installation files for the module | |
109 # --------------------------------------------------------------- | |
110 | |
111 install( | |
112 TARGETS StoneWebViewer | |
113 RUNTIME DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX} | |
114 ) | |
115 | |
116 | |
117 # Declare installation files for the companion files (web scaffolding) | |
118 # please note that ${CMAKE_CURRENT_BINARY_DIR}/StoneWebViewer.js | |
119 # (the generated JS loader for the WASM module) is handled by the `install` | |
120 # section above: it is considered to be the binary output of | |
121 # the linker. | |
122 # --------------------------------------------------------------- | |
123 install( | |
124 FILES | |
125 ${CMAKE_CURRENT_BINARY_DIR}/StoneWebViewer.wasm | |
126 ${CMAKE_SOURCE_DIR}/../../WebApplication/app.css | |
127 ${CMAKE_SOURCE_DIR}/../../WebApplication/app.js | |
128 ${CMAKE_SOURCE_DIR}/../../WebApplication/index.html | |
129 ${ORTHANC_STONE_MODULE_PREFIX}/lib/OrthancStoneModule.wasm # NEW | |
130 ${STONE_WRAPPER} | |
131 DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX} | |
132 ) | |
133 | |
134 install( | |
135 FILES | |
136 ${CMAKE_SOURCE_DIR}/../../WebApplication/img/grid1x1.png | |
137 ${CMAKE_SOURCE_DIR}/../../WebApplication/img/grid1x2.png | |
138 ${CMAKE_SOURCE_DIR}/../../WebApplication/img/grid2x1.png | |
139 ${CMAKE_SOURCE_DIR}/../../WebApplication/img/grid2x2.png | |
140 ${CMAKE_SOURCE_DIR}/../../WebApplication/img/loading.gif | |
141 DESTINATION ${ORTHANC_STONE_INSTALL_PREFIX}/img | |
142 ) |