config_common.cmake 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. else ()
  18. message (WARNING "-- WAMR build platform isn't set")
  19. endif ()
  20. # Add definitions for the build target
  21. if (WAMR_BUILD_TARGET STREQUAL "X86_64")
  22. add_definitions(-DBUILD_TARGET_X86_64)
  23. elseif (WAMR_BUILD_TARGET STREQUAL "AMD_64")
  24. add_definitions(-DBUILD_TARGET_AMD_64)
  25. elseif (WAMR_BUILD_TARGET STREQUAL "X86_32")
  26. add_definitions(-DBUILD_TARGET_X86_32)
  27. elseif (WAMR_BUILD_TARGET MATCHES "ARM.*")
  28. if (WAMR_BUILD_TARGET MATCHES "(ARM.*)_VFP")
  29. add_definitions(-DBUILD_TARGET_ARM_VFP)
  30. add_definitions(-DBUILD_TARGET="${CMAKE_MATCH_1}")
  31. else ()
  32. add_definitions(-DBUILD_TARGET_ARM)
  33. add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}")
  34. endif ()
  35. elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
  36. if (WAMR_BUILD_TARGET MATCHES "(THUMB.*)_VFP")
  37. add_definitions(-DBUILD_TARGET_THUMB_VFP)
  38. add_definitions(-DBUILD_TARGET="${CMAKE_MATCH_1}")
  39. else ()
  40. add_definitions(-DBUILD_TARGET_THUMB)
  41. add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}")
  42. endif ()
  43. elseif (WAMR_BUILD_TARGET STREQUAL "MIPS")
  44. add_definitions(-DBUILD_TARGET_MIPS)
  45. elseif (WAMR_BUILD_TARGET STREQUAL "XTENSA")
  46. add_definitions(-DBUILD_TARGET_XTENSA)
  47. else ()
  48. message (FATAL_ERROR "-- WAMR build target isn't set")
  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. # Add -fPIC flag if build as 64-bit
  53. set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
  54. set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
  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. if (NOT EXISTS "${LLVM_SRC_ROOT}/build")
  77. message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build")
  78. endif ()
  79. set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}")
  80. find_package(LLVM REQUIRED CONFIG)
  81. include_directories(${LLVM_INCLUDE_DIRS})
  82. add_definitions(${LLVM_DEFINITIONS})
  83. message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
  84. message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
  85. else ()
  86. set (WAMR_BUILD_JIT 0)
  87. message ("-- WAMR JIT disabled due to WAMR AOT is disabled")
  88. endif ()
  89. else ()
  90. unset (LLVM_AVAILABLE_LIBS)
  91. endif ()
  92. message ("-- Build Configurations:")
  93. message (" Build as target ${WAMR_BUILD_TARGET}")
  94. message (" CMAKE_BUILD_TYPE " ${CMAKE_BUILD_TYPE})
  95. if (WAMR_BUILD_INTERP EQUAL 1)
  96. message (" WAMR Interpreter enabled")
  97. else ()
  98. message (" WAMR Interpreter disbled")
  99. endif ()
  100. if (WAMR_BUILD_AOT EQUAL 1)
  101. message (" WAMR AOT enabled")
  102. else ()
  103. message (" WAMR AOT disbled")
  104. endif ()
  105. if (WAMR_BUILD_JIT EQUAL 1)
  106. message (" WAMR JIT enabled")
  107. else ()
  108. message (" WAMR JIT disbled")
  109. endif ()
  110. if (WAMR_BUILD_LIBC_BUILTIN EQUAL 1)
  111. message (" Libc builtin enabled")
  112. else ()
  113. message (" Libc builtin disbled")
  114. endif ()
  115. if (WAMR_BUILD_LIBC_WASI EQUAL 1)
  116. message (" Libc WASI enabled")
  117. else ()
  118. message (" Libc WASI disbled")
  119. endif ()