CMakeLists.txt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  2. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  3. cmake_minimum_required (VERSION 3.14)
  4. project (wamr_unit_tests)
  5. include (CTest)
  6. if (NOT DEFINED WAMR_BUILD_INTERP)
  7. # Enable Interpreter by default
  8. set (WAMR_BUILD_INTERP 1)
  9. endif ()
  10. if (NOT DEFINED WAMR_BUILD_PLATFORM)
  11. string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
  12. endif ()
  13. set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
  14. include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
  15. add_library (vmlib ${WAMR_RUNTIME_LIB_SOURCE})
  16. include (FetchContent)
  17. FetchContent_Declare (
  18. googletest
  19. URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
  20. )
  21. # For Windows: Prevent overriding the parent project's compiler/linker settings
  22. set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
  23. FetchContent_MakeAvailable (googletest)
  24. include (GoogleTest)
  25. add_library (wamr_gtest_main main.cpp)
  26. target_link_libraries (wamr_gtest_main PUBLIC gtest vmlib)
  27. function (create_wamr_unit_test test_name)
  28. set (sources ${ARGN})
  29. add_executable (${test_name} ${sources})
  30. target_link_libraries (
  31. ${test_name}
  32. wamr_gtest_main
  33. vmlib
  34. ${LLVM_AVAILABLE_LIBS}
  35. )
  36. gtest_discover_tests (${test_name})
  37. endfunction ()
  38. if (WAMR_BUILD_LIB_WASI_THREADS EQUAL 1)
  39. include (${IWASM_DIR}/libraries/lib-wasi-threads/unit-test/lib_wasi_threads_unit_tests.cmake)
  40. endif ()