From f8e2ea2b1a7a2a002a595e96fc7c5e1e10fc3128 Mon Sep 17 00:00:00 2001 From: Vijai Kumar S <2363451+vijaiaeroastro@users.noreply.github.com> Date: Sun, 20 Oct 2024 13:08:14 +0200 Subject: [PATCH] Emscripten build works and produces a static library --- CMakeLists.txt | 22 ++++++++++++++++++---- emscripten_build_notes.txt | 3 +++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 emscripten_build_notes.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index fac4a8fc9..374773296 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,13 @@ cmake_policy(SET CMP0048 NEW) set_property(GLOBAL PROPERTY USE_FOLDERS ON) +if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + set(CMAKE_CXX_COMPILER_WORKS TRUE) + set(CMAKE_C_COMPILER_WORKS TRUE) + set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + set(VCPKG_TARGET_TRIPLET wasm32-emscripten) +endif() + # Automatically set the vcpkg toolchain file if vcpkg exists as a submodule if (EXISTS "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake") message("Using VCPKG Toolchain") @@ -116,10 +123,17 @@ endif() ######################################################### # Shared library -add_library(${PROJECT_NAME} SHARED ${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} + ${VERSION_FILES_OUTPUTLOCATION} + ) +else() + add_library(${PROJECT_NAME} SHARED ${SRCS_COMMON} ${HDRS_COMMON} + ${ACT_GENERATED_SOURCE} + ${VERSION_FILES_OUTPUTLOCATION} + ) +endif () SOURCE_GROUP("Source Files\\Autogenerated" FILES ${ACT_GENERATED_SOURCE}) diff --git a/emscripten_build_notes.txt b/emscripten_build_notes.txt new file mode 100644 index 000000000..7321f7fb9 --- /dev/null +++ b/emscripten_build_notes.txt @@ -0,0 +1,3 @@ +# Building a static library using emscripten compiler + +cmake .. -DCMAKE_SYSTEM_NAME=Emscripten \ No newline at end of file