summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2020-01-16 14:53:11 -0800
committerGitHub <noreply@github.com>2020-01-16 14:53:11 -0800
commit7c80d05e37dc02870c680869ae3f04ac6d9637ee (patch)
tree57645c67379d4e6ec49773b3494dc752ffcb5e68 /CMakeLists.txt
parentd663c80dcb627fed3e21cfa2b47465452a83a894 (diff)
downloadwabt-7c80d05e37dc02870c680869ae3f04ac6d9637ee.tar.gz
wabt-7c80d05e37dc02870c680869ae3f04ac6d9637ee.tar.bz2
wabt-7c80d05e37dc02870c680869ae3f04ac6d9637ee.zip
Initial WASM C API implementation. (#1250)
All tests except `threads` pass.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt62
1 files changed, 60 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index edbb072e..363a5660 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -224,7 +224,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${WABT_SOURCE_DIR}/cmake)
add_custom_target(everything)
-add_library(wabt STATIC
+set(WABT_LIBRARY_SRC
src/apply-names.h
src/apply-names.cc
src/binary.h
@@ -308,12 +308,27 @@ add_library(wabt STATIC
# TODO(binji): Move this into its own library?
src/interp/binary-reader-interp.h
src/interp/binary-reader-interp.cc
+ src/interp/binary-reader-metadata.h
+ src/interp/binary-reader-metadata.cc
src/interp/interp.h
src/interp/interp.cc
src/interp/interp-disassemble.cc
src/interp/interp-trace.cc
)
+add_library(wabt STATIC ${WABT_LIBRARY_SRC})
+
+# libwasm, which implenents the wasm C API
+add_library(wasm SHARED ${WABT_LIBRARY_SRC} src/interp/interp-wasm-c-api.cc)
+target_link_libraries(wasm wabt)
+target_include_directories(wasm PUBLIC third_party/wasm-c-api/include)
+if (COMPILER_IS_MSVC)
+ target_compile_definitions(wasm PRIVATE "WASM_API_EXTERN=__declspec(dllexport)")
+else ()
+ target_compile_options(wasm PRIVATE -Wno-old-style-cast)
+ target_compile_definitions(wasm PRIVATE "WASM_API_EXTERN=__attribute__((visibility(\"default\")))")
+endif ()
+set_target_properties(wasm PROPERTIES CXX_VISIBILITY_PRESET hidden)
if (NOT EMSCRIPTEN)
if (CODE_COVERAGE)
@@ -507,6 +522,7 @@ if (NOT EMSCRIPTEN)
# See: https://github.com/actions/setup-python/issues/40
find_package(PythonInterp REQUIRED)
set(RUN_TESTS_PY ${WABT_SOURCE_DIR}/test/run-tests.py)
+
add_custom_target(run-tests
COMMAND ${PYTHON_EXECUTABLE} ${RUN_TESTS_PY} --bindir $<TARGET_FILE_DIR:wat2wasm>
DEPENDS ${WABT_EXECUTABLES}
@@ -521,7 +537,49 @@ if (NOT EMSCRIPTEN)
${USES_TERMINAL}
)
- add_custom_target(check DEPENDS run-tests wabt-unittests)
+ add_custom_target(run-c-api-tests
+ COMMAND ${PYTHON_EXECUTABLE} ${WABT_SOURCE_DIR}/test/run-c-api-examples.py --bindir $<TARGET_FILE_DIR:wat2wasm>
+ WORKING_DIRECTORY ${WABT_SOURCE_DIR}
+ ${USES_TERMINAL}
+ )
+
+ add_custom_target(check DEPENDS run-unittests run-tests run-c-api-tests)
+
+ function(c_api_example NAME)
+ set(EXENAME wasm-c-api-${NAME})
+ add_executable(${EXENAME} third_party/wasm-c-api/example/${NAME}.c)
+ if (NOT COMPILER_IS_MSVC)
+ set_target_properties(${EXENAME} PROPERTIES COMPILE_FLAGS "-std=gnu11 -Wno-pointer-to-int-cast")
+ endif ()
+ target_link_libraries(${EXENAME} wasm Threads::Threads)
+ add_custom_target(${EXENAME}-copy-to-bin ALL
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${WABT_SOURCE_DIR}/bin
+ COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${EXENAME}> ${WABT_SOURCE_DIR}/bin/
+ COMMAND ${CMAKE_COMMAND} -E copy ${WABT_SOURCE_DIR}/third_party/wasm-c-api/example/${NAME}.wasm $<TARGET_FILE_DIR:${EXENAME}>/
+ COMMAND ${CMAKE_COMMAND} -E copy ${WABT_SOURCE_DIR}/third_party/wasm-c-api/example/${NAME}.wasm ${WABT_SOURCE_DIR}/bin/
+ DEPENDS ${EXENAME}
+ )
+ add_dependencies(run-c-api-tests ${EXENAME})
+ endfunction()
+
+ c_api_example(callback)
+ c_api_example(finalize)
+ c_api_example(global)
+ c_api_example(hello)
+ c_api_example(hostref)
+ c_api_example(multi)
+ c_api_example(memory)
+ c_api_example(reflect)
+ c_api_example(serialize)
+ c_api_example(start)
+ c_api_example(table)
+ c_api_example(trap)
+ if (NOT WIN32)
+ # depends on pthreads
+ set(THREADS_PREFER_PTHREAD_FLAG ON)
+ find_package(Threads REQUIRED)
+ c_api_example(threads)
+ endif ()
endif ()
# install