CMakeLists.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. project (iwasm)
  5. option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
  6. set (WAMR_BUILD_PLATFORM "darwin")
  7. # Reset default linker flags
  8. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
  9. set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
  10. # Set WAMR_BUILD_TARGET, currently values supported:
  11. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  12. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  13. if (NOT DEFINED WAMR_BUILD_TARGET)
  14. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
  15. set (WAMR_BUILD_TARGET "AARCH64")
  16. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  17. set (WAMR_BUILD_TARGET "RISCV64")
  18. elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
  19. # Build as X86_64 by default in 64-bit platform
  20. set (WAMR_BUILD_TARGET "X86_64")
  21. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  22. # Build as X86_32 by default in 32-bit platform
  23. set (WAMR_BUILD_TARGET "X86_32")
  24. else ()
  25. message(SEND_ERROR "Unsupported build target platform!")
  26. endif ()
  27. endif ()
  28. if (NOT CMAKE_BUILD_TYPE)
  29. set(CMAKE_BUILD_TYPE Release)
  30. endif ()
  31. set(CMAKE_CXX_STANDARD 17)
  32. if (NOT DEFINED WAMR_BUILD_INTERP)
  33. # Enable Interpreter by default
  34. set (WAMR_BUILD_INTERP 1)
  35. endif ()
  36. if (NOT DEFINED WAMR_BUILD_AOT)
  37. # Enable AOT by default.
  38. set (WAMR_BUILD_AOT 1)
  39. endif ()
  40. if (NOT DEFINED WAMR_BUILD_JIT)
  41. # Disable JIT by default.
  42. set (WAMR_BUILD_JIT 0)
  43. endif ()
  44. if (NOT DEFINED WAMR_BUILD_FAST_JIT)
  45. # Disable Fast JIT by default
  46. set (WAMR_BUILD_FAST_JIT 0)
  47. endif ()
  48. if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
  49. # Enable libc builtin support by default
  50. set (WAMR_BUILD_LIBC_BUILTIN 1)
  51. endif ()
  52. if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
  53. # Enable libc wasi support by default
  54. set (WAMR_BUILD_LIBC_WASI 1)
  55. endif ()
  56. if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
  57. # Enable fast interpreter
  58. set (WAMR_BUILD_FAST_INTERP 1)
  59. endif ()
  60. if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
  61. # Disable multiple module by default
  62. set (WAMR_BUILD_MULTI_MODULE 0)
  63. endif ()
  64. if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
  65. # Disable pthread library by default
  66. set (WAMR_BUILD_LIB_PTHREAD 0)
  67. endif ()
  68. if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
  69. # Disable wasm mini loader by default
  70. set (WAMR_BUILD_MINI_LOADER 0)
  71. endif ()
  72. if (NOT DEFINED WAMR_BUILD_SIMD)
  73. # Enable SIMD by default
  74. set (WAMR_BUILD_SIMD 1)
  75. endif ()
  76. if (NOT DEFINED WAMR_BUILD_REF_TYPES)
  77. # Enable reference types by default
  78. set (WAMR_BUILD_REF_TYPES 1)
  79. endif ()
  80. if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
  81. # Disable Debug feature by default
  82. set (WAMR_BUILD_DEBUG_INTERP 0)
  83. endif ()
  84. if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
  85. set (WAMR_BUILD_FAST_INTERP 0)
  86. set (WAMR_BUILD_MINI_LOADER 0)
  87. set (WAMR_BUILD_SIMD 0)
  88. endif ()
  89. set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-U,_get_ext_lib_export_apis")
  90. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
  91. set (CMAKE_MACOSX_RPATH True)
  92. # if enable wasi-nn, both wasi-nn-backends and iwasm
  93. # need to use same WAMR (dynamic) libraries
  94. if (WAMR_BUILD_WASI_NN EQUAL 1)
  95. set (BUILD_SHARED_LIBS ON)
  96. endif ()
  97. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
  98. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  99. include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
  100. add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE})
  101. set_version_info (iwasm)
  102. install (TARGETS iwasm DESTINATION bin)
  103. target_link_libraries (iwasm vmlib)
  104. add_library (vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  105. set_version_info (vmlib)
  106. target_include_directories(vmlib INTERFACE
  107. $<INSTALL_INTERFACE:include>
  108. )
  109. set (WAMR_PUBLIC_HEADERS
  110. ${WAMR_ROOT_DIR}/core/iwasm/include/wasm_c_api.h
  111. ${WAMR_ROOT_DIR}/core/iwasm/include/wasm_export.h
  112. ${WAMR_ROOT_DIR}/core/iwasm/include/lib_export.h
  113. )
  114. set_target_properties (vmlib PROPERTIES
  115. OUTPUT_NAME iwasm
  116. PUBLIC_HEADER "${WAMR_PUBLIC_HEADERS}"
  117. )
  118. target_link_libraries (vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
  119. install (TARGETS vmlib
  120. EXPORT iwasmTargets
  121. DESTINATION lib
  122. PUBLIC_HEADER DESTINATION include
  123. )
  124. install_iwasm_package ()