CMakeLists.txt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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(native_lib)
  6. ################ runtime settings ##############
  7. string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
  8. if (APPLE)
  9. add_definitions(-DBH_PLATFORM_DARWIN)
  10. endif ()
  11. # Reset default linker flags
  12. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  13. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  14. # WAMR features switch
  15. # Set WAMR_BUILD_TARGET, currently values supported are:
  16. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  17. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  18. if (NOT DEFINED WAMR_BUILD_TARGET)
  19. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
  20. set (WAMR_BUILD_TARGET "AARCH64")
  21. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  22. set (WAMR_BUILD_TARGET "RISCV64")
  23. elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
  24. # Build as X86_64 by default in 64-bit platform
  25. set (WAMR_BUILD_TARGET "X86_64")
  26. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  27. # Build as X86_32 by default in 32-bit platform
  28. set (WAMR_BUILD_TARGET "X86_32")
  29. else ()
  30. message(SEND_ERROR "Unsupported build target platform!")
  31. endif ()
  32. endif ()
  33. if (NOT CMAKE_BUILD_TYPE)
  34. set (CMAKE_BUILD_TYPE Release)
  35. endif ()
  36. set (WAMR_BUILD_INTERP 1)
  37. set (WAMR_BUILD_AOT 1)
  38. set (WAMR_BUILD_JIT 0)
  39. set (WAMR_BUILD_LIBC_BUILTIN 1)
  40. set (WAMR_BUILD_FAST_INTERP 1)
  41. # compiling and linking flags
  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. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
  46. # build out libiwasm
  47. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
  48. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  49. # Note: we build libiwasm as a shared library here so that it can be
  50. # shared between iwasm and native libraries.
  51. add_library(libiwasm SHARED ${WAMR_RUNTIME_LIB_SOURCE})
  52. set_target_properties (libiwasm PROPERTIES OUTPUT_NAME iwasm)
  53. ################ wamr runtime ###################
  54. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  55. set (RUNTIME_SOURCE_ALL
  56. ${WAMR_ROOT_DIR}/product-mini/platforms/posix/main.c
  57. ${UNCOMMON_SHARED_SOURCE}
  58. )
  59. add_executable (iwasm ${RUNTIME_SOURCE_ALL})
  60. check_pie_supported()
  61. set_target_properties (iwasm PROPERTIES POSITION_INDEPENDENT_CODE ON)
  62. target_link_libraries(iwasm libiwasm -lpthread -lm -ldl)
  63. ################ native libraries ###############
  64. add_library (test_add SHARED test_add.c)
  65. add_library (test_sqrt SHARED test_sqrt.c)
  66. add_library (test_hello SHARED test_hello.c)
  67. # Note: Unlike simpler examples above, test_hello2 directly uses
  68. # the API provided by the libiwasm library.
  69. add_library (test_hello2 SHARED test_hello2.c)
  70. target_link_libraries(test_hello2 libiwasm)
  71. ################ wasm application ###############
  72. add_subdirectory(wasm-app)