CMakeLists.txt 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. if (APPLE)
  4. set (HAVE_FLAG_SEARCH_PATHS_FIRST 0)
  5. set (CMAKE_C_LINK_FLAGS "")
  6. set (CMAKE_CXX_LINK_FLAGS "")
  7. endif ()
  8. if (NOT DEFINED WASI_SDK_DIR)
  9. set (WASI_SDK_DIR "/opt/wasi-sdk")
  10. endif ()
  11. if (DEFINED WASI_SYSROOT)
  12. set (CMAKE_SYSROOT "${WASI_SYSROOT}")
  13. endif ()
  14. set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang")
  15. set (CMAKE_ASM_COMPILER "${WASI_SDK_DIR}/bin/clang")
  16. set (CMAKE_EXE_LINKER_FLAGS "-target wasm32-wasi-threads")
  17. if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1)
  18. set (CMAKE_C_FLAGS "")
  19. set (CMAKE_CXX_FLAGS "")
  20. endif ()
  21. function (compile_sample SOURCE_FILE)
  22. get_filename_component (FILE_NAME ${SOURCE_FILE} NAME_WLE)
  23. set (WASM_MODULE ${FILE_NAME}.wasm)
  24. add_executable (${WASM_MODULE} ${SOURCE_FILE} ${ARGN})
  25. target_compile_options (${WASM_MODULE} PRIVATE
  26. -pthread -ftls-model=local-exec)
  27. target_link_options (${WASM_MODULE} PRIVATE
  28. -z stack-size=32768
  29. LINKER:--export=__heap_base
  30. LINKER:--export=__data_end
  31. LINKER:--shared-memory,--max-memory=1966080
  32. LINKER:--export=wasi_thread_start
  33. LINKER:--export=malloc
  34. LINKER:--export=free
  35. )
  36. endfunction ()
  37. compile_sample(no_pthread.c wasi_thread_start.S)