CMakeLists.txt 2.8 KB

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