CMakeLists.txt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(custom_section)
  7. else()
  8. project(custom_section 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. set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  16. set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  17. if(NOT DEFINED WAMR_BUILD_TARGET)
  18. if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
  19. set(WAMR_BUILD_TARGET "AARCH64")
  20. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  21. set(WAMR_BUILD_TARGET "RISCV64")
  22. elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
  23. set(WAMR_BUILD_TARGET "X86_64")
  24. elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
  25. set(WAMR_BUILD_TARGET "X86_32")
  26. else()
  27. message(SEND_ERROR "Unsupported build target platform!")
  28. endif()
  29. endif()
  30. if(NOT CMAKE_BUILD_TYPE)
  31. set(CMAKE_BUILD_TYPE Debug)
  32. endif()
  33. set(WAMR_BUILD_INTERP 1)
  34. set(WAMR_BUILD_AOT 1)
  35. set(WAMR_BUILD_JIT 0)
  36. set(WAMR_BUILD_LIBC_BUILTIN 1)
  37. set(WAMR_BUILD_LOAD_CUSTOM_SECTION 1)
  38. if(NOT MSVC)
  39. set(WAMR_BUILD_LIBC_WASI 1)
  40. endif()
  41. if(NOT MSVC)
  42. if(NOT(CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
  43. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
  44. endif()
  45. endif()
  46. set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
  47. include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  48. add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  49. # ############### application related ################
  50. include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
  51. include(${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  52. add_executable(custom_section
  53. src/main.c
  54. src/native_impl.c
  55. ${UNCOMMON_SHARED_SOURCE}
  56. )
  57. check_pie_supported()
  58. set_target_properties(custom_section PROPERTIES POSITION_INDEPENDENT_CODE ON)
  59. if(APPLE)
  60. target_link_libraries(custom_section vmlib -lm -ldl -lpthread)
  61. else()
  62. target_link_libraries(custom_section vmlib -lm -ldl -lpthread -lrt)
  63. endif()