aboutsummaryrefslogtreecommitdiff
path: root/cmake/platforms/emscripten.cmake
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-10-29 18:22:35 +0100
committerBen Harris <bjh21@bjh21.me.uk>2023-01-19 20:34:48 +0000
commitf9449af87a4f5420aa7683d3f15110bfa2f1bf17 (patch)
tree987c3bd3ad5966b2095bcf52bf72b4de7bea9bd1 /cmake/platforms/emscripten.cmake
parent241f68b543de62a800ff5cbf6c06580d45ab8a13 (diff)
downloadpuzzles-f9449af87a4f5420aa7683d3f15110bfa2f1bf17.zip
puzzles-f9449af87a4f5420aa7683d3f15110bfa2f1bf17.tar.gz
puzzles-f9449af87a4f5420aa7683d3f15110bfa2f1bf17.tar.bz2
puzzles-f9449af87a4f5420aa7683d3f15110bfa2f1bf17.tar.xz
kaios: Major parts of a build for KaiOS
KaiOS (which is based on Firefox OS, formerly Boot to Gecko) runs its "native" apps in a Web browser, so this is essentially a rather specialised version of the JavaScript front-end. Indeed, the JavaScript and C parts are the same as the Web version. There are three major parts that are specific to the KaiOS build. First, there's manifest.pl, which generates a KaiOS-specific JSON manifest describing each puzzle. Second, there's a new HTML page generator, apppage.pl, that generates an HTML page that is much less like a Web page, and much more like an application, than the one generated by jspage.pl. It expects to build a single HTML page at a time and gets all its limited knowledge of the environment from its command line. This makes it gratuitously different from jspage.pl and javapage.pl, but makes it easier to run from the build system. And finally, there's the CMake glue that assembles the necessary parts for each application in a directory. This includes the manifest, the HTML, the JavaScript, the KaiOS-specific icons (generated as part of the GTK build) and a copy of the HTML documentation. The directory is assembled using CMake's install() function, and can be installed on a KaiOS device using the developer tools.
Diffstat (limited to 'cmake/platforms/emscripten.cmake')
-rw-r--r--cmake/platforms/emscripten.cmake67
1 files changed, 67 insertions, 0 deletions
diff --git a/cmake/platforms/emscripten.cmake b/cmake/platforms/emscripten.cmake
index 244cfcb..3cbcab4 100644
--- a/cmake/platforms/emscripten.cmake
+++ b/cmake/platforms/emscripten.cmake
@@ -6,6 +6,11 @@ set(CMAKE_EXECUTABLE_SUFFIX ".js")
set(WASM ON
CACHE BOOL "Compile to WebAssembly rather than plain JavaScript")
+find_program(HALIBUT halibut)
+if(NOT HALIBUT)
+ message(WARNING "HTML documentation cannot be built (did not find halibut)")
+endif()
+
set(emcc_export_list
# Event handlers for mouse and keyboard input
_mouseup
@@ -62,4 +67,66 @@ function(set_platform_puzzle_target_properties NAME TARGET)
endfunction()
function(build_platform_extras)
+ if(HALIBUT)
+ set(help_dir ${CMAKE_CURRENT_BINARY_DIR}/help)
+ add_custom_command(OUTPUT ${help_dir}/en
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${help_dir}/en)
+ add_custom_command(OUTPUT ${help_dir}/en/index.html
+ COMMAND ${HALIBUT} --html -Chtml-template-fragment:%k
+ ${CMAKE_CURRENT_SOURCE_DIR}/puzzles.but
+ DEPENDS
+ ${help_dir}/en
+ ${CMAKE_CURRENT_SOURCE_DIR}/puzzles.but
+ WORKING_DIRECTORY ${help_dir}/en)
+ add_custom_target(kaios_help ALL
+ DEPENDS ${help_dir}/en/index.html)
+ endif()
+
+ # This is probably not the right way to set the destination.
+ set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH
+ "Installation path" FORCE)
+
+ add_custom_target(kaios-extras ALL)
+
+ foreach(name ${puzzle_names})
+ add_custom_command(
+ OUTPUT ${name}-manifest.webapp
+ COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/kaios/manifest.pl
+ "${name}" "${displayname_${name}}" "${description_${name}}"
+ "${objective_${name}}" > "${name}-manifest.webapp"
+ VERBATIM
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/kaios/manifest.pl)
+
+ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/kaios)
+ add_custom_command(
+ OUTPUT ${name}-kaios.html
+ COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/kaios/apppage.pl
+ "${name}" "${displayname_${name}}" > "${name}-kaios.html"
+ VERBATIM
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/kaios/apppage.pl)
+
+ add_custom_target(${name}-kaios-extras
+ DEPENDS ${name}-manifest.webapp ${name}-kaios.html)
+ add_dependencies(kaios-extras ${name}-kaios-extras)
+
+ install(TARGETS ${name} DESTINATION kaios/${name})
+ # Release builds generate an initial memory image alongside the
+ # JavaScript, but CMake doesn't seem to know about it to install
+ # it.
+ install(FILES $<TARGET_FILE:${name}>.mem OPTIONAL
+ DESTINATION kaios/${name})
+ install(FILES ${ICON_DIR}/${name}-56kai.png ${ICON_DIR}/${name}-112kai.png
+ DESTINATION kaios/${name} OPTIONAL)
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name}-kaios.html
+ RENAME ${name}.html
+ DESTINATION kaios/${name})
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${name}-manifest.webapp
+ RENAME manifest.webapp
+ DESTINATION kaios/${name})
+ if (HALIBUT)
+ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/help
+ DESTINATION kaios/${name})
+ endif()
+
+ endforeach()
endfunction()