CMakeLists.txt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  26. # Build as X86_32 by default in 32-bit platform
  27. set (WAMR_BUILD_TARGET "X86_32")
  28. else ()
  29. message(SEND_ERROR "Unsupported build target platform!")
  30. endif ()
  31. endif ()
  32. if (NOT CMAKE_BUILD_TYPE)
  33. set (CMAKE_BUILD_TYPE Release)
  34. endif ()
  35. set (WAMR_BUILD_INTERP 1)
  36. set (WAMR_BUILD_AOT 1)
  37. set (WAMR_BUILD_JIT 0)
  38. set (WAMR_BUILD_LIBC_BUILTIN 1)
  39. set (WAMR_BUILD_FAST_INTERP 1)
  40. # compiling and linking flags
  41. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -fPIE")
  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 vmlib
  47. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
  48. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  49. add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  50. ################ wamr runtime ###################
  51. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  52. set (RUNTIME_SOURCE_ALL
  53. ${WAMR_ROOT_DIR}/product-mini/platforms/posix/main.c
  54. ${UNCOMMON_SHARED_SOURCE}
  55. )
  56. add_executable (iwasm ${RUNTIME_SOURCE_ALL})
  57. target_link_libraries(iwasm vmlib -lpthread -lm -ldl)
  58. ################ native libraries ###############
  59. add_library (test_add SHARED test_add.c)
  60. add_library (test_sqrt SHARED test_sqrt.c)
  61. ################ wasm application ###############
  62. add_subdirectory(wasm-app)