runtime_lib.cmake 6.1 KB

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