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