runtime_lib.cmake 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. if (NOT DEFINED WAMR_ROOT_DIR)
  4. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../)
  5. endif ()
  6. if (NOT DEFINED SHARED_DIR)
  7. set (SHARED_DIR ${WAMR_ROOT_DIR}/core/shared)
  8. endif ()
  9. if (NOT DEFINED IWASM_DIR)
  10. set (IWASM_DIR ${WAMR_ROOT_DIR}/core/iwasm)
  11. endif ()
  12. if (NOT DEFINED APP_MGR_DIR)
  13. set (APP_MGR_DIR ${WAMR_ROOT_DIR}/core/app-mgr)
  14. endif ()
  15. if (NOT DEFINED APP_FRAMEWORK_DIR)
  16. set (APP_FRAMEWORK_DIR ${WAMR_ROOT_DIR}/core/app-framework)
  17. endif ()
  18. if (NOT DEFINED DEPS_DIR)
  19. set (DEPS_DIR ${WAMR_ROOT_DIR}/core/deps)
  20. endif ()
  21. if (DEFINED EXTRA_SDK_INCLUDE_PATH)
  22. message(STATUS, "EXTRA_SDK_INCLUDE_PATH = ${EXTRA_SDK_INCLUDE_PATH} ")
  23. include_directories (
  24. ${EXTRA_SDK_INCLUDE_PATH}
  25. )
  26. endif ()
  27. # Set default options
  28. # Set WAMR_BUILD_TARGET, currently values supported:
  29. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  30. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  31. if (NOT DEFINED WAMR_BUILD_TARGET)
  32. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
  33. set (WAMR_BUILD_TARGET "AARCH64")
  34. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  35. set (WAMR_BUILD_TARGET "RISCV64")
  36. elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
  37. # Build as X86_64 by default in 64-bit platform
  38. set (WAMR_BUILD_TARGET "X86_64")
  39. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  40. # Build as X86_32 by default in 32-bit platform
  41. set (WAMR_BUILD_TARGET "X86_32")
  42. else ()
  43. message(SEND_ERROR "Unsupported build target platform!")
  44. endif ()
  45. endif ()
  46. ################ optional according to settings ################
  47. if (WAMR_BUILD_INTERP EQUAL 1 OR WAMR_BUILD_JIT EQUAL 1
  48. OR WAMR_BUILD_FAST_JIT EQUAL 1)
  49. if (WAMR_BUILD_FAST_JIT EQUAL 1 OR WAMR_BUILD_JIT EQUAL 1)
  50. set (WAMR_BUILD_FAST_INTERP 0)
  51. endif ()
  52. include (${IWASM_DIR}/interpreter/iwasm_interp.cmake)
  53. endif ()
  54. if (WAMR_BUILD_AOT EQUAL 1)
  55. include (${IWASM_DIR}/aot/iwasm_aot.cmake)
  56. if (WAMR_BUILD_JIT EQUAL 1)
  57. include (${IWASM_DIR}/compilation/iwasm_compl.cmake)
  58. endif ()
  59. endif ()
  60. if (NOT WAMR_BUILD_JIT EQUAL 1 AND WAMR_BUILD_FAST_JIT EQUAL 1)
  61. include (${IWASM_DIR}/fast-jit/iwasm_fast_jit.cmake)
  62. endif ()
  63. if (WAMR_BUILD_APP_FRAMEWORK EQUAL 1)
  64. include (${APP_FRAMEWORK_DIR}/app_framework.cmake)
  65. include (${SHARED_DIR}/coap/lib_coap.cmake)
  66. include (${APP_MGR_DIR}/app-manager/app_mgr.cmake)
  67. include (${APP_MGR_DIR}/app-mgr-shared/app_mgr_shared.cmake)
  68. endif ()
  69. if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
  70. include (${IWASM_DIR}/libraries/libc-builtin/libc_builtin.cmake)
  71. endif ()
  72. if (WAMR_BUILD_LIBC_UVWASI EQUAL 1)
  73. include (${IWASM_DIR}/libraries/libc-uvwasi/libc_uvwasi.cmake)
  74. elseif (WAMR_BUILD_LIBC_WASI EQUAL 1)
  75. include (${IWASM_DIR}/libraries/libc-wasi/libc_wasi.cmake)
  76. endif ()
  77. if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1)
  78. # Enable the dependent feature if lib pthread semaphore is enabled
  79. set (WAMR_BUILD_LIB_PTHREAD 1)
  80. endif ()
  81. if (WAMR_BUILD_WASI_NN EQUAL 1)
  82. execute_process(COMMAND ${WAMR_ROOT_DIR}/core/deps/install_tensorflow.sh
  83. RESULT_VARIABLE TENSORFLOW_RESULT
  84. )
  85. set(TENSORFLOW_SOURCE_DIR "${WAMR_ROOT_DIR}/core/deps/tensorflow-src")
  86. include_directories (${CMAKE_CURRENT_BINARY_DIR}/flatbuffers/include)
  87. include_directories (${TENSORFLOW_SOURCE_DIR})
  88. add_subdirectory(
  89. "${TENSORFLOW_SOURCE_DIR}/tensorflow/lite"
  90. "${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite" EXCLUDE_FROM_ALL)
  91. include (${IWASM_DIR}/libraries/wasi-nn/wasi_nn.cmake)
  92. endif ()
  93. if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
  94. include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake)
  95. # Enable the dependent feature if lib pthread is enabled
  96. set (WAMR_BUILD_THREAD_MGR 1)
  97. set (WAMR_BUILD_BULK_MEMORY 1)
  98. set (WAMR_BUILD_SHARED_MEMORY 1)
  99. endif ()
  100. if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
  101. set (WAMR_BUILD_THREAD_MGR 1)
  102. include (${IWASM_DIR}/libraries/debug-engine/debug_engine.cmake)
  103. if (WAMR_BUILD_FAST_INTERP EQUAL 1)
  104. set (WAMR_BUILD_FAST_INTERP 0)
  105. message(STATUS
  106. "Debugger doesn't work with fast interpreter, switch to classic interpreter")
  107. endif ()
  108. endif ()
  109. if (WAMR_BUILD_THREAD_MGR EQUAL 1)
  110. include (${IWASM_DIR}/libraries/thread-mgr/thread_mgr.cmake)
  111. endif ()
  112. if (WAMR_BUILD_LIBC_EMCC EQUAL 1)
  113. include (${IWASM_DIR}/libraries/libc-emcc/libc_emcc.cmake)
  114. endif ()
  115. if (WAMR_BUILD_LIB_RATS EQUAL 1)
  116. include (${IWASM_DIR}/libraries/lib-rats/lib_rats.cmake)
  117. endif ()
  118. ####################### Common sources #######################
  119. if (NOT MSVC)
  120. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \
  121. -Wall -Wno-unused-parameter -Wno-pedantic")
  122. endif ()
  123. # include the build config template file
  124. include (${CMAKE_CURRENT_LIST_DIR}/config_common.cmake)
  125. include_directories (${IWASM_DIR}/include)
  126. file (GLOB header
  127. ${IWASM_DIR}/include/*.h
  128. )
  129. LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header})
  130. enable_language (ASM)
  131. include (${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
  132. include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
  133. include (${IWASM_DIR}/common/iwasm_common.cmake)
  134. include (${SHARED_DIR}/utils/shared_utils.cmake)
  135. set (source_all
  136. ${PLATFORM_SHARED_SOURCE}
  137. ${MEM_ALLOC_SHARED_SOURCE}
  138. ${UTILS_SHARED_SOURCE}
  139. ${LIBC_BUILTIN_SOURCE}
  140. ${LIBC_WASI_SOURCE}
  141. ${LIBC_WASI_NN_SOURCE}
  142. ${IWASM_COMMON_SOURCE}
  143. ${IWASM_INTERP_SOURCE}
  144. ${IWASM_AOT_SOURCE}
  145. ${IWASM_COMPL_SOURCE}
  146. ${IWASM_FAST_JIT_SOURCE}
  147. ${WASM_APP_LIB_SOURCE_ALL}
  148. ${NATIVE_INTERFACE_SOURCE}
  149. ${APP_MGR_SOURCE}
  150. ${LIB_PTHREAD_SOURCE}
  151. ${THREAD_MGR_SOURCE}
  152. ${LIBC_EMCC_SOURCE}
  153. ${LIB_RATS_SOURCE}
  154. ${DEBUG_ENGINE_SOURCE}
  155. )
  156. set (WAMR_RUNTIME_LIB_SOURCE ${source_all})