config_common.cmake 4.4 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 platform
  5. if (WAMR_BUILD_PLATFORM STREQUAL "linux")
  6. add_definitions(-DBH_PLATFORM_LINUX)
  7. elseif (WAMR_BUILD_PLATFORM STREQUAL "linux-sgx")
  8. add_definitions(-DBH_PLATFORM_LINUX_SGX)
  9. elseif (WAMR_BUILD_PLATFORM STREQUAL "zephyr")
  10. add_definitions(-DBH_PLATFORM_ZEPHYR)
  11. elseif (WAMR_BUILD_PLATFORM STREQUAL "vxworks")
  12. add_definitions(-DBH_PLATFORM_VXWORKS)
  13. elseif (WAMR_BUILD_PLATFORM STREQUAL "darwin")
  14. add_definitions(-DBH_PLATFORM_DARWIN)
  15. elseif (WAMR_BUILD_PLATFORM STREQUAL "alios-things")
  16. add_definitions(-DBH_PLATFORM_ALIOS_THINGS)
  17. elseif (WAMR_BUILD_PLATFORM STREQUAL "android")
  18. add_definitions(-DBH_PLATFORM_ANDROID)
  19. else ()
  20. message (WARNING "-- WAMR build platform isn't set")
  21. endif ()
  22. # Add definitions for the build target
  23. if (WAMR_BUILD_TARGET STREQUAL "X86_64")
  24. add_definitions(-DBUILD_TARGET_X86_64)
  25. elseif (WAMR_BUILD_TARGET STREQUAL "AMD_64")
  26. add_definitions(-DBUILD_TARGET_AMD_64)
  27. elseif (WAMR_BUILD_TARGET STREQUAL "X86_32")
  28. add_definitions(-DBUILD_TARGET_X86_32)
  29. elseif (WAMR_BUILD_TARGET MATCHES "ARM.*")
  30. if (WAMR_BUILD_TARGET MATCHES "(ARM.*)_VFP")
  31. add_definitions(-DBUILD_TARGET_ARM_VFP)
  32. add_definitions(-DBUILD_TARGET="${CMAKE_MATCH_1}")
  33. else ()
  34. add_definitions(-DBUILD_TARGET_ARM)
  35. add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}")
  36. endif ()
  37. elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
  38. if (WAMR_BUILD_TARGET MATCHES "(THUMB.*)_VFP")
  39. add_definitions(-DBUILD_TARGET_THUMB_VFP)
  40. add_definitions(-DBUILD_TARGET="${CMAKE_MATCH_1}")
  41. else ()
  42. add_definitions(-DBUILD_TARGET_THUMB)
  43. add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}")
  44. endif ()
  45. elseif (WAMR_BUILD_TARGET STREQUAL "MIPS")
  46. add_definitions(-DBUILD_TARGET_MIPS)
  47. elseif (WAMR_BUILD_TARGET STREQUAL "XTENSA")
  48. add_definitions(-DBUILD_TARGET_XTENSA)
  49. else ()
  50. message (FATAL_ERROR "-- WAMR build target isn't set")
  51. endif ()
  52. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  53. if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
  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. else ()
  58. add_definitions (-m32)
  59. set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
  60. set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
  61. endif ()
  62. endif ()
  63. if (WAMR_BUILD_TARGET MATCHES "ARM.*")
  64. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -marm")
  65. elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
  66. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mthumb")
  67. set (CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -Wa,-mthumb")
  68. endif ()
  69. if (NOT WAMR_BUILD_INTERP EQUAL 1)
  70. if (NOT WAMR_BUILD_AOT EQUAL 1)
  71. message (FATAL_ERROR "-- WAMR Interpreter and AOT must be enabled at least one")
  72. endif ()
  73. endif ()
  74. if (WAMR_BUILD_JIT EQUAL 1)
  75. if (WAMR_BUILD_AOT EQUAL 1)
  76. add_definitions("-DWASM_ENABLE_JIT=1")
  77. set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
  78. if (NOT EXISTS "${LLVM_SRC_ROOT}/build")
  79. message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build")
  80. endif ()
  81. set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}")
  82. find_package(LLVM REQUIRED CONFIG)
  83. include_directories(${LLVM_INCLUDE_DIRS})
  84. add_definitions(${LLVM_DEFINITIONS})
  85. message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
  86. message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
  87. else ()
  88. set (WAMR_BUILD_JIT 0)
  89. message ("-- WAMR JIT disabled due to WAMR AOT is disabled")
  90. endif ()
  91. else ()
  92. unset (LLVM_AVAILABLE_LIBS)
  93. endif ()
  94. message ("-- Build Configurations:")
  95. message (" Build as target ${WAMR_BUILD_TARGET}")
  96. message (" CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
  97. if (WAMR_BUILD_INTERP EQUAL 1)
  98. message (" WAMR Interpreter enabled")
  99. else ()
  100. message (" WAMR Interpreter disbled")
  101. endif ()
  102. if (WAMR_BUILD_AOT EQUAL 1)
  103. message (" WAMR AOT enabled")
  104. else ()
  105. message (" WAMR AOT disbled")
  106. endif ()
  107. if (WAMR_BUILD_JIT EQUAL 1)
  108. message (" WAMR JIT enabled")
  109. else ()
  110. message (" WAMR JIT disbled")
  111. endif ()
  112. if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
  113. message (" Libc builtin enabled")
  114. else ()
  115. message (" Libc builtin disbled")
  116. endif ()
  117. if (WAMR_BUILD_LIBC_WASI EQUAL 1)
  118. message (" Libc WASI enabled")
  119. else ()
  120. message (" Libc WASI disbled")
  121. endif ()