config_common.cmake 4.0 KB

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