CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. cmake_minimum_required(VERSION 3.14)
  4. project(unit-test)
  5. option(FULL_TEST "Build all unit tests including llm-enhanced-test" OFF)
  6. # Yes. To solve the compatibility issue with CMAKE (>= 4.0), we need to update
  7. # our `cmake_minimum_required()` to 3.5. However, there are CMakeLists.txt
  8. # from 3rd parties that we should not alter. Therefore, in addition to
  9. # changing the `cmake_minimum_required()`, we should also add a configuration
  10. # here that is compatible with earlier versions.
  11. set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
  12. SET(CMAKE_BUILD_TYPE Debug)
  13. set(CMAKE_CXX_STANDARD 17)
  14. #TODO: modularization me
  15. # Detect Hosting target info
  16. string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
  17. # Set WAMR_BUILD_TARGET, currently values supported:
  18. # "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
  19. # "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
  20. if (NOT DEFINED WAMR_BUILD_TARGET)
  21. if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
  22. set (WAMR_BUILD_TARGET "AARCH64")
  23. elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
  24. set (WAMR_BUILD_TARGET "RISCV64")
  25. elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
  26. # Build as X86_64 by default in 64-bit platform
  27. set (WAMR_BUILD_TARGET "X86_64")
  28. elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
  29. # Build as X86_32 by default in 32-bit platform
  30. set (WAMR_BUILD_TARGET "X86_32")
  31. else ()
  32. message(SEND_ERROR "Unsupported build target platform!")
  33. endif ()
  34. endif ()
  35. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
  36. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
  37. if(WAMR_BUILD_TARGET STREQUAL "X86_32")
  38. # 1) Force -m32
  39. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "" FORCE)
  40. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "" FORCE)
  41. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32" CACHE STRING "" FORCE)
  42. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32" CACHE STRING "" FORCE)
  43. # 2) Make CMake prefer i386 libraries
  44. set(CMAKE_SYSTEM_PROCESSOR i386 CACHE STRING "" FORCE)
  45. set(CMAKE_LIBRARY_ARCHITECTURE "i386-linux-gnu" CACHE STRING "" FORCE)
  46. endif()
  47. # Fetch Google test
  48. include (FetchContent)
  49. if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
  50. FetchContent_Declare (
  51. googletest
  52. URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
  53. DOWNLOAD_EXTRACT_TIMESTAMP ON
  54. )
  55. else()
  56. FetchContent_Declare (
  57. googletest
  58. URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
  59. )
  60. endif()
  61. # Prevent overriding the parent project's compiler/linker
  62. # settings on Windows
  63. set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  64. FetchContent_MakeAvailable(googletest)
  65. # Fetch CMocka for C unit tests
  66. if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
  67. FetchContent_Declare(
  68. cmocka
  69. URL https://git.cryptomilk.org/projects/cmocka.git/snapshot/cmocka-2.0.1.tar.gz
  70. DOWNLOAD_EXTRACT_TIMESTAMP ON
  71. )
  72. else()
  73. FetchContent_Declare(
  74. cmocka
  75. URL https://git.cryptomilk.org/projects/cmocka.git/snapshot/cmocka-2.0.1.tar.gz
  76. )
  77. endif()
  78. FetchContent_MakeAvailable(cmocka)
  79. include(GoogleTest)
  80. enable_testing()
  81. add_subdirectory(wasm-vm)
  82. add_subdirectory(interpreter)
  83. add_subdirectory(wasm-c-api)
  84. add_subdirectory(libc-builtin)
  85. add_subdirectory(shared-utils)
  86. add_subdirectory(linear-memory-wasm)
  87. add_subdirectory(linear-memory-aot)
  88. add_subdirectory(linux-perf)
  89. add_subdirectory(gc)
  90. add_subdirectory(unsupported-features)
  91. add_subdirectory(exception-handling)
  92. add_subdirectory(running-modes)
  93. add_subdirectory(mem-alloc)
  94. if(FULL_TEST)
  95. message(STATUS "FULL_TEST=ON: include llm-enhanced-test")
  96. add_subdirectory(llm-enhanced-test)
  97. else()
  98. message(STATUS "FULL_TEST=OFF: exclude llm-enhanced-test")
  99. endif()
  100. if(WAMR_BUILD_TARGET STREQUAL "X86_64")
  101. add_subdirectory(aot-stack-frame)
  102. # should enable 32-bit llvm when X86_32
  103. add_subdirectory (aot)
  104. add_subdirectory (custom-section)
  105. add_subdirectory (compilation)
  106. add_subdirectory (memory64)
  107. add_subdirectory (shared-heap)
  108. # HW_BOUND_CHECK is not supported on X86_32
  109. add_subdirectory (runtime-common)
  110. endif()
  111. if(WAMR_BUILD_TARGET STREQUAL "AARCH64")
  112. add_subdirectory(aot-stack-frame)
  113. add_subdirectory (aot)
  114. add_subdirectory (custom-section)
  115. add_subdirectory (compilation)
  116. add_subdirectory (memory64)
  117. add_subdirectory (shared-heap)
  118. add_subdirectory (runtime-common)
  119. endif ()