Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/c-api/tests/CMakeLists.txt
3093 views
1
include(FetchContent)
2
FetchContent_Declare(
3
googletest
4
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip
5
)
6
# For Windows: Prevent overriding the parent project's compiler/linker settings
7
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
8
FetchContent_MakeAvailable(googletest)
9
10
include(GoogleTest)
11
12
function(add_capi_test name)
13
cmake_parse_arguments(PARSE_ARGV 1 arg "" "" "FILES")
14
add_executable(test-${name} ${arg_FILES})
15
target_link_libraries(test-${name} PRIVATE wasmtime-cpp gtest_main)
16
gtest_discover_tests(test-${name}
17
# GitHub Actions on Windows is pretty slow, let's give it lots more time
18
# than the default 5 seconds.
19
DISCOVERY_TIMEOUT 60)
20
endfunction()
21
22
add_capi_test(tests FILES
23
simple.cc
24
types.cc
25
memory_type.cc
26
val_type.cc
27
global_type.cc
28
table_type.cc
29
func_type.cc
30
import_type.cc
31
export_type.cc
32
extern_type.cc
33
func.cc
34
component/instantiate.cc
35
component/define_module.cc
36
component/lookup_func.cc
37
component/call_func.cc
38
component/values.cc
39
component/linker.cc
40
component/types.cc
41
error.cc
42
config.cc
43
wat.cc
44
module.cc
45
engine.cc
46
trap.cc
47
wasi.cc
48
store.cc
49
val.cc
50
table.cc
51
global.cc
52
memory.cc
53
instance.cc
54
linker.cc
55
wasip2.cc
56
)
57
58
# Create a list of all wasmtime headers with `GLOB_RECURSE`, then emit a file
59
# into the current binary directory which tests that if the header is included
60
# that the file compiles correctly.
61
#
62
# Gather everything into a list and then create a test which links all these
63
# compilations together. This binary doesn't actually run any tests itself but
64
# it does test that all headers compile in isolation at least. Not perfect but
65
# hopefully at least something.
66
cmake_path(APPEND CMAKE_CURRENT_SOURCE_DIR "../include" OUTPUT_VARIABLE header_root)
67
file(GLOB_RECURSE cpp_headers "${header_root}/*.h*")
68
foreach(header IN LISTS cpp_headers)
69
cmake_path(GET header EXTENSION header_extension)
70
if(header_extension STREQUAL ".h.in")
71
continue()
72
endif()
73
cmake_path(
74
RELATIVE_PATH header
75
BASE_DIRECTORY ${header_root}
76
OUTPUT_VARIABLE rel_header)
77
cmake_path(APPEND CMAKE_CURRENT_BINARY_DIR "header-test" "${rel_header}.cc"
78
OUTPUT_VARIABLE test_filename)
79
list(APPEND header_tests ${test_filename})
80
81
file(WRITE ${test_filename} "#include <${rel_header}>")
82
endforeach()
83
add_capi_test(standalone-headers FILES ${header_tests})
84
85
# Add a custom test where two files include `wasmtime.hh` and are compiled into
86
# the same executable (basically makes sure any defined functions in the header
87
# are tagged with `inline`).
88
add_capi_test(test-double-include FILES double-include-a.cc double-include-b.cc)
89
90