runtime_lib.cmake 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 DEPS_DIR)
  13. set (DEPS_DIR ${WAMR_ROOT_DIR}/core/deps)
  14. endif ()
  15. if (NOT DEFINED SHARED_PLATFORM_CONFIG)
  16. # CMake file for platform configuration. The PLATFORM_SHARED_SOURCE variable
  17. # should point to a list of platform-specfic source files to compile.
  18. set (SHARED_PLATFORM_CONFIG ${SHARED_DIR}/platform/${WAMR_BUILD_PLATFORM}/shared_platform.cmake)
  19. endif ()
  20. if (DEFINED EXTRA_SDK_INCLUDE_PATH)
  21. message(STATUS, "EXTRA_SDK_INCLUDE_PATH = ${EXTRA_SDK_INCLUDE_PATH} ")
  22. include_directories (
  23. ${EXTRA_SDK_INCLUDE_PATH}
  24. )
  25. endif ()
  26. # Set default options
  27. # Set WAMR_BUILD_TARGET, currently values supported:
  28. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  29. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  30. if (NOT DEFINED WAMR_BUILD_TARGET)
  31. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
  32. set (WAMR_BUILD_TARGET "AARCH64")
  33. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  34. set (WAMR_BUILD_TARGET "RISCV64")
  35. elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
  36. # Build as X86_64 by default in 64-bit platform
  37. set (WAMR_BUILD_TARGET "X86_64")
  38. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  39. # Build as X86_32 by default in 32-bit platform
  40. set (WAMR_BUILD_TARGET "X86_32")
  41. else ()
  42. message(SEND_ERROR "Unsupported build target platform!")
  43. endif ()
  44. endif ()
  45. ################ optional according to settings ################
  46. if (WAMR_BUILD_FAST_JIT EQUAL 1 OR WAMR_BUILD_JIT EQUAL 1)
  47. # Enable classic interpreter if Fast JIT or LLVM JIT is enabled
  48. set (WAMR_BUILD_INTERP 1)
  49. set (WAMR_BUILD_FAST_INTERP 0)
  50. endif ()
  51. if (WAMR_BUILD_INTERP EQUAL 1)
  52. include (${IWASM_DIR}/interpreter/iwasm_interp.cmake)
  53. endif ()
  54. if (WAMR_BUILD_FAST_JIT EQUAL 1)
  55. if (WAMR_BUILD_PLATFORM STREQUAL "windows")
  56. message ("Fast JIT currently not supported on Windows")
  57. set (WAMR_BUILD_FAST_JIT 0)
  58. else ()
  59. include (${IWASM_DIR}/fast-jit/iwasm_fast_jit.cmake)
  60. endif ()
  61. endif ()
  62. if (WAMR_BUILD_JIT EQUAL 1)
  63. # Enable AOT if LLVM JIT is enabled
  64. set (WAMR_BUILD_AOT 1)
  65. include (${IWASM_DIR}/compilation/iwasm_compl.cmake)
  66. endif ()
  67. if (WAMR_BUILD_AOT EQUAL 1)
  68. include (${IWASM_DIR}/aot/iwasm_aot.cmake)
  69. endif ()
  70. if (WAMR_BUILD_STRINGREF EQUAL 1)
  71. set (WAMR_BUILD_GC 1)
  72. endif ()
  73. if (WAMR_BUILD_GC EQUAL 1)
  74. include (${IWASM_DIR}/common/gc/iwasm_gc.cmake)
  75. # Enable the dependent feature if GC is enabled
  76. set (WAMR_BUILD_REF_TYPES 1)
  77. endif ()
  78. if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
  79. include (${IWASM_DIR}/libraries/libc-builtin/libc_builtin.cmake)
  80. endif ()
  81. if (WAMR_BUILD_LIBC_UVWASI EQUAL 1)
  82. include (${IWASM_DIR}/libraries/libc-uvwasi/libc_uvwasi.cmake)
  83. set (WAMR_BUILD_MODULE_INST_CONTEXT 1)
  84. elseif (WAMR_BUILD_LIBC_WASI EQUAL 1)
  85. include (${IWASM_DIR}/libraries/libc-wasi/libc_wasi.cmake)
  86. set (WAMR_BUILD_MODULE_INST_CONTEXT 1)
  87. endif ()
  88. if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1)
  89. # Enable the dependent feature if lib pthread semaphore is enabled
  90. set (WAMR_BUILD_LIB_PTHREAD 1)
  91. endif ()
  92. if (WAMR_BUILD_WASI_NN EQUAL 1)
  93. include (${IWASM_DIR}/libraries/wasi-nn/cmake/wasi_nn.cmake)
  94. set (WAMR_BUILD_MODULE_INST_CONTEXT 1)
  95. endif ()
  96. if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
  97. if (WAMR_BUILD_PLATFORM STREQUAL "windows")
  98. set (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE 0)
  99. message ("Lib pthread semaphore currently not supported on Windows")
  100. endif ()
  101. include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake)
  102. # Enable the dependent feature if lib pthread is enabled
  103. set (WAMR_BUILD_THREAD_MGR 1)
  104. set (WAMR_BUILD_BULK_MEMORY 1)
  105. set (WAMR_BUILD_SHARED_MEMORY 1)
  106. endif ()
  107. if (WAMR_BUILD_LIB_WASI_THREADS EQUAL 1)
  108. include (${IWASM_DIR}/libraries/lib-wasi-threads/lib_wasi_threads.cmake)
  109. # Enable the dependent feature if lib wasi threads is enabled
  110. set (WAMR_BUILD_THREAD_MGR 1)
  111. set (WAMR_BUILD_BULK_MEMORY 1)
  112. set (WAMR_BUILD_SHARED_MEMORY 1)
  113. endif ()
  114. if (WAMR_BUILD_SHARED_HEAP EQUAL 1)
  115. include (${IWASM_DIR}/libraries/shared-heap/shared_heap.cmake)
  116. endif ()
  117. if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
  118. set (WAMR_BUILD_THREAD_MGR 1)
  119. include (${IWASM_DIR}/libraries/debug-engine/debug_engine.cmake)
  120. if (WAMR_BUILD_FAST_INTERP EQUAL 1)
  121. set (WAMR_BUILD_FAST_INTERP 0)
  122. message(STATUS
  123. "Debugger doesn't work with fast interpreter, switch to classic interpreter")
  124. endif ()
  125. endif ()
  126. if (WAMR_BUILD_THREAD_MGR EQUAL 1)
  127. include (${IWASM_DIR}/libraries/thread-mgr/thread_mgr.cmake)
  128. endif ()
  129. if (WAMR_BUILD_LIBC_EMCC EQUAL 1)
  130. include (${IWASM_DIR}/libraries/libc-emcc/libc_emcc.cmake)
  131. endif ()
  132. if (WAMR_BUILD_LIB_RATS EQUAL 1)
  133. include (${IWASM_DIR}/libraries/lib-rats/lib_rats.cmake)
  134. endif ()
  135. if (WAMR_BUILD_WASM_CACHE EQUAL 1)
  136. include (${WAMR_ROOT_DIR}/build-scripts/involve_boringssl.cmake)
  137. endif ()
  138. ####################### Common sources #######################
  139. if (NOT MSVC)
  140. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections")
  141. endif ()
  142. # include the build config template file
  143. include (${CMAKE_CURRENT_LIST_DIR}/config_common.cmake)
  144. if (WAMR_BUILD_SIMD EQUAL 1 AND WAMR_BUILD_FAST_INTERP EQUAL 1)
  145. if (WAMR_BUILD_PLATFORM STREQUAL "windows")
  146. message(STATUS "SIMDe doesnt support platform " ${WAMR_BUILD_PLATFORM})
  147. set(WAMR_BUILD_SIMDE 0)
  148. else()
  149. include (${IWASM_DIR}/libraries/simde/simde.cmake)
  150. set (WAMR_BUILD_SIMDE 1)
  151. endif()
  152. else()
  153. set(WAMR_BUILD_SIMDE 0)
  154. endif ()
  155. include_directories (${IWASM_DIR}/include)
  156. file (GLOB header
  157. ${IWASM_DIR}/include/*.h
  158. )
  159. LIST (APPEND RUNTIME_LIB_HEADER_LIST ${header})
  160. if (WAMR_BUILD_PLATFORM STREQUAL "windows")
  161. enable_language (ASM_MASM)
  162. else()
  163. enable_language (ASM)
  164. endif()
  165. # it will expose the runtime APIs.
  166. # you'll use the following command to check the exported APIs
  167. # dumpbin.exe /EXPORTS xxx
  168. if (MSVC)
  169. add_compile_definitions(COMPILING_WASM_RUNTIME_API=1)
  170. endif ()
  171. include (${SHARED_PLATFORM_CONFIG})
  172. include (${SHARED_DIR}/mem-alloc/mem_alloc.cmake)
  173. include (${IWASM_DIR}/common/iwasm_common.cmake)
  174. include (${SHARED_DIR}/utils/shared_utils.cmake)
  175. set (source_all
  176. ${PLATFORM_SHARED_SOURCE}
  177. ${MEM_ALLOC_SHARED_SOURCE}
  178. ${UTILS_SHARED_SOURCE}
  179. ${LIBC_BUILTIN_SOURCE}
  180. ${LIBC_WASI_SOURCE}
  181. ${WASI_NN_SOURCES}
  182. ${IWASM_COMMON_SOURCE}
  183. ${IWASM_INTERP_SOURCE}
  184. ${IWASM_AOT_SOURCE}
  185. ${IWASM_COMPL_SOURCE}
  186. ${IWASM_FAST_JIT_SOURCE}
  187. ${IWASM_GC_SOURCE}
  188. ${LIB_WASI_THREADS_SOURCE}
  189. ${LIB_PTHREAD_SOURCE}
  190. ${THREAD_MGR_SOURCE}
  191. ${LIBC_EMCC_SOURCE}
  192. ${LIB_RATS_SOURCE}
  193. ${DEBUG_ENGINE_SOURCE}
  194. ${LIB_SHARED_HEAP_SOURCE}
  195. )
  196. set (WAMR_RUNTIME_LIB_SOURCE ${source_all})