I'm trying to use emscripten from cmake and generate a html file as the output, but it doesn't output an html file. Instead, it only outputs a js and wasm file.
I include/set the Emscripten toolchain file and set the CMAKE_EXECUTABLE_SUFFIX
, But it doesn't work!
CMakeLists.txt
cmake_minimum_required(VERSION 3.2.1)
set(LINK_OPTIONS)
set(CMAKE_TOOLCHAIN_FILE $ENV{EMSDK_HOME}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
set(LINK_OPTIONS ${LINK_OPTIONS} -sWASM=1 -sALLOW_MEMORY_GROWTH=1 -sNO_EXIT_RUNTIME=0 -sASSERTIONS=1)
project(emscripten_project)
add_executable(emscripten_project main.cpp)
target_link_options(emscripten_project PUBLIC ${LINK_OPTIONS})
main.cpp
#include <iostream>
int main()
{
std::cout << "Emscripten Example\n";
return 0;
}
The Configure and Build Commands
cmake . -G Ninja && ninja
Running ninja -v
, gives this:
[2/2] cmd.exe /C "cd . && C:\emsdk\upstream\emscripten\em++.bat -o emscripten_project.html -sUSE_GLFW=3 -sWASM=1 -sALLOW_MEMORY_GROWTH=1 -sNO_EXIT_RUNTIME=0 -sASSERTIONS=1 CMakeFiles/emscripten_project.dir/src/main.cpp.o -o emscripten_project.js && cd ."
The important part is that something is passing -o emscripten_project.js
after the first -o emscripten_project.html
My installed CMake version is 3.25.2, and emcc
version output is "emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.25 (febd44b21ecaca86e2cb2a25ef3ed4a0a2076365)"
This issue also occurs when I use the emcmake
wrapper isntead of specifying the toolchain file path manually.