To my delight, recently vcpkg received Emscripten support - see PR.
One can install packages like so:
vcpkg install zlib:wasm32-emscripten
Usage is pretty usual standard, for example CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(zpipe CXX)
find_package(ZLIB REQUIRED)
add_executable(zpipe zpipe.cpp)
target_link_libraries(zpipe ZLIB::ZLIB)
The tricky part is still as in question how to combine two toolchains. This invocation works for me:
mkdir build
cd build
emcmake "c:\Program files\CMake\bin\cmake" .. "-G" "Ninja" "-DCMAKE_MAKE_PROGRAM=F:/vcpkg/downloads/tools/ninja/1.10.1-windows/ninja.exe" "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=%EMSDK%/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" "-DVCPKG_TARGET_TRIPLET=wasm32-emscripten" "-DCMAKE_TOOLCHAIN_FILE=F:/vcpkg/scripts/buildsystems/vcpkg.cmake" "-DCMAKE_BUILD_TYPE=Release"
emmake ninja
As usually, this needs first Emscripten environment variables set (e.g. with emsdk_env.bat
).
Failing to provide this asked second toolchain will result with errors like wasm-ld: error: unknown argument: --out-implib
If for whatever reason (e.g. not absolute path) emcmake can't find the CMake executable, it may result with errors like FileNotFoundError: [WinError 2] The system cannot find the file specified
In case of CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set.
, as hinted, the CMAKE_MAKE_PROGRAM
needs to be set pointing to ninja executable.