config_common.cmake 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. else ()
  43. message (FATAL_ERROR "-- WAMR build target isn't set")
  44. endif ()
  45. if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  46. add_definitions(-DBH_DEBUG=1)
  47. endif ()
  48. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  49. if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64" OR WAMR_BUILD_TARGET MATCHES "AARCH64.*" OR WAMR_BUILD_TARGET MATCHES "RISCV64.*")
  50. if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
  51. # Add -fPIC flag if build as 64-bit
  52. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
  53. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
  54. endif ()
  55. else ()
  56. add_definitions (-m32)
  57. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
  58. set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
  59. endif ()
  60. endif ()
  61. if (WAMR_BUILD_TARGET MATCHES "ARM.*")
  62. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm")
  63. elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
  64. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb")
  65. set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-mthumb")
  66. endif ()
  67. if (NOT WAMR_BUILD_INTERP EQUAL 1)
  68. if (NOT WAMR_BUILD_AOT EQUAL 1)
  69. message (FATAL_ERROR "-- WAMR Interpreter and AOT must be enabled at least one")
  70. endif ()
  71. endif ()
  72. if (WAMR_BUILD_JIT EQUAL 1)
  73. if (WAMR_BUILD_AOT EQUAL 1)
  74. add_definitions("-DWASM_ENABLE_JIT=1")
  75. set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
  76. set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/build")
  77. if (WAMR_BUILD_PLATFORM STREQUAL "windows")
  78. set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/win32build")
  79. endif ()
  80. if (NOT EXISTS "${LLVM_BUILD_ROOT}")
  81. message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_BUILD_ROOT}")
  82. endif ()
  83. set (CMAKE_PREFIX_PATH "${LLVM_BUILD_ROOT};${CMAKE_PREFIX_PATH}")
  84. find_package(LLVM REQUIRED CONFIG)
  85. include_directories(${LLVM_INCLUDE_DIRS})
  86. add_definitions(${LLVM_DEFINITIONS})
  87. message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
  88. message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
  89. else ()
  90. set (WAMR_BUILD_JIT 0)
  91. message ("-- WAMR JIT disabled due to WAMR AOT is disabled")
  92. endif ()
  93. else ()
  94. unset (LLVM_AVAILABLE_LIBS)
  95. endif ()
  96. message ("-- Build Configurations:")
  97. message (" Build as target ${WAMR_BUILD_TARGET}")
  98. message (" CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
  99. if (WAMR_BUILD_INTERP EQUAL 1)
  100. message (" WAMR Interpreter enabled")
  101. else ()
  102. message (" WAMR Interpreter disabled")
  103. endif ()
  104. if (WAMR_BUILD_AOT EQUAL 1)
  105. message (" WAMR AOT enabled")
  106. else ()
  107. message (" WAMR AOT disabled")
  108. endif ()
  109. if (WAMR_BUILD_JIT EQUAL 1)
  110. message (" WAMR JIT enabled")
  111. else ()
  112. message (" WAMR JIT disabled")
  113. endif ()
  114. if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
  115. message (" Libc builtin enabled")
  116. else ()
  117. message (" Libc builtin disabled")
  118. endif ()
  119. if (WAMR_BUILD_LIBC_UVWASI EQUAL 1)
  120. message (" Libc WASI enabled with uvwasi implementation")
  121. elseif (WAMR_BUILD_LIBC_WASI EQUAL 1)
  122. message (" Libc WASI enabled")
  123. else ()
  124. message (" Libc WASI disabled")
  125. endif ()
  126. if (WAMR_BUILD_FAST_INTERP EQUAL 1)
  127. add_definitions (-DWASM_ENABLE_FAST_INTERP=1)
  128. message (" Fast interpreter enabled")
  129. else ()
  130. add_definitions (-DWASM_ENABLE_FAST_INTERP=0)
  131. message (" Fast interpreter disabled")
  132. endif ()
  133. if (WAMR_BUILD_MULTI_MODULE EQUAL 1)
  134. add_definitions (-DWASM_ENABLE_MULTI_MODULE=1)
  135. message (" Multiple modules enabled")
  136. else ()
  137. add_definitions (-DWASM_ENABLE_MULTI_MODULE=0)
  138. message (" Multiple modules disabled")
  139. endif ()
  140. if (WAMR_BUILD_SPEC_TEST EQUAL 1)
  141. add_definitions (-DWASM_ENABLE_SPEC_TEST=1)
  142. message (" spec test compatible mode is on")
  143. endif ()
  144. if (WAMR_BUILD_BULK_MEMORY EQUAL 1)
  145. add_definitions (-DWASM_ENABLE_BULK_MEMORY=1)
  146. message (" Bulk memory feature enabled")
  147. else ()
  148. add_definitions (-DWASM_ENABLE_BULK_MEMORY=0)
  149. endif ()
  150. if (WAMR_BUILD_SHARED_MEMORY EQUAL 1)
  151. add_definitions (-DWASM_ENABLE_SHARED_MEMORY=1)
  152. message (" Shared memory enabled")
  153. else ()
  154. add_definitions (-DWASM_ENABLE_SHARED_MEMORY=0)
  155. endif ()
  156. if (WAMR_BUILD_THREAD_MGR EQUAL 1)
  157. message (" Thread manager enabled")
  158. endif ()
  159. if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
  160. message (" Lib pthread enabled")
  161. endif ()
  162. if (WAMR_BUILD_LIBC_EMCC EQUAL 1)
  163. message (" Libc emcc enabled")
  164. endif ()
  165. if (WAMR_BUILD_MINI_LOADER EQUAL 1)
  166. add_definitions (-DWASM_ENABLE_MINI_LOADER=1)
  167. message (" WASM mini loader enabled")
  168. else ()
  169. add_definitions (-DWASM_ENABLE_MINI_LOADER=0)
  170. endif ()
  171. if (WAMR_DISABLE_HW_BOUND_CHECK EQUAL 1)
  172. add_definitions (-DWASM_DISABLE_HW_BOUND_CHECK=1)
  173. message (" Hardware boundary check disabled")
  174. endif ()
  175. if (WAMR_BUILD_SIMD EQUAL 1)
  176. add_definitions (-DWASM_ENABLE_SIMD=1)
  177. message (" SIMD enabled")
  178. endif ()
  179. if (WAMR_BUILD_MEMORY_PROFILING EQUAL 1)
  180. add_definitions (-DWASM_ENABLE_MEMORY_PROFILING=1)
  181. message (" Memory profiling enabled")
  182. endif ()
  183. if (WAMR_BUILD_PERF_PROFILING EQUAL 1)
  184. add_definitions (-DWASM_ENABLE_PERF_PROFILING=1)
  185. message (" Performance profiling enabled")
  186. endif ()
  187. if (DEFINED WAMR_APP_THREAD_STACK_SIZE_MAX)
  188. add_definitions (-DAPP_THREAD_STACK_SIZE_MAX=${WAMR_APP_THREAD_STACK_SIZE_MAX})
  189. endif ()
  190. if (WAMR_BUILD_CUSTOM_NAME_SECTION EQUAL 1)
  191. add_definitions (-DWASM_ENABLE_CUSTOM_NAME_SECTION=1)
  192. message (" Custom name section enabled")
  193. endif ()
  194. if (WAMR_BUILD_DUMP_CALL_STACK EQUAL 1)
  195. add_definitions (-DWASM_ENABLE_DUMP_CALL_STACK=1)
  196. message (" Dump call stack enabled")
  197. endif ()
  198. if (WAMR_BUILD_TAIL_CALL EQUAL 1)
  199. add_definitions (-DWASM_ENABLE_TAIL_CALL=1)
  200. message (" Tail call enabled")
  201. endif ()
  202. if (WAMR_BUILD_REF_TYPES EQUAL 1)
  203. add_definitions (-DWASM_ENABLE_REF_TYPES=1)
  204. message (" Reference types enabled")
  205. else ()
  206. message (" Reference types disabled")
  207. endif ()
  208. if (DEFINED WAMR_BH_VPRINTF)
  209. add_definitions (-DBH_VPRINTF=${WAMR_BH_VPRINTF})
  210. endif ()