CMakeLists.txt 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. cmake_minimum_required(VERSION 3.14)
  4. include(CheckPIESupported)
  5. project(wasi_threads_sample)
  6. if (NOT DEFINED WASI_SYSROOT)
  7. message (WARNING "Custom sysroot with threads enabled is required to build wasi threads samples.
  8. Please note that current wasi-sdk doesn't ship with threads enabled.
  9. Run cmake command with -DWASI_SYSROOT=/path/to/sysroot/with/threads to compile samples.")
  10. return ()
  11. endif ()
  12. ################ runtime settings ################
  13. string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
  14. if (APPLE)
  15. add_definitions(-DBH_PLATFORM_DARWIN)
  16. endif ()
  17. # Resetdefault linker flags
  18. set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  19. set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  20. # WAMR features switch
  21. # Set WAMR_BUILD_TARGET, currently values supported:
  22. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  23. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  24. if (NOT DEFINED WAMR_BUILD_TARGET)
  25. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
  26. set (WAMR_BUILD_TARGET "AARCH64")
  27. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  28. set (WAMR_BUILD_TARGET "RISCV64")
  29. elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
  30. # Build as X86_64 by default in 64-bit platform
  31. set (WAMR_BUILD_TARGET "X86_64")
  32. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  33. # Build as X86_32 by default in 32-bit platform
  34. set (WAMR_BUILD_TARGET "X86_32")
  35. else ()
  36. message(SEND_ERROR "Unsupported build target platform!")
  37. endif ()
  38. endif ()
  39. if (NOT CMAKE_BUILD_TYPE)
  40. set (CMAKE_BUILD_TYPE Release)
  41. endif ()
  42. set(WAMR_BUILD_INTERP 1)
  43. set(WAMR_BUILD_AOT 1)
  44. set(WAMR_BUILD_JIT 0)
  45. set(WAMR_BUILD_LIBC_BUILTIN 1)
  46. set(WAMR_BUILD_FAST_INTERP 1)
  47. set(WAMR_BUILD_LIBC_WASI 1)
  48. set(WAMR_BUILD_LIB_WASI_THREADS 1)
  49. # compiling and linking flags
  50. if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
  51. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
  52. endif ()
  53. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
  54. # build out vmlib
  55. set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
  56. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  57. add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  58. ################################################
  59. ################ wasm application ################
  60. add_subdirectory(wasm-apps)
  61. ################ wamr runtime ################
  62. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  63. set (RUNTIME_SOURCE_ALL
  64. ${CMAKE_CURRENT_LIST_DIR}/../../product-mini/platforms/linux/main.c
  65. ${UNCOMMON_SHARED_SOURCE}
  66. )
  67. add_executable (iwasm ${RUNTIME_SOURCE_ALL})
  68. check_pie_supported()
  69. set_target_properties (iwasm PROPERTIES POSITION_INDEPENDENT_CODE ON)
  70. target_link_libraries(iwasm vmlib -lpthread -lm -ldl)