diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cb531bb..aecefd76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,11 +127,33 @@ endif() ######################################################### +# Add conditional compilation for Emscripten +if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + set(CMAKE_EXECUTABLE_SUFFIX ".js") # Set the output suffix to .js for WebAssembly + + add_executable(${PROJECT_NAME} ${SRCS_COMMON} ${HDRS_COMMON} ${ACT_GENERATED_SOURCE} ${VERSION_FILES_OUTPUTLOCATION}) + + # Emscripten-specific linker options + target_link_options(${PROJECT_NAME} PRIVATE + "-s MODULARIZE=1" # Wrap the output in a module + "-s EXPORT_ALL=1" # Export all functions + "-s ALLOW_MEMORY_GROWTH=1" # Allow dynamic memory growth + "--bind" # Enables embind support (optional if you’re using embind) + "--whole-archive" + ) + SOURCE_GROUP("Source Files\\Autogenerated" FILES ${ACT_GENERATED_SOURCE}) +else() + # For non-Emscripten builds, keep the original library setup + add_library(${PROJECT_NAME} STATIC ${SRCS_COMMON} ${HDRS_COMMON} ${ACT_GENERATED_SOURCE} ${VERSION_FILES_OUTPUTLOCATION}) + SOURCE_GROUP("Source Files\\Autogenerated" FILES ${ACT_GENERATED_SOURCE}) +endif () + + # Shared library -add_library(${PROJECT_NAME} STATIC ${SRCS_COMMON} ${HDRS_COMMON} - ${ACT_GENERATED_SOURCE} - ${VERSION_FILES_OUTPUTLOCATION} -) +#add_library(${PROJECT_NAME} STATIC ${SRCS_COMMON} ${HDRS_COMMON} +# ${ACT_GENERATED_SOURCE} +# ${VERSION_FILES_OUTPUTLOCATION} +#) #if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") # add_library(${PROJECT_NAME} STATIC ${SRCS_COMMON} ${HDRS_COMMON} # ${ACT_GENERATED_SOURCE} @@ -143,7 +165,6 @@ add_library(${PROJECT_NAME} STATIC ${SRCS_COMMON} ${HDRS_COMMON} # ${VERSION_FILES_OUTPUTLOCATION} # ) #endif () -SOURCE_GROUP("Source Files\\Autogenerated" FILES ${ACT_GENERATED_SOURCE})