CMakeLists.txt 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.0)
  4. project(native_lib)
  5. ################ runtime settings ##############
  6. string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
  7. if (APPLE)
  8. add_definitions(-DBH_PLATFORM_DARWIN)
  9. endif ()
  10. # Reset default linker flags
  11. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  12. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  13. # WAMR features switch
  14. # Set WAMR_BUILD_TARGET, currently values supported are:
  15. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  16. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  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. # Build as X86_64 by default in 64-bit platform
  24. set (WAMR_BUILD_TARGET "X86_64")
  25. else ()
  26. # Build as X86_32 by default in 32-bit platform
  27. set (WAMR_BUILD_TARGET "X86_32")
  28. endif ()
  29. endif ()
  30. if (NOT CMAKE_BUILD_TYPE)
  31. set (CMAKE_BUILD_TYPE Release)
  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_FAST_INTERP 1)
  38. # compiling and linking flags
  39. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -fPIE")
  40. if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
  41. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
  42. endif ()
  43. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
  44. # build out vmlib
  45. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
  46. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  47. add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  48. ################ wamr runtime ###################
  49. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  50. set (RUNTIME_SOURCE_ALL
  51. ${WAMR_ROOT_DIR}/product-mini/platforms/posix/main.c
  52. ${UNCOMMON_SHARED_SOURCE}
  53. )
  54. add_executable (iwasm ${RUNTIME_SOURCE_ALL})
  55. target_link_libraries(iwasm vmlib -lpthread -lm -ldl)
  56. ################ native libraries ###############
  57. add_library (test_add SHARED test_add.c)
  58. add_library (test_sqrt SHARED test_sqrt.c)
  59. ################ wasm application ###############
  60. add_subdirectory(wasm-app)