Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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...

like image 631
ymoreau Avatar asked May 18 '20 08:05

ymoreau


1 Answers

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()
like image 164
Tyler Drake Avatar answered Sep 28 '22 18:09

Tyler Drake