Skip to content

Commit

Permalink
Update CMake files for Emscripten support
Browse files Browse the repository at this point in the history
Lower CMake version requirement to 3.22 and adjust `target_link_options` for Emscripten. Conditionalize `target_link_libraries` for Emscripten in both main and extras CMakeLists.
  • Loading branch information
matthew-mccall committed Jul 24, 2024
1 parent a2ea351 commit 6577b84
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.28)
cmake_minimum_required(VERSION 3.22)
project(OasisC CXX C)

add_subdirectory(libs/Oasis)
Expand All @@ -14,7 +14,7 @@ set(OasisC_SOURCES
if (DEFINED EMSCRIPTEN)
add_executable(OasisC ${OasisC_SOURCES})
set(CMAKE_EXECUTABLE_SUFFIX ".mjs")
target_link_options(OasisC PUBLIC -sSINGLE_FILE --no-entry "-s EXPORT_NAME='OasisC'" "-s EXPORTED_RUNTIME_METHODS='[\"ccall\", \"cwrap\"]'")
target_link_options(OasisC PUBLIC -sSINGLE_FILE --no-entry "-sEXPORT_NAME='OasisC'" "-sEXPORTED_RUNTIME_METHODS=ccall,cwrap")
else ()
add_library(OasisC ${OasisC_SOURCES})
endif ()
Expand All @@ -28,5 +28,7 @@ endif()

if(OASIS_BUILD_EXTRAS)
add_subdirectory(extras)
target_link_libraries(OasisC PUBLIC OasisCExtras)
if (DEFINED EMSCRIPTEN)
target_link_libraries(OasisC PUBLIC OasisCExtras)
endif ()
endif()
8 changes: 6 additions & 2 deletions extras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ set(OasisC_EXTRAS_SOURCES
# cmake-format: sortable
src/FromString.cpp src/MathMLSerializer.cpp)

add_library(OasisCExtras ${OasisC_EXTRAS_SOURCES})

if (DEFINED EMSCRIPTEN)
add_library(OasisCExtras OBJECT ${OasisC_EXTRAS_SOURCES})
else ()
add_library(OasisCExtras ${OasisC_EXTRAS_SOURCES})
endif ()

target_include_directories(OasisCExtras
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(OasisCExtras PUBLIC Oasis::Oasis Oasis::Extras)
Expand Down

0 comments on commit 6577b84

Please sign in to comment.