Skip to content

Commit

Permalink
fixes release mode issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ypujante committed Jul 28, 2024
1 parent e54898f commit a725563
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
17 changes: 12 additions & 5 deletions test/demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ project(emscripten_glfw_demo LANGUAGES CXX)

set(target "demo")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sMIN_WEBGL_VERSION=2 -sNO_DISABLE_EXCEPTION_CATCHING -s ASSERTIONS=1 -s WASM=1 -s SAFE_HEAP=1 --shell-file ${CMAKE_CURRENT_LIST_DIR}/shell.html")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sMIN_WEBGL_VERSION=2 -sNO_DISABLE_EXCEPTION_CATCHING -s ASSERTIONS=1 -s WASM=1 -s SAFE_HEAP=1")

add_executable(${target} src/main.cpp src/Triangle.cpp)
set_target_properties(${target} PROPERTIES OUTPUT_NAME "main")
set_target_properties(${target} PROPERTIES SUFFIX ".html")
target_link_libraries(${target} PRIVATE glfw3)

# Copy (and processes) shell.html
set(SHELL_SRC "${CMAKE_CURRENT_LIST_DIR}/shell.html")
set(SHELL_DST "${CMAKE_CURRENT_BINARY_DIR}/main.html")

# using port
# mkdir build
#emcc --use-port=contrib.glfw3 -sASYNCIFY -sMIN_WEBGL_VERSION=2 --shell-file=shell.html src/main.cpp src/Triangle.cpp -o build/index.html
add_custom_command(
OUTPUT ${SHELL_DST}
COMMAND ${CMAKE_COMMAND} -D SRC=${SHELL_SRC} -D DST=${SHELL_DST} -P ${CMAKE_CURRENT_LIST_DIR}/CopyResource.cmake
DEPENDS ${SHELL_SRC}
)
add_custom_target(copy_shell_html DEPENDS ${SHELL_DST})

add_dependencies(${target} copy_shell_html)
5 changes: 5 additions & 0 deletions test/demo/CopyResource.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.28)

message(STATUS "Copying resource SRC=${SRC} | DST=${DST}")

configure_file(${SRC} ${DST} @ONLY)
4 changes: 2 additions & 2 deletions test/demo/shell.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ <h3 class="clear-float">Actions</h3>
</tr>
<tr class="GetClipboardString">
<td class="action">GetClipboardString (async)</td>
<td colspan="2"><input type="button" value="Paste" onclick="Module.pushEvent('async_get_clipboard_string');"> <label>Result: <input type="text" value="-" disabled></label></td>
<td colspan="2"><input type="button" value="Paste" onclick="Module.pushEvent('async_get_clipboard_string');"> <label>Result: <input class="value" type="text" value="-" disabled></label></td>
</tr>
<tr>
<td class="action">Change focus</td>
Expand Down Expand Up @@ -467,6 +467,6 @@ <h3 class="clear-float">Actions</h3>
// }

</script>
{{{ SCRIPT }}}
<script async src='main.js'></script>
</body>
</html>
8 changes: 5 additions & 3 deletions test/demo/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ bool handleEvents()
}
}

constexpr auto kGetClipboardStringValueSelector = ".GetClipboardString .value";

//------------------------------------------------------------------------
// one iteration of the loop
//------------------------------------------------------------------------
Expand All @@ -137,14 +139,14 @@ bool iter()
auto value = kClipboardString.get();
if(value.hasValue())
{
setHtmlValue(".GetClipboardString input[type='text']", value.value());
setHtmlValue(kGetClipboardStringValueSelector, value.value());
}
else
{
// convoluted way of doing it to test the API...
auto error = value.hasError() ? value.value_or("Error: " + value.error()) : "Not Reached";
printf("GetClipboardString: %s\n", value.error().c_str());
setHtmlValue(".GetClipboardString input[type='text']", error);
setHtmlValue(kGetClipboardStringValueSelector, error);
}
kClipboardString = {};
}
Expand Down Expand Up @@ -199,7 +201,7 @@ int main()
printf("GLFW: %s | Platform: 0x%x\n", glfwGetVersionString(), glfwGetPlatform());
printf("emscripten: v%d.%d.%d\n", __EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__);
setHtmlValue("#version", glfwGetVersionString());
setHtmlValue(".GetClipboardString input[type='text']", "-");
setHtmlValue(kGetClipboardStringValueSelector, "-");

auto canvas1Enabled = static_cast<bool>(EM_ASM_INT( return Module.canvas1Enabled; ));
auto canvas2Enabled = static_cast<bool>(EM_ASM_INT( return Module.canvas2Enabled; ));
Expand Down

0 comments on commit a725563

Please sign in to comment.