CMakeLists.txt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. cmake_minimum_required(VERSION 3.14)
  4. project(wasm-apps)
  5. set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
  6. set(CMAKE_SYSTEM_PROCESSOR wasm32)
  7. set(CMAKE_SYSROOT ${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot)
  8. if (NOT DEFINED WASI_SDK_DIR)
  9. set(WASI_SDK_DIR "/opt/wasi-sdk")
  10. endif ()
  11. set(CMAKE_C_FLAGS "-nostdlib -pthread -Qunused-arguments")
  12. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z stack-size=8192 -nostdlib")
  13. set(CMAKE_C_COMPILER_TARGET "wasm32")
  14. set(CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang")
  15. set(DEFINED_SYMBOLS
  16. "${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt")
  17. set(CMAKE_EXE_LINKER_FLAGS
  18. "-Wl,--no-entry \
  19. -Wl,--initial-memory=65536 \
  20. -Wl,--export-all \
  21. -Wl,--allow-undefined"
  22. )
  23. add_executable(mytest.wasm mytest.c)
  24. target_link_libraries(mytest.wasm)
  25. add_executable(hello.wasm hello.c)
  26. target_link_libraries(hello.wasm)
  27. add_custom_command(TARGET hello.wasm POST_BUILD
  28. COMMAND ${CMAKE_COMMAND} -E copy
  29. ${CMAKE_CURRENT_BINARY_DIR}/hello.wasm
  30. ${CMAKE_CURRENT_BINARY_DIR}/../
  31. COMMENT "Copy hello.wasm to the same directory of google test"
  32. )
  33. add_custom_command(TARGET mytest.wasm POST_BUILD
  34. COMMAND ${CMAKE_COMMAND} -E copy
  35. ${CMAKE_CURRENT_BINARY_DIR}/mytest.wasm
  36. ${CMAKE_CURRENT_BINARY_DIR}/../
  37. COMMENT "Copy mytest.wasm to the same directory of google test"
  38. )