From c571915ef734836c24719b5ca3fe03cdeda4aa97 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Thu, 30 Jan 2025 09:52:19 +0530 Subject: [PATCH] fixes to build for WASM --- CMakeLists.txt | 34 ++++++++++++++++++++++++++-------- src/Cppyy.h | 2 +- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 253ec83d..f9b47ce3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,15 +11,27 @@ if (CMAKE_COMPILER_IS_GNUCXX) endif() message(STATUS "Looking for python ...") -set(Python_FIND_VIRTUALENV ONLY) -find_package (Python COMPONENTS Interpreter Development) -if (NOT Python_FOUND) - set(Python_FIND_VIRTUALENV STANDARD) - find_package (Python COMPONENTS Interpreter Development) -endif() -if (NOT Python_Development_FOUND) - message(FATAL_ERROR "Python development package not found and python component required") +if(NOT EMSCRIPTEN) + set(Python_FIND_VIRTUALENV ONLY) + find_package (Python COMPONENTS Interpreter Development) + if (NOT Python_FOUND) + set(Python_FIND_VIRTUALENV STANDARD) + find_package (Python COMPONENTS Interpreter Development) + endif() + + if (NOT Python_Development_FOUND) + message(FATAL_ERROR "Python development package not found and python component required") + endif() +else() + set(Python_INCLUDE_DIRS + "${CMAKE_PREFIX_PATH}/include/python3.11" + ) + + set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE) + set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-s SIDE_MODULE=1") + set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-s SIDE_MODULE=1") + set(CMAKE_STRIP FALSE) endif() include_directories("${PROJECT_SOURCE_DIR}/include" "${Python_INCLUDE_DIRS}") @@ -28,6 +40,12 @@ file (GLOB cppyy_src src/*.cxx) add_library(cppyy SHARED ${cppyy_src}) +if (EMSCRIPTEN) + target_link_options(cppyy + PUBLIC "SHELL: -s WASM_BIGINT" + ) +endif() + if(APPLE) set_target_properties(cppyy PROPERTIES LINK_FLAGS "-undefined dynamic_lookup") set_target_properties(cppyy PROPERTIES SUFFIX ".so") diff --git a/src/Cppyy.h b/src/Cppyy.h index d2eb42b3..8928602d 100644 --- a/src/Cppyy.h +++ b/src/Cppyy.h @@ -354,7 +354,7 @@ namespace Cppyy { CPPYY_IMPORT TCppType_t GetEnumConstantType(TCppScope_t scope); CPPYY_IMPORT - long long GetEnumDataValue(TCppScope_t scope); + TCppIndex_t GetEnumDataValue(TCppScope_t scope); CPPYY_IMPORT TCppScope_t InstantiateTemplate( TCppScope_t tmpl, Cpp::TemplateArgInfo* args, size_t args_size);