CMakeLists.txt 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. include(CheckPIESupported)
  5. project (terminate)
  6. set (CMAKE_CXX_STANDARD 17)
  7. ################ runtime settings ################
  8. string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
  9. if (APPLE)
  10. add_definitions(-DBH_PLATFORM_DARWIN)
  11. endif ()
  12. # Reset default linker flags
  13. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  14. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  15. # WAMR features switch
  16. # Set WAMR_BUILD_TARGET, currently values supported:
  17. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  18. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  19. if (NOT DEFINED WAMR_BUILD_TARGET)
  20. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
  21. set (WAMR_BUILD_TARGET "AARCH64")
  22. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  23. set (WAMR_BUILD_TARGET "RISCV64")
  24. elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
  25. # Build as X86_64 by default in 64-bit platform
  26. set (WAMR_BUILD_TARGET "X86_64")
  27. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  28. # Build as X86_32 by default in 32-bit platform
  29. set (WAMR_BUILD_TARGET "X86_32")
  30. else ()
  31. message(SEND_ERROR "Unsupported build target platform!")
  32. endif ()
  33. endif ()
  34. if (NOT CMAKE_BUILD_TYPE)
  35. set (CMAKE_BUILD_TYPE Debug)
  36. endif ()
  37. set (WAMR_BUILD_LIBC_WASI 1)
  38. set (WAMR_BUILD_LIB_WASI_THREADS 1)
  39. set (WAMR_BUILD_THREAD_MGR 1)
  40. set (WAMR_BUILD_INTERP 1)
  41. set (WAMR_BUILD_AOT 1)
  42. set (WAMR_BUILD_JIT 0)
  43. # fast interpreter
  44. # set (WAMR_BUILD_FAST_INTERP 1)
  45. # fast-jit
  46. # set (WAMR_BUILD_FAST_JIT 1)
  47. # llvm jit
  48. # set (WAMR_BUILD_JIT 1)
  49. # set (LLVM_DIR /usr/local/opt/llvm@14/lib/cmake/llvm)
  50. set (WAMR_BUILD_REF_TYPES 1)
  51. if (NOT MSVC)
  52. # linker flags
  53. if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
  54. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
  55. endif ()
  56. endif ()
  57. # build out vmlib
  58. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
  59. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  60. add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  61. ################ application related ################
  62. include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
  63. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  64. add_executable (terminate src/main.c ${UNCOMMON_SHARED_SOURCE})
  65. check_pie_supported()
  66. set_target_properties (terminate PROPERTIES POSITION_INDEPENDENT_CODE ON)
  67. if (APPLE)
  68. target_link_libraries (terminate vmlib -lm -ldl -lpthread ${LLVM_AVAILABLE_LIBS})
  69. else ()
  70. target_link_libraries (terminate vmlib -lm -ldl -lpthread -lrt ${LLVM_AVAILABLE_LIBS})
  71. endif ()