@ -5,8 +5,12 @@ include(CTest)
enable_testing ( )
enable_testing ( )
set ( CMAKE_EXECUTABLE_SUFFIX ".wasm" )
set ( CMAKE_EXECUTABLE_SUFFIX ".wasm" )
option ( WASI_SDK_TEST_HOST_TOOLCHAIN "Test against the host toolchain, not a fresh sysroot" OFF )
if ( NOT WASI_SDK_TEST_HOST_TOOLCHAIN )
add_compile_options ( --sysroot= ${ wasi_sysroot } -resource-dir ${ wasi_resource_dir } )
add_compile_options ( --sysroot= ${ wasi_sysroot } -resource-dir ${ wasi_resource_dir } )
add_link_options ( --sysroot= ${ wasi_sysroot } -resource-dir ${ wasi_resource_dir } )
add_link_options ( --sysroot= ${ wasi_sysroot } -resource-dir ${ wasi_resource_dir } )
endif ( )
# S a n i t y c h e c k s e t u p
# S a n i t y c h e c k s e t u p
if ( NOT ${ CMAKE_SYSTEM_NAME } STREQUAL WASI )
if ( NOT ${ CMAKE_SYSTEM_NAME } STREQUAL WASI )
@ -22,6 +26,8 @@ set(WASI_SDK_RUNWASI "wasmtime" CACHE STRING "Runner for tests")
# T e s t e v e r y t h i n g a t O 0 , O 2 , a n d O 2 + L T O
# T e s t e v e r y t h i n g a t O 0 , O 2 , a n d O 2 + L T O
set ( opt_flags -O0 -O2 "-O2 -flto" )
set ( opt_flags -O0 -O2 "-O2 -flto" )
add_custom_target ( build-tests )
# E x e c u t e s a s i n g l e ` t e s t ` s p e c i f i e d .
# E x e c u t e s a s i n g l e ` t e s t ` s p e c i f i e d .
#
#
# T h i s w i l l c o m p i l e ` t e s t ` f o r a l l t h e v a r i o u s t a r g e t s a n d w i t h v a r i o u s
# T h i s w i l l c o m p i l e ` t e s t ` f o r a l l t h e v a r i o u s t a r g e t s a n d w i t h v a r i o u s
@ -35,6 +41,7 @@ function(add_testcase runwasi test)
# A d d a n e w t e s t e x e c u t a b l e b a s e d o n ` t e s t `
# A d d a n e w t e s t e x e c u t a b l e b a s e d o n ` t e s t `
add_executable ( ${ target_name } ${ test } )
add_executable ( ${ target_name } ${ test } )
add_dependencies ( build-tests ${ target_name } )
# C o n f i g u r e a l l t h e c o m p i l e o p t i o n s n e c e s s a r y . F o r e x a m p l e ` - - t a r g e t ` h e r e
# C o n f i g u r e a l l t h e c o m p i l e o p t i o n s n e c e s s a r y . F o r e x a m p l e ` - - t a r g e t ` h e r e
# i f t h e t a r g e t d o e s n ' t l o o k l i k e i t ' s a l r e a d y i n t h e n a m e o f t h e c o m p i l e r
# i f t h e t a r g e t d o e s n ' t l o o k l i k e i t ' s a l r e a d y i n t h e n a m e o f t h e c o m p i l e r
@ -60,10 +67,14 @@ function(add_testcase runwasi test)
# A p p l y l a n g u a g e - s p e c i f i c o p t i o n s a n d d e p e n d e n c i e s .
# A p p l y l a n g u a g e - s p e c i f i c o p t i o n s a n d d e p e n d e n c i e s .
if ( test MATCHES "cc$" )
if ( test MATCHES "cc$" )
target_compile_options ( ${ target_name } PRIVATE -fno-exceptions )
target_compile_options ( ${ target_name } PRIVATE -fno-exceptions )
if ( NOT WASI_SDK_TEST_HOST_TOOLCHAIN )
add_dependencies ( ${ target_name } libcxx- ${ target } )
add_dependencies ( ${ target_name } libcxx- ${ target } )
endif ( )
else ( )
else ( )
if ( NOT WASI_SDK_TEST_HOST_TOOLCHAIN )
add_dependencies ( ${ target_name } wasi-libc- ${ target } )
add_dependencies ( ${ target_name } wasi-libc- ${ target } )
endif ( )
endif ( )
endif ( )
# A p p l y t a r g e t - s p e c i f i c o p t i o n s .
# A p p l y t a r g e t - s p e c i f i c o p t i o n s .
if ( target MATCHES threads )
if ( target MATCHES threads )