Path: blob/main/crates/c-api/tests/CMakeLists.txt
1692 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.cc38error.cc39config.cc40wat.cc41module.cc42engine.cc43trap.cc44wasi.cc45store.cc46val.cc47table.cc48global.cc49memory.cc50instance.cc51linker.cc52wasip2.cc53)5455# Create a list of all wasmtime headers with `GLOB_RECURSE`, then emit a file56# into the current binary directory which tests that if the header is included57# that the file compiles correctly.58#59# Gather everything into a list and then create a test which links all these60# compilations together. This binary doesn't actually run any tests itself but61# it does test that all headers compile in isolation at least. Not perfect but62# hopefully at least something.63cmake_path(APPEND CMAKE_CURRENT_SOURCE_DIR "../include" OUTPUT_VARIABLE header_root)64file(GLOB_RECURSE cpp_headers "${header_root}/*.h*")65foreach(header IN LISTS cpp_headers)66cmake_path(GET header EXTENSION header_extension)67if(header_extension STREQUAL ".h.in")68continue()69endif()70cmake_path(GET header FILENAME header_filename)71cmake_path(APPEND CMAKE_CURRENT_BINARY_DIR "header-test" "${header_filename}.cc"72OUTPUT_VARIABLE test_filename)73list(APPEND header_tests ${test_filename})7475cmake_path(76RELATIVE_PATH header77BASE_DIRECTORY ${header_root}78OUTPUT_VARIABLE rel_header)79file(WRITE ${test_filename} "#include <${rel_header}>")80endforeach()81add_capi_test(standalone-headers FILES ${header_tests})8283# Add a custom test where two files include `wasmtime.hh` and are compiled into84# the same executable (basically makes sure any defined functions in the header85# are tagged with `inline`).86add_capi_test(test-double-include FILES double-include-a.cc double-include-b.cc)878889