From ba7bf3dde0dc73429dd5530b83e5dc4317ac27a7 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Wed, 21 Aug 2024 03:51:34 +0900 Subject: [PATCH] add cmakelists.txt to build tinyusdz wasm --- web/CMakeLists.txt | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 web/CMakeLists.txt diff --git a/web/CMakeLists.txt b/web/CMakeLists.txt new file mode 100644 index 00000000..b9d1849e --- /dev/null +++ b/web/CMakeLists.txt @@ -0,0 +1,59 @@ +# Assume this project is invoked by emcmake. +cmake_minimum_required(VERSION 3.5.1) + +set(BUILD_TARGET "tinyusdz") + +if (NOT EMSCRIPTEN) + message(FATAL "Must be compiled with emscripten") +endif() + +project(${BUILD_TARGET} CXX C) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# cmake modules +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake) +#list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake/sanitizers) +#find_package(Sanitizers) # Address sanitizer (-DSANITIZE_ADDRESS=ON) + +# [tinyusdz] +add_subdirectory(../ tinyusdz) + +list( + APPEND + SOURCES + binding.cc +) + + +add_executable(${BUILD_TARGET} ${SOURCES}) +add_sanitizers(${BUILD_TARGET}) + +target_compile_options(${BUILD_TARGET} PRIVATE ${EXT_COMPILE_OPTIONS}) + +# tinyusdz dir +target_include_directories(${BUILD_TARGET} + PRIVATE "${PROJECT_SOURCE_DIR}/../src/") + + +target_link_libraries(${BUILD_TARGET} PRIVATE tinyusdz::tinyusdz_static + ${EXT_LIBRARIES} PUBLIC ${CMAKE_DL_LIBS}) + +source_group("Source Files" FILES ${SOURCES}) + +if (EMSCRIPTEN) + set_target_properties( + ${BUILD_TARGET} + PROPERTIES OUTPUT_NAME tinyusdz + SUFFIX ".js" + RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/dist) + #set(CMAKE_EXECUTABLE_SUFFIX ".html") +endif() + +# TODO: Adjust memory size. +set_target_properties(${BUILD_TARGET} PROPERTIES LINK_FLAGS "-s INITIAL_MEMORY=32MB -s TOTAL_MEMORY=256MB -sTOTAL_STACK=32MB -sASSERTIONS -s ALLOW_MEMORY_GROWTH=1 -s WASM=1 -sMODULARIZE -sEXPORT_ES6=1 --bind") + +# ENVIRONMENT=web +# SINGLE_FILE=1