From c0ae8892cc3473c92b2ac1be3193b4cf90640e34 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Fri, 23 Aug 2024 20:48:06 -0400 Subject: [PATCH] GH-609 Create Emscripten `.so` file --- CMakeLists.txt | 21 +++++++++++++++------ CMakePresets.json | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c49da96b..c9e41e4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,17 +148,26 @@ endif() TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") IF (NOT APPLE) - # Linker options for the GDExtension library - TARGET_LINK_OPTIONS(${PROJECT_NAME} PRIVATE - $<$: + # Check if we are using Emscripten + IF (CMAKE_CXX_COMPILER MATCHES "em\\+\\+|emcc") + # Emscripten-specific linker options (empty or specific to Emscripten) + # Do not add -R or $$ORIGIN here since Emscripten does not support them + TARGET_LINK_OPTIONS(${PROJECT_NAME} PRIVATE + # Emscripten does not need these options + ) + ELSE() + # Linker options for non-Emscripten platforms + TARGET_LINK_OPTIONS(${PROJECT_NAME} PRIVATE + $<$: -static-libgcc -static-libstdc++ -Wl,-R,'$$ORIGIN' $<$: - $<$:-s> + $<$:-s> > - > - ) + > + ) + ENDIF() ENDIF () if (AUTOFORMAT_SRC_ON_CONFIGURE MATCHES ON) diff --git a/CMakePresets.json b/CMakePresets.json index 8d55f8ef..e03d1338 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -92,7 +92,7 @@ "CMAKE_CXX_COMPILER": "em++", "CMAKE_TOOLCHAIN_FILE": "$env{EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake", "BUILD_SHARED_LIBS": "ON", - "CMAKE_CXX_FLAGS": "-s SIDE_MODULE=1 -shared" + "CMAKE_CXX_FLAGS": "-s SIDE_MODULE=1" } } ]