Path: blob/main/crates/c-api/tests/CMakeLists.txt
3093 views
include(FetchContent)1FetchContent_Declare(2googletest3URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip4)5# For Windows: Prevent overriding the parent project's compiler/linker settings6set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)7FetchContent_MakeAvailable(googletest)89include(GoogleTest)1011function(add_capi_test name)12cmake_parse_arguments(PARSE_ARGV 1 arg "" "" "FILES")13add_executable(test-${name} ${arg_FILES})14target_link_libraries(test-${name} PRIVATE wasmtime-cpp gtest_main)15gtest_discover_tests(test-${name}16# GitHub Actions on Windows is pretty slow, let's give it lots more time17# than the default 5 seconds.18DISCOVERY_TIMEOUT 60)19endfunction()2021add_capi_test(tests FILES22simple.cc23types.cc24memory_type.cc25val_type.cc26global_type.cc27table_type.cc28func_type.cc29import_type.cc30export_type.cc31extern_type.cc32func.cc33component/instantiate.cc34component/define_module.cc35component/lookup_func.cc36component/call_func.cc37component/values.cc38component/linker.cc39component/types.cc40error.cc41config.cc42wat.cc43module.cc44engine.cc45trap.cc46wasi.cc47store.cc48val.cc49table.cc50global.cc51memory.cc52instance.cc53linker.cc54wasip2.cc55)5657# Create a list of all wasmtime headers with `GLOB_RECURSE`, then emit a file58# into the current binary directory which tests that if the header is included59# that the file compiles correctly.60#61# Gather everything into a list and then create a test which links all these62# compilations together. This binary doesn't actually run any tests itself but63# it does test that all headers compile in isolation at least. Not perfect but64# hopefully at least something.65cmake_path(APPEND CMAKE_CURRENT_SOURCE_DIR "../include" OUTPUT_VARIABLE header_root)66file(GLOB_RECURSE cpp_headers "${header_root}/*.h*")67foreach(header IN LISTS cpp_headers)68cmake_path(GET header EXTENSION header_extension)69if(header_extension STREQUAL ".h.in")70continue()71endif()72cmake_path(73RELATIVE_PATH header74BASE_DIRECTORY ${header_root}75OUTPUT_VARIABLE rel_header)76cmake_path(APPEND CMAKE_CURRENT_BINARY_DIR "header-test" "${rel_header}.cc"77OUTPUT_VARIABLE test_filename)78list(APPEND header_tests ${test_filename})7980file(WRITE ${test_filename} "#include <${rel_header}>")81endforeach()82add_capi_test(standalone-headers FILES ${header_tests})8384# Add a custom test where two files include `wasmtime.hh` and are compiled into85# the same executable (basically makes sure any defined functions in the header86# are tagged with `inline`).87add_capi_test(test-double-include FILES double-include-a.cc double-include-b.cc)888990