How to install both .js and .wasm files with the CMake target for emscripten?
Asked Answered
V

1

7

When building a C++/web-assembly project with CMake and emscripten, the install command for the target only install the .js file and not the .wasm file.

install(TARGETS MyTarget RUNTIME DESTINATION ${CMAKE_BINARY_DIR}/dist)

This will install the JS file only. I tried to add rules for LIBRARY, RESOURCE, ARCHIVE... but the Wasm is never copied. I could not find anything in the official doc.

I know it's easy to workaround using the install(FILES ... command to force the copy of the wasm, but is there no way to make the standard install work for both files? They are both needed as a target...

Vinegar answered 18/5, 2020 at 8:33 Comment(1)
I have the same issue. Found a relevant CMake bug but no solution yet.Roulette
S
3

Here is an example of the workaround mentioned in the question for others like me who landed on this page after googling.

if (NOT EMSCRIPTEN)
    install(TARGETS MyTarget RUNTIME DESTINATION ${CMAKE_BINARY_DIR}/dist)
else()
    install(FILES
        "$<TARGET_FILE_DIR:MyTarget>/MyTarget.js"
        "$<TARGET_FILE_DIR:MyTarget>/MyTarget.wasm"
        DESTINATION ${CMAKE_BINARY_DIR}/dist)
endif()
Skew answered 13/1, 2022 at 19:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.