Skip to content

Commit e876931

Browse files
committed
Support shared build for xeus-cpp-lite
1 parent 3fe6a48 commit e876931

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
cmake_minimum_required(VERSION 3.8)
1010
project(xwidgets)
1111

12+
if(EMSCRIPTEN)
13+
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
14+
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-s SIDE_MODULE=1")
15+
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-s SIDE_MODULE=1")
16+
set(CMAKE_STRIP FALSE)
17+
18+
# Define the path to the shared library for use with CppInterOp dynamic loading
19+
set(XWIDGETS_CPPINTEROP_LIBRARY_PATH "\"/lib/${CMAKE_SHARED_LIBRARY_PREFIX}xwidgets${CMAKE_SHARED_LIBRARY_SUFFIX}\"")
20+
message(STATUS "XWIDGETS_CPPINTEROP_LIBRARY_PATH = ${XWIDGETS_CPPINTEROP_LIBRARY_PATH}")
21+
endif()
22+
1223
set(XWIDGETS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
1324
set(XWIDGETS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
1425

@@ -157,6 +168,9 @@ macro(xwidgets_create_target target_name linkage output_name)
157168
)
158169

159170
target_link_libraries(${target_name} PUBLIC ${XEUS_TARGET_NAME} xproperty)
171+
if(EMSCRIPTEN)
172+
set_target_properties(${target_name} PROPERTIES NO_SONAME 1)
173+
endif()
160174

161175
set_target_properties(
162176
${target_name}
@@ -182,7 +196,11 @@ macro(xwidgets_create_target target_name linkage output_name)
182196
OR CMAKE_CXX_COMPILER_ID MATCHES "GNU"
183197
OR CMAKE_CXX_COMPILER_ID MATCHES "Intel"
184198
)
185-
target_compile_options(${target_name} PUBLIC -Wunused-parameter -Wextra -Wreorder)
199+
if(EMSCRIPTEN)
200+
target_compile_options(${target_name} PRIVATE -fPIC)
201+
else ()
202+
target_compile_options(${target_name} PUBLIC -Wunused-parameter -Wextra -Wreorder)
203+
endif()
186204

187205
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
188206
endif()

include/xwidgets/xwidgets_config.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,8 @@
106106
#include "xwidgets_config_cling.hpp"
107107
#endif
108108

109+
#if defined(__CLANG_REPL__) && defined(__EMSCRIPTEN__)
110+
#include "xwidgets_config_cling.hpp"
111+
#endif
112+
109113
#endif

include/xwidgets/xwidgets_config_cling.hpp.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@
99
#ifndef XWIDGETS_CONFIG_CLING_HPP
1010
#define XWIDGETS_CONFIG_CLING_HPP
1111

12+
#ifdef __CLING__
13+
1214
#pragma cling add_library_path(@XWIDGETS_INSTALL_LIBRARY_DIR@)
1315
#pragma cling load("libxwidgets")
1416

17+
#elif defined(__EMSCRIPTEN__) && defined(__CLANG_REPL__)
18+
19+
#include <clang/Interpreter/CppInterOp.h>
20+
static bool _xwidgets_loaded = []() {
21+
Cpp::LoadLibrary(@XWIDGETS_CPPINTEROP_LIBRARY_PATH@, false);
22+
return true;
23+
}();
24+
1525
#endif
26+
27+
#endif // XWIDGETS_CONFIG_CLING_HPP

0 commit comments

Comments
 (0)