diff --git a/meson.build b/meson.build index 3e0ef609..c558d4ce 100644 --- a/meson.build +++ b/meson.build @@ -83,6 +83,10 @@ if get_option('bindings').contains('capi') == true config_h.set10('THORVG_CAPI_BINDING_SUPPORT', true) endif +if get_option('bindings').contains('wasm') == true + config_h.set10('THORVG_WASM_BINDING_SUPPORT', true) +endif + #Log if get_option('log') == true config_h.set10('THORVG_LOG_ENABLED', true) @@ -126,12 +130,13 @@ Summary: Loader (WEBP_BETA): @10@ Loader (LOTTIE_BETA): @11@ Saver (TVG): @12@ - CAPI Binding: @13@ - Log Message: @14@ - Tests: @15@ - Examples: @16@ - Tool (Svg2Tvg): @17@ - Tool (Svg2Png): @18@ + Binding (CAPI): @13@ + Binding (WASM): @14@ + Log Message: @15@ + Tests: @16@ + Examples: @17@ + Tool (Svg2Tvg): @18@ + Tool (Svg2Png): @19@ '''.format( meson.project_version(), @@ -148,6 +153,7 @@ Summary: get_option('loaders').contains('lottie_beta'), all_savers or get_option('savers').contains('tvg'), get_option('bindings').contains('capi'), + get_option('bindings').contains('wasm'), get_option('log'), get_option('tests'), get_option('examples'), diff --git a/meson_options.txt b/meson_options.txt index 1a56c650..a4c9cab2 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -23,7 +23,7 @@ option('vector', option('bindings', type: 'array', - choices: ['', 'capi'], + choices: ['', 'capi', 'wasm'], value: [''], description: 'Enable API bindings') diff --git a/src/bindings/meson.build b/src/bindings/meson.build index 00dcadad..3d32d319 100644 --- a/src/bindings/meson.build +++ b/src/bindings/meson.build @@ -1,3 +1,7 @@ if get_option('bindings').contains('capi') == true subdir('capi') endif + +if get_option('bindings').contains('wasm') == true + subdir('wasm') +endif diff --git a/src/bindings/wasm/meson.build b/src/bindings/wasm/meson.build new file mode 100644 index 00000000..49ee8d92 --- /dev/null +++ b/src/bindings/wasm/meson.build @@ -0,0 +1,13 @@ +if (cc.get_id() == 'emscripten') + source_file = files('tvgWasm.cpp') + thorvg_wasm_dep = declare_dependency(include_directories + : include_directories('.'), sources + : source_file) + executable('thorvg-wasm', + [], + include_directories : headers, + dependencies : [thorvg_lib_dep, thorvg_wasm_dep], + ) +else + message('wasm compiler is not the emscripten!') +endif diff --git a/src/wasm/thorvgwasm.cpp b/src/bindings/wasm/tvgWasm.cpp similarity index 100% rename from src/wasm/thorvgwasm.cpp rename to src/bindings/wasm/tvgWasm.cpp diff --git a/src/meson.build b/src/meson.build index 8981077e..2ae3e066 100644 --- a/src/meson.build +++ b/src/meson.build @@ -60,16 +60,6 @@ thorvg_lib = library( override_options : override_options ) -if (cc.get_id() == 'emscripten') - subdir('wasm') - - executable('thorvg-wasm', - [], - include_directories : headers, - dependencies : [thorvg_lib_dep, thorvg_wasm_dep], - ) -endif - pkg_mod = import('pkgconfig') pkg_mod.generate( diff --git a/src/wasm/meson.build b/src/wasm/meson.build deleted file mode 100644 index 61bddc47..00000000 --- a/src/wasm/meson.build +++ /dev/null @@ -1,5 +0,0 @@ -source_file = files('thorvgwasm.cpp') - - thorvg_wasm_dep = declare_dependency(include_directories - : include_directories('.'), sources - : source_file) diff --git a/wasm_build.sh b/wasm_build.sh index da5146c3..5ec57440 100755 --- a/wasm_build.sh +++ b/wasm_build.sh @@ -1,12 +1,12 @@ #!/bin/bash +#https://github.com/thorvg/thorvg/wiki/ThorVG-Viewer-Development-Guide + if [ ! -d "./build_wasm" ]; then sed "s|EMSDK:|$1|g" wasm_cross.txt > /tmp/.wasm_cross.txt - meson -Db_lto=true -Ddefault_library=static -Dstatic=true -Dloaders="all, lottie_beta" -Dsavers="all" -Dlog=true --cross-file /tmp/.wasm_cross.txt build_wasm + meson -Db_lto=true -Ddefault_library=static -Dstatic=true -Dloaders="all, lottie_beta" -Dsavers="all" -Dbindings="wasm" -Dlog=true --cross-file /tmp/.wasm_cross.txt build_wasm cp ./test/wasm/wasm_test.html build_wasm/src/index.html fi ninja -C build_wasm/ -echo "RESULT:" -echo " thorvg-wasm.wasm and thorvg-wasm.js can be found in build_wasm/src folder" -ls -lrt build_wasm/src/thorvg-wasm.* +ls -lrt build_wasm/src/bindings/wasm/thorvg-wasm.*