config_common.cmake 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. string(TOUPPER ${WAMR_BUILD_TARGET} WAMR_BUILD_TARGET)
  4. # Add definitions for the build target
  5. if (WAMR_BUILD_TARGET STREQUAL "X86_64")
  6. add_definitions(-DBUILD_TARGET_X86_64)
  7. elseif (WAMR_BUILD_TARGET STREQUAL "AMD_64")
  8. add_definitions(-DBUILD_TARGET_AMD_64)
  9. elseif (WAMR_BUILD_TARGET STREQUAL "X86_32")
  10. add_definitions(-DBUILD_TARGET_X86_32)
  11. elseif (WAMR_BUILD_TARGET MATCHES "ARM.*")
  12. if (WAMR_BUILD_TARGET MATCHES "(ARM.*)_VFP")
  13. add_definitions(-DBUILD_TARGET_ARM_VFP)
  14. add_definitions(-DBUILD_TARGET="${CMAKE_MATCH_1}")
  15. else ()
  16. add_definitions(-DBUILD_TARGET_ARM)
  17. add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}")
  18. endif ()
  19. elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
  20. if (WAMR_BUILD_TARGET MATCHES "(THUMB.*)_VFP")
  21. add_definitions(-DBUILD_TARGET_THUMB_VFP)
  22. add_definitions(-DBUILD_TARGET="${CMAKE_MATCH_1}")
  23. else ()
  24. add_definitions(-DBUILD_TARGET_THUMB)
  25. add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}")
  26. endif ()
  27. elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*")
  28. add_definitions(-DBUILD_TARGET_AARCH64)
  29. add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}")
  30. elseif (WAMR_BUILD_TARGET STREQUAL "MIPS")
  31. add_definitions(-DBUILD_TARGET_MIPS)
  32. elseif (WAMR_BUILD_TARGET STREQUAL "XTENSA")
  33. add_definitions(-DBUILD_TARGET_XTENSA)
  34. elseif (WAMR_BUILD_TARGET STREQUAL "RISCV64" OR WAMR_BUILD_TARGET STREQUAL "RISCV64_LP64D")
  35. add_definitions(-DBUILD_TARGET_RISCV64_LP64D)
  36. elseif (WAMR_BUILD_TARGET STREQUAL "RISCV64_LP64")
  37. add_definitions(-DBUILD_TARGET_RISCV64_LP64)
  38. elseif (WAMR_BUILD_TARGET STREQUAL "RISCV32" OR WAMR_BUILD_TARGET STREQUAL "RISCV32_ILP32D")
  39. add_definitions(-DBUILD_TARGET_RISCV32_ILP32D)
  40. elseif (WAMR_BUILD_TARGET STREQUAL "RISCV32_ILP32")
  41. add_definitions(-DBUILD_TARGET_RISCV32_ILP32)
  42. elseif (WAMR_BUILD_TARGET STREQUAL "ARC")
  43. add_definitions(-DBUILD_TARGET_ARC)
  44. else ()
  45. message (FATAL_ERROR "-- WAMR build target isn't set")
  46. endif ()
  47. if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  48. add_definitions(-DBH_DEBUG=1)
  49. endif ()
  50. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  51. if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64"
  52. OR WAMR_BUILD_TARGET MATCHES "AARCH64.*" OR WAMR_BUILD_TARGET MATCHES "RISCV64.*")
  53. if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
  54. # Add -fPIC flag if build as 64-bit
  55. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
  56. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
  57. endif ()
  58. else ()
  59. include(CheckCCompilerFlag)
  60. Check_C_Compiler_Flag(-m32 M32_OK)
  61. if (M32_OK OR WAMR_BUILD_TARGET STREQUAL "X86_32")
  62. add_definitions (-m32)
  63. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
  64. set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
  65. endif ()
  66. endif ()
  67. endif ()
  68. if (WAMR_BUILD_TARGET MATCHES "ARM.*")
  69. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm")
  70. elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
  71. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb")
  72. set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-mthumb")
  73. endif ()
  74. if (NOT WAMR_BUILD_INTERP EQUAL 1)
  75. if (NOT WAMR_BUILD_AOT EQUAL 1)
  76. message (FATAL_ERROR "-- WAMR Interpreter and AOT must be enabled at least one")
  77. endif ()
  78. endif ()
  79. if (WAMR_BUILD_JIT EQUAL 1)
  80. if (WAMR_BUILD_AOT EQUAL 1)
  81. add_definitions("-DWASM_ENABLE_JIT=1")
  82. if (NOT WAMR_BUILD_LAZY_JIT EQUAL 0)
  83. # Enable Lazy JIT by default
  84. set (WAMR_BUILD_LAZY_JIT 1)
  85. add_definitions("-DWASM_ENABLE_LAZY_JIT=1")
  86. endif ()
  87. if (NOT DEFINED LLVM_DIR)
  88. set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
  89. set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/build")
  90. if (WAMR_BUILD_PLATFORM STREQUAL "windows")
  91. set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/win32build")
  92. endif ()
  93. if (NOT EXISTS "${LLVM_BUILD_ROOT}")
  94. message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_BUILD_ROOT}")
  95. endif ()
  96. set (CMAKE_PREFIX_PATH "${LLVM_BUILD_ROOT};${CMAKE_PREFIX_PATH}")
  97. endif ()
  98. find_package(LLVM REQUIRED CONFIG)
  99. include_directories(${LLVM_INCLUDE_DIRS})
  100. add_definitions(${LLVM_DEFINITIONS})
  101. message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
  102. message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
  103. else ()
  104. set (WAMR_BUILD_JIT 0)
  105. message ("-- WAMR JIT disabled due to WAMR AOT is disabled")
  106. endif ()
  107. else ()
  108. unset (LLVM_AVAILABLE_LIBS)
  109. endif ()
  110. ########################################
  111. ## semantic version information
  112. if (NOT DEFINED WAMR_VERSION_MAJOR)
  113. set (WAMR_VERSION_MAJOR 1)
  114. endif ()
  115. if (NOT DEFINED WAMR_VERSION_MINOR)
  116. set (WAMR_VERSION_MINOR 0)
  117. endif ()
  118. if (NOT DEFINED WAMR_VERSION_PATCH)
  119. set (WAMR_VERSION_PATCH 0)
  120. endif ()
  121. configure_file(${WAMR_ROOT_DIR}/core/version.h.in ${WAMR_ROOT_DIR}/core/version.h @ONLY)
  122. ########################################
  123. message ("-- Build Configurations:")
  124. message (" Build as target ${WAMR_BUILD_TARGET}")
  125. message (" CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
  126. if (WAMR_BUILD_INTERP EQUAL 1)
  127. message (" WAMR Interpreter enabled")
  128. elseif (WAMR_BUILD_JIT EQUAL 1)
  129. set (WAMR_BUILD_INTERP 1)
  130. message (" WAMR Interpreter enabled due to WAMR JIT is enabled")
  131. else ()
  132. message (" WAMR Interpreter disabled")
  133. endif ()
  134. if (WAMR_BUILD_AOT EQUAL 1)
  135. message (" WAMR AOT enabled")
  136. else ()
  137. message (" WAMR AOT disabled")
  138. endif ()
  139. if (WAMR_BUILD_JIT EQUAL 1)
  140. if (WAMR_BUILD_LAZY_JIT EQUAL 1)
  141. message (" WAMR LLVM Orc Lazy JIT enabled")
  142. else ()
  143. message (" WAMR LLVM MC JIT enabled")
  144. endif ()
  145. elseif (WAMR_BUILD_FAST_JIT EQUAL 1)
  146. message (" WAMR Fast JIT enabled")
  147. else ()
  148. message (" WAMR JIT disabled")
  149. endif ()
  150. if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
  151. message (" Libc builtin enabled")
  152. else ()
  153. message (" Libc builtin disabled")
  154. endif ()
  155. if (WAMR_BUILD_LIBC_UVWASI EQUAL 1)
  156. message (" Libc WASI enabled with uvwasi implementation")
  157. elseif (WAMR_BUILD_LIBC_WASI EQUAL 1)
  158. message (" Libc WASI enabled")
  159. else ()
  160. message (" Libc WASI disabled")
  161. endif ()
  162. if ((WAMR_BUILD_FAST_INTERP EQUAL 1) AND (WAMR_BUILD_INTERP EQUAL 1))
  163. add_definitions (-DWASM_ENABLE_FAST_INTERP=1)
  164. message (" Fast interpreter enabled")
  165. else ()
  166. add_definitions (-DWASM_ENABLE_FAST_INTERP=0)
  167. message (" Fast interpreter disabled")
  168. endif ()
  169. if (WAMR_BUILD_MULTI_MODULE EQUAL 1)
  170. add_definitions (-DWASM_ENABLE_MULTI_MODULE=1)
  171. message (" Multiple modules enabled")
  172. else ()
  173. add_definitions (-DWASM_ENABLE_MULTI_MODULE=0)
  174. message (" Multiple modules disabled")
  175. endif ()
  176. if (WAMR_BUILD_SPEC_TEST EQUAL 1)
  177. add_definitions (-DWASM_ENABLE_SPEC_TEST=1)
  178. message (" spec test compatible mode is on")
  179. endif ()
  180. if (WAMR_BUILD_BULK_MEMORY EQUAL 1)
  181. add_definitions (-DWASM_ENABLE_BULK_MEMORY=1)
  182. message (" Bulk memory feature enabled")
  183. else ()
  184. add_definitions (-DWASM_ENABLE_BULK_MEMORY=0)
  185. endif ()
  186. if (WAMR_BUILD_SHARED_MEMORY EQUAL 1)
  187. add_definitions (-DWASM_ENABLE_SHARED_MEMORY=1)
  188. message (" Shared memory enabled")
  189. else ()
  190. add_definitions (-DWASM_ENABLE_SHARED_MEMORY=0)
  191. endif ()
  192. if (WAMR_BUILD_THREAD_MGR EQUAL 1)
  193. message (" Thread manager enabled")
  194. endif ()
  195. if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
  196. message (" Lib pthread enabled")
  197. endif ()
  198. if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1)
  199. message (" Lib pthread semaphore enabled")
  200. endif ()
  201. if (WAMR_BUILD_LIBC_EMCC EQUAL 1)
  202. message (" Libc emcc enabled")
  203. endif ()
  204. if (WAMR_BUILD_LIB_RATS EQUAL 1)
  205. message (" Lib rats enabled")
  206. endif()
  207. if (WAMR_BUILD_MINI_LOADER EQUAL 1)
  208. add_definitions (-DWASM_ENABLE_MINI_LOADER=1)
  209. message (" WASM mini loader enabled")
  210. else ()
  211. add_definitions (-DWASM_ENABLE_MINI_LOADER=0)
  212. endif ()
  213. if (WAMR_DISABLE_HW_BOUND_CHECK EQUAL 1)
  214. add_definitions (-DWASM_DISABLE_HW_BOUND_CHECK=1)
  215. message (" Hardware boundary check disabled")
  216. else ()
  217. add_definitions (-DWASM_DISABLE_HW_BOUND_CHECK=0)
  218. endif ()
  219. if (WAMR_BUILD_SIMD EQUAL 1)
  220. if (NOT WAMR_BUILD_TARGET MATCHES "RISCV64.*")
  221. add_definitions (-DWASM_ENABLE_SIMD=1)
  222. message (" SIMD enabled")
  223. else ()
  224. message (" SIMD disabled due to not supported on target RISCV64")
  225. endif ()
  226. endif ()
  227. if (WAMR_BUILD_MEMORY_PROFILING EQUAL 1)
  228. add_definitions (-DWASM_ENABLE_MEMORY_PROFILING=1)
  229. message (" Memory profiling enabled")
  230. endif ()
  231. if (WAMR_BUILD_PERF_PROFILING EQUAL 1)
  232. add_definitions (-DWASM_ENABLE_PERF_PROFILING=1)
  233. message (" Performance profiling enabled")
  234. endif ()
  235. if (DEFINED WAMR_APP_THREAD_STACK_SIZE_MAX)
  236. add_definitions (-DAPP_THREAD_STACK_SIZE_MAX=${WAMR_APP_THREAD_STACK_SIZE_MAX})
  237. endif ()
  238. if (WAMR_BUILD_CUSTOM_NAME_SECTION EQUAL 1)
  239. add_definitions (-DWASM_ENABLE_CUSTOM_NAME_SECTION=1)
  240. message (" Custom name section enabled")
  241. endif ()
  242. if (WAMR_BUILD_DUMP_CALL_STACK EQUAL 1)
  243. add_definitions (-DWASM_ENABLE_DUMP_CALL_STACK=1)
  244. message (" Dump call stack enabled")
  245. endif ()
  246. if (WAMR_BUILD_TAIL_CALL EQUAL 1)
  247. add_definitions (-DWASM_ENABLE_TAIL_CALL=1)
  248. message (" Tail call enabled")
  249. endif ()
  250. if (WAMR_BUILD_REF_TYPES EQUAL 1)
  251. add_definitions (-DWASM_ENABLE_REF_TYPES=1)
  252. message (" Reference types enabled")
  253. else ()
  254. message (" Reference types disabled")
  255. endif ()
  256. if (DEFINED WAMR_BH_VPRINTF)
  257. add_definitions (-DBH_VPRINTF=${WAMR_BH_VPRINTF})
  258. endif ()
  259. if (WAMR_DISABLE_APP_ENTRY EQUAL 1)
  260. message (" WAMR application entry functions excluded")
  261. endif ()
  262. if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
  263. message (" Debug Interpreter enabled")
  264. endif ()
  265. if (WAMR_BUILD_DEBUG_AOT EQUAL 1)
  266. message (" Debug AOT enabled")
  267. endif ()
  268. if (WAMR_BUILD_LOAD_CUSTOM_SECTION EQUAL 1)
  269. add_definitions (-DWASM_ENABLE_LOAD_CUSTOM_SECTION=1)
  270. message (" Load custom section enabled")
  271. endif ()
  272. if (WAMR_BUILD_STACK_GUARD_SIZE GREATER 0)
  273. add_definitions (-DWASM_STACK_GUARD_SIZE=${WAMR_BUILD_STACK_GUARD_SIZE})
  274. message (" Custom stack guard size: " ${WAMR_BUILD_STACK_GUARD_SIZE})
  275. endif ()
  276. if (WAMR_BUILD_SGX_IPFS EQUAL 1)
  277. add_definitions (-DWASM_ENABLE_SGX_IPFS=1)
  278. message (" SGX IPFS enabled")
  279. endif ()