Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake with Emscripten and vcpkg can't bind two TOOLCHAIN_FILES

Both vcpkg and Emscripten require to set CMAKE_TOOLCHAIN_FILE to

vcpkg/scripts/buildsystems/vcpkg.cmake and emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake respectively.

How do i do that? or what is the best way to get them both working together?

right now i have a naive attempt:

set(CMAKE_TOOLCHAIN_FILE "/Users/screen-photo-to-text/vcpkg/scripts/buildsystems/vcpkg.cmake" "/Users/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake")

But it get Could not find toolchain file error and i can't find a way to get this working

like image 589
Alejandro Camba Avatar asked Sep 03 '25 07:09

Alejandro Camba


1 Answers

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.

like image 132
stoper Avatar answered Sep 05 '25 01:09

stoper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!