@@ -58,25 +58,40 @@ option(XEUS_OCTAVE_BUILD_SHARED "Split xoctave build into executable and library
5858option (XEUS_OCTAVE_BUILD_EXECUTABLE "Build the xoctave executable" ON )
5959
6060option (
61- XEUS_OCTAVE_USE_SHARED_XEUS
62- "Link xeus-octave with the xeus shared library (instead of the static library)"
61+ XEUS_OCTAVE_USE_SHARED_XEUS_ZMQ
62+ "Link xeus-octave with the xeus-zmq shared library (instead of the static library)"
6363 ON
6464)
6565option (
6666 XEUS_OCTAVE_USE_SHARED_XEUS_OCTAVE
67- "Link xoctave with the xeus shared library (instead of the static library)"
67+ "Link xoctave with the xeus-octave shared library (instead of the static library)"
6868 ON
6969)
7070
71+ if (EMSCRIPTEN)
72+ set (XEUS_OCTAVE_BUILD_STATIC ON )
73+ set (XEUS_OCTAVE_BUILD_SHARED OFF )
74+ set (XEUS_OCTAVE_BUILD_EXECUTABLE ON )
75+ set (XEUS_OCTAVE_USE_SHARED_XEUS_ZMQ OFF )
76+ set (XEUS_OCTAVE_USE_SHARED_XEUS_OCTAVE OFF )
77+ set (XEUS_OCTAVE_DISABLE_ARCH_NATIVE ON )
78+ set (XEUS_OCTAVE_DISABLE_TUNE_GENERIC ON )
79+ endif ()
80+
7181# Dependencies
7282# ============
7383
74- set (xeus_zmq_REQUIRED_VERSION 3.0.0)
75- find_package (xeus-zmq ${xeus_zmq_REQUIRED_VERSION} REQUIRED)
76-
7784find_package (PNG REQUIRED)
78- find_package (glad REQUIRED)
79- find_package (glfw3)
85+
86+ if (NOT EMSCRIPTEN)
87+ set (xeus_zmq_REQUIRED_VERSION 3.0.0)
88+ find_package (xeus-zmq ${xeus_zmq_REQUIRED_VERSION} REQUIRED)
89+ find_package (glad REQUIRED)
90+ find_package (glfw3)
91+ else ()
92+ find_package (xeus-lite REQUIRED)
93+ endif ()
94+
8095find_package (PkgConfig REQUIRED)
8196pkg_check_modules(octinterp REQUIRED IMPORTED_TARGET GLOBAL octinterp>=10.0)
8297
@@ -105,29 +120,40 @@ endif()
105120set (
106121 XEUS_OCTAVE_HEADERS
107122 include /xeus-octave/config.hpp
108- include /xeus-octave/xinterpreter .hpp
123+ include /xeus-octave/display .hpp
109124 include /xeus-octave/input .hpp
110125 include /xeus-octave/output .hpp
111- include /xeus-octave/utils.hpp
112- include /xeus-octave/tk_notebook.hpp
113- include /xeus-octave/opengl.hpp
114- include /xeus-octave/tk_plotly.hpp
115126 include /xeus-octave/plotstream.hpp
116127 include /xeus-octave/tex2html.hpp
117- include /xeus-octave/display.hpp
128+ include /xeus-octave/tk_plotly.hpp
129+ include /xeus-octave/utils.hpp
130+ include /xeus-octave/xinterpreter.hpp
118131)
119132
133+ if (EMSCRIPTEN)
134+ list (APPEND XEUS_OCTAVE_HEADERS include /xeus-octave/xinterpreter_wasm.hpp)
135+ else ()
136+ list (
137+ APPEND
138+ XEUS_OCTAVE_HEADERS
139+ include /xeus-octave/opengl.hpp
140+ include /xeus-octave/tk_notebook.hpp
141+ )
142+ endif ()
143+
120144set (
121145 XEUS_OCTAVE_SRC
122- src/tk_plotly.cpp
123- src/tk_notebook.cpp
124- src/display.cpp
125- src/xinterpreter.cpp
126- src/input .cpp
127- src/output .cpp
146+ src/display.cpp src/input .cpp src/output .cpp src/tk_plotly.cpp src/xinterpreter.cpp
128147)
129148
149+ if (EMSCRIPTEN)
150+ list (APPEND XEUS_OCTAVE_SRC src/xinterpreter_wasm.cpp)
151+ else ()
152+ list (APPEND XEUS_OCTAVE_SRC src/tk_notebook.cpp)
153+ endif ()
154+
130155set (XEUS_OCTAVE_MAIN_SRC src/main.cpp)
156+ set (XEUS_OCTAVE_MAIN_WASM_SRC src/main_wasm.cpp)
131157
132158# Targets and link - Macros
133159# =========================
@@ -182,8 +208,10 @@ macro(xeus_octave_set_kernel_options target_name)
182208 target_link_libraries (${target_name} PRIVATE xeus-octave-static )
183209 endif ()
184210
185- find_package (Threads)
186- target_link_libraries (${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} )
211+ if (NOT EMSCRIPTEN)
212+ find_package (Threads)
213+ target_link_libraries (${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} )
214+ endif ()
187215
188216endmacro ()
189217
@@ -226,24 +254,35 @@ macro(xeus_octave_create_target target_name linkage output_name)
226254 PUBLIC $<BUILD_INTERFACE:${XEUS_OCTAVE_INCLUDE_DIR} > $<INSTALL_INTERFACE:include >
227255 )
228256
229- target_link_libraries (
230- ${target_name}
231- PUBLIC PkgConfig::octinterp
232- PRIVATE glad::glad glfw PNG::PNG
233- )
234- if (XEUS_OCTAVE_USE_SHARED_XEUS)
235- target_link_libraries (${target_name} PUBLIC xeus-zmq)
257+ target_link_libraries (${target_name} PRIVATE PNG::PNG)
258+
259+ if (EMSCRIPTEN)
260+ target_compile_options (${target_name} PRIVATE ${octinterp_CFLAGS} )
261+ target_link_libraries (
262+ ${target_name}
263+ # Cannot mix shared and static libs with emscripten
264+ PUBLIC ${octinterp_STATIC_LIBRARIES}
265+ )
236266 else ()
237- target_link_libraries (${target_name} PUBLIC xeus-zmq-static )
267+ target_link_libraries (
268+ ${target_name}
269+ PUBLIC PkgConfig::octinterp
270+ PRIVATE glad::glad glfw
271+ )
272+
273+ if (XEUS_OCTAVE_USE_SHARED_XEUS_ZMQ)
274+ target_link_libraries (${target_name} PUBLIC xeus-zmq)
275+ else ()
276+ target_link_libraries (${target_name} PUBLIC xeus-zmq-static )
277+ endif ()
278+
279+ find_package (Threads)
280+ target_link_libraries (${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} )
238281 endif ()
239282
240- if (WIN32 OR CYGWIN )
241- #
242- elseif (APPLE )
283+ if (APPLE )
243284 target_link_libraries (${target_name} PRIVATE "-undefined dynamic_lookup" )
244285 endif ()
245- find_package (Threads)
246- target_link_libraries (${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} )
247286
248287endmacro ()
249288
@@ -272,9 +311,31 @@ endif()
272311# xeus-octave
273312# =======
274313if (XEUS_OCTAVE_BUILD_EXECUTABLE)
275- add_executable (xoctave ${XEUS_OCTAVE_MAIN_SRC} )
276- xeus_octave_set_common_options(xoctave)
277- xeus_octave_set_kernel_options(xoctave)
314+ if (NOT EMSCRIPTEN)
315+ add_executable (xoctave ${XEUS_OCTAVE_MAIN_SRC} )
316+ xeus_octave_set_common_options(xoctave)
317+ xeus_octave_set_kernel_options(xoctave)
318+ else ()
319+ include (WasmBuildOptions)
320+ add_executable (xoctave ${XEUS_OCTAVE_MAIN_WASM_SRC} )
321+ target_link_libraries (xoctave PRIVATE xeus-lite)
322+ xeus_octave_set_kernel_options(xoctave)
323+
324+ xeus_wasm_compile_options(xoctave)
325+ xeus_wasm_link_options(xoctave "web,worker" )
326+ target_compile_options (xoctave PRIVATE ${octinterp_CFLAGS} )
327+ target_link_options (
328+ xoctave
329+ PUBLIC
330+ "SHELL: --pre-js ${CMAKE_CURRENT_SOURCE_DIR} /wasm/env_vars.js"
331+ PUBLIC
332+ "SHELL: --post-js ${CMAKE_CURRENT_SOURCE_DIR} /wasm/post.js"
333+ PRIVATE
334+ ${octinterp_LDFLAGS}
335+ PRIVATE
336+ "SHELL: -L${CMAKE_INSTALL_PREFIX} /lib -lfreetype -lFortranDecimal -Wl,--allow-multiple-definition"
337+ )
338+ endif ()
278339endif ()
279340
280341# Installation
@@ -384,3 +445,10 @@ if(XEUS_OCTAVE_BUILD_SHARED)
384445 DESTINATION ${XEUS_OCTAVE_CMAKECONFIG_INSTALL_DIR}
385446 )
386447endif ()
448+
449+ if (EMSCRIPTEN)
450+ install (
451+ FILES "$<TARGET_FILE_DIR:xoctave>/xoctave.js" "$<TARGET_FILE_DIR:xoctave>/xoctave.wasm"
452+ DESTINATION ${CMAKE_INSTALL_BINDIR}
453+ )
454+ endif ()
0 commit comments