config_common.cmake 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. else ()
  35. message (FATAL_ERROR "-- WAMR build target isn't set")
  36. endif ()
  37. if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  38. add_definitions(-DBH_DEBUG=1)
  39. endif ()
  40. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  41. if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64" OR WAMR_BUILD_TARGET MATCHES "AARCH64.*")
  42. # Add -fPIC flag if build as 64-bit
  43. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
  44. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
  45. else ()
  46. add_definitions (-m32)
  47. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
  48. set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
  49. endif ()
  50. endif ()
  51. if (WAMR_BUILD_TARGET MATCHES "ARM.*")
  52. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm")
  53. elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
  54. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb")
  55. set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-mthumb")
  56. endif ()
  57. if (NOT WAMR_BUILD_INTERP EQUAL 1)
  58. if (NOT WAMR_BUILD_AOT EQUAL 1)
  59. message (FATAL_ERROR "-- WAMR Interpreter and AOT must be enabled at least one")
  60. endif ()
  61. endif ()
  62. if (WAMR_BUILD_JIT EQUAL 1)
  63. if (WAMR_BUILD_AOT EQUAL 1)
  64. add_definitions("-DWASM_ENABLE_JIT=1")
  65. set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
  66. if (NOT EXISTS "${LLVM_SRC_ROOT}/build")
  67. message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build")
  68. endif ()
  69. set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}")
  70. find_package(LLVM REQUIRED CONFIG)
  71. include_directories(${LLVM_INCLUDE_DIRS})
  72. add_definitions(${LLVM_DEFINITIONS})
  73. message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
  74. message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
  75. else ()
  76. set (WAMR_BUILD_JIT 0)
  77. message ("-- WAMR JIT disabled due to WAMR AOT is disabled")
  78. endif ()
  79. else ()
  80. unset (LLVM_AVAILABLE_LIBS)
  81. endif ()
  82. message ("-- Build Configurations:")
  83. message (" Build as target ${WAMR_BUILD_TARGET}")
  84. message (" CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
  85. if (WAMR_BUILD_INTERP EQUAL 1)
  86. message (" WAMR Interpreter enabled")
  87. else ()
  88. message (" WAMR Interpreter disabled")
  89. endif ()
  90. if (WAMR_BUILD_AOT EQUAL 1)
  91. message (" WAMR AOT enabled")
  92. else ()
  93. message (" WAMR AOT disabled")
  94. endif ()
  95. if (WAMR_BUILD_JIT EQUAL 1)
  96. message (" WAMR JIT enabled")
  97. else ()
  98. message (" WAMR JIT disabled")
  99. endif ()
  100. if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
  101. message (" Libc builtin enabled")
  102. else ()
  103. message (" Libc builtin disabled")
  104. endif ()
  105. if (WAMR_BUILD_LIBC_WASI EQUAL 1)
  106. message (" Libc WASI enabled")
  107. else ()
  108. message (" Libc WASI disabled")
  109. endif ()
  110. if (WAMR_BUILD_FAST_INTERP EQUAL 1)
  111. add_definitions (-DWASM_ENABLE_FAST_INTERP=1)
  112. message (" Fast interpreter enabled")
  113. else ()
  114. add_definitions (-DWASM_ENABLE_FAST_INTERP=0)
  115. message (" Fast interpreter disabled")
  116. endif ()
  117. if (WAMR_BUILD_SPEC_TEST EQUAL 1)
  118. add_definitions (-DWASM_ENABLE_SPEC_TEST=1)
  119. message (" spec test compatible mode is on")
  120. endif()