CMakeLists.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 (native-stack-overflow)
  7. else()
  8. project (native-stack-overflow C ASM)
  9. endif()
  10. set(CMAKE_C_STANDARD 11)
  11. set(CMAKE_C_EXTENSIONS YES)
  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. # Reset default 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 0)
  46. set (WAMR_BUILD_LIBC_WASI 1)
  47. if (NOT MSVC)
  48. # linker flags
  49. if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
  50. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
  51. endif ()
  52. endif ()
  53. if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 13.0.0)
  54. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-usage")
  55. endif ()
  56. # GCC doesn't have disable_tail_calls attribute
  57. if (CMAKE_C_COMPILER_ID MATCHES "GNU")
  58. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-optimize-sibling-calls")
  59. endif ()
  60. # build out vmlib
  61. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
  62. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  63. add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  64. ################ application related ################
  65. include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
  66. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  67. add_executable (native-stack-overflow src/main.c src/native_impl.c ${UNCOMMON_SHARED_SOURCE})
  68. check_pie_supported()
  69. set_target_properties (native-stack-overflow PROPERTIES POSITION_INDEPENDENT_CODE ON)
  70. if (APPLE)
  71. target_link_libraries (native-stack-overflow vmlib -lm -ldl -lpthread)
  72. else ()
  73. target_link_libraries (native-stack-overflow vmlib -lm -ldl -lpthread -lrt)
  74. endif ()