@@ -50,9 +50,9 @@ OPTION(XEUS_CPP_BUILD_EXECUTABLE "Build the xcpp executable" ON)
5050OPTION (XEUS_CPP_USE_SHARED_XEUS "Link xcpp with the xeus shared library (instead of the static library)" ON )
5151OPTION (XEUS_CPP_USE_SHARED_XEUS_CPP "Link xcpp with the xeus shared library (instead of the static library)" ON )
5252
53- OPTION (XEUS_CPP_EMSCRIPTEN_WASM_BUILD "Build for wasm with emscripten" OFF )
5453
55- if (XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
54+
55+ if (EMSCRIPTEN)
5656 add_compile_definitions (XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
5757 message ("Build with emscripten" )
5858 SET (XEUS_CPP_BUILD_STATIC ON )
9090endif ()
9191
9292if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel" )
93- if (NOT XEUS_CPP_EMSCRIPTEN_WASM_BUILD )
93+ if (NOT EMSCRIPTEN )
9494 add_compile_options (-Wunused-parameter -Wextra -Wreorder)
9595 endif ()
9696
@@ -103,7 +103,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
103103 endif ()
104104endif ()
105105
106- if (XEUS_CPP_EMSCRIPTEN_WASM_BUILD )
106+ if (EMSCRIPTEN )
107107 # ENV (https://github.com/emscripten-core/emscripten/commit/6d9681ad04f60b41ef6345ab06c29bbc9eeb84e0)
108108 set (EMSCRIPTEN_FEATURES "${EMSCRIPTEN_FEATURES} -s \" EXTRA_EXPORTED_RUNTIME_METHODS=[ENV']\" " )
109109endif ()
@@ -131,6 +131,10 @@ set(XEUS_CPP_SRC
131131 src/xparser.cpp
132132)
133133
134+ if (EMSCRIPTEN)
135+ list (APPEND XEUS_CPP_SRC src/xinterpreter_wasm.cpp)
136+ endif ()
137+
134138set (XEUS_CPP_MAIN_SRC
135139 src/main.cpp
136140)
@@ -192,7 +196,7 @@ macro(xeus_cpp_set_kernel_options target_name)
192196 target_link_libraries (${target_name} PRIVATE xeus-cpp-static )
193197 endif ()
194198
195- if (NOT XEUS_CPP_EMSCRIPTEN_WASM_BUILD )
199+ if (NOT EMSCRIPTEN )
196200 find_package (Threads)
197201 target_link_libraries (${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} )
198202 endif ()
@@ -238,7 +242,7 @@ macro(xeus_cpp_create_target target_name linkage output_name)
238242 elseif (APPLE )
239243 target_link_libraries (${target_name} PRIVATE "-undefined dynamic_lookup" )
240244 endif ()
241- if (NOT XEUS_CPP_EMSCRIPTEN_WASM_BUILD )
245+ if (NOT EMSCRIPTEN )
242246 find_package (Threads) # TODO: add Threads as a dependence of xeus-static?
243247 target_link_libraries (${target_name} PRIVATE ${CMAKE_THREAD_LIBS_INIT} )
244248 endif ()
@@ -291,14 +295,14 @@ if (XEUS_CPP_BUILD_EXECUTABLE)
291295 target_link_libraries (xcpp PRIVATE xeus-zmq)
292296endif ()
293297
294- if (XEUS_CPP_EMSCRIPTEN_WASM_BUILD )
298+ if (EMSCRIPTEN )
295299 include (WasmBuildOptions)
296300 find_package (xeus-lite REQUIRED)
297- add_executable (xcpp_wasm src/main_emscripten_kernel.cpp )
298- target_link_libraries (xcpp_wasm PRIVATE xeus-lite)
299- xeus_cpp_set_kernel_options(xcpp_wasm )
300- xeus_wasm_compile_options(xcpp_wasm )
301- xeus_wasm_link_options(xcpp_wasm "web,worker" )
301+ add_executable (xcpp src/main_emscripten_kernel.cpp )
302+ target_link_libraries (xcpp PRIVATE xeus-lite)
303+ xeus_cpp_set_kernel_options(xcpp )
304+ xeus_wasm_compile_options(xcpp )
305+ xeus_wasm_link_options(xcpp "web,worker" )
302306endif ()
303307
304308# Installation
@@ -325,7 +329,9 @@ endif ()
325329if (XEUS_CPP_BUILD_EXECUTABLE)
326330 install (TARGETS xcpp
327331 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
332+ endif ()
328333
334+ if (XEUS_CPP_BUILD_EXECUTABLE OR EMSCRIPTEN)
329335 # Configuration and data directories for jupyter and xeus-cpp
330336 set (XJUPYTER_DATA_DIR "share/jupyter" CACHE STRING "Jupyter data directory" )
331337
@@ -391,13 +397,13 @@ if (XEUS_CPP_BUILD_SHARED)
391397 DESTINATION ${XEUS_CPP_CMAKECONFIG_INSTALL_DIR} )
392398endif ()
393399
394- if (XEUS_CPP_EMSCRIPTEN_WASM_BUILD )
395- install (TARGETS xcpp_wasm
400+ if (EMSCRIPTEN )
401+ install (TARGETS xcpp
396402 ARCHIVE DESTINATION ${XEUS_CPP_CMAKECONFIG_INSTALL_DIR} )
397403
398404 install (FILES
399- "$<TARGET_FILE_DIR:xcpp_wasm>/xcpp_wasm .js"
400- "$<TARGET_FILE_DIR:xcpp_wasm>/xcpp_wasm .wasm"
405+ "$<TARGET_FILE_DIR:xcpp>/xcpp .js"
406+ "$<TARGET_FILE_DIR:xcpp>/xcpp .wasm"
401407 DESTINATION ${CMAKE_INSTALL_BINDIR} )
402408endif ()
403409
0 commit comments