summaryrefslogtreecommitdiff
path: root/os/emscripten/cmake
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2020-12-05 21:57:47 +0100
committerPatric Stout <github@truebrain.nl>2020-12-15 15:46:39 +0100
commitd15dc9f40f5a20bff452547a2dcb15231f9f969d (patch)
tree7b8d88635c048d906cbb6358007fb26055e24410 /os/emscripten/cmake
parent2da07f76154d841bcfe9aaff4833144550186deb (diff)
downloadopenttd-d15dc9f40f5a20bff452547a2dcb15231f9f969d.tar.xz
Add: support for emscripten (play-OpenTTD-in-the-browser)
Emscripten compiles to WASM, which can be loaded via HTML / JavaScript. This allows you to play OpenTTD inside a browser. Co-authored-by: milek7 <me@milek7.pl>
Diffstat (limited to 'os/emscripten/cmake')
-rw-r--r--os/emscripten/cmake/FindLibLZMA.cmake20
-rw-r--r--os/emscripten/cmake/FindPNG.cmake7
-rw-r--r--os/emscripten/cmake/FindSDL2.cmake7
-rw-r--r--os/emscripten/cmake/FindZLIB.cmake7
4 files changed, 41 insertions, 0 deletions
diff --git a/os/emscripten/cmake/FindLibLZMA.cmake b/os/emscripten/cmake/FindLibLZMA.cmake
new file mode 100644
index 000000000..99d1ca640
--- /dev/null
+++ b/os/emscripten/cmake/FindLibLZMA.cmake
@@ -0,0 +1,20 @@
+# LibLZMA is a recent addition to the emscripten SDK, so it is possible
+# someone hasn't updated his SDK yet. Test out if the SDK supports LibLZMA.
+include(CheckCXXSourceCompiles)
+set(CMAKE_REQUIRED_FLAGS "-sUSE_LIBLZMA=1")
+
+check_cxx_source_compiles("
+ #include <lzma.h>
+ int main() { return 0; }"
+ LIBLZMA_FOUND
+)
+
+if (LIBLZMA_FOUND)
+ add_library(LibLZMA::LibLZMA INTERFACE IMPORTED)
+ set_target_properties(LibLZMA::LibLZMA PROPERTIES
+ INTERFACE_COMPILE_OPTIONS "-sUSE_LIBLZMA=1"
+ INTERFACE_LINK_LIBRARIES "-sUSE_LIBLZMA=1"
+ )
+else()
+ message(WARNING "You are using an emscripten SDK without LibLZMA support. Many savegames won't be able to load in OpenTTD. Please apply 'emsdk-liblzma.patch' to your local emsdk installation.")
+endif()
diff --git a/os/emscripten/cmake/FindPNG.cmake b/os/emscripten/cmake/FindPNG.cmake
new file mode 100644
index 000000000..2616af33d
--- /dev/null
+++ b/os/emscripten/cmake/FindPNG.cmake
@@ -0,0 +1,7 @@
+add_library(PNG::PNG INTERFACE IMPORTED)
+set_target_properties(PNG::PNG PROPERTIES
+ INTERFACE_COMPILE_OPTIONS "-sUSE_LIBPNG=1"
+ INTERFACE_LINK_LIBRARIES "-sUSE_LIBPNG=1"
+)
+
+set(PNG_FOUND on)
diff --git a/os/emscripten/cmake/FindSDL2.cmake b/os/emscripten/cmake/FindSDL2.cmake
new file mode 100644
index 000000000..54553958b
--- /dev/null
+++ b/os/emscripten/cmake/FindSDL2.cmake
@@ -0,0 +1,7 @@
+add_library(SDL2::SDL2 INTERFACE IMPORTED)
+set_target_properties(SDL2::SDL2 PROPERTIES
+ INTERFACE_COMPILE_OPTIONS "-sUSE_SDL=2"
+ INTERFACE_LINK_LIBRARIES "-sUSE_SDL=2"
+)
+
+set(SDL2_FOUND on)
diff --git a/os/emscripten/cmake/FindZLIB.cmake b/os/emscripten/cmake/FindZLIB.cmake
new file mode 100644
index 000000000..2ade2ba1b
--- /dev/null
+++ b/os/emscripten/cmake/FindZLIB.cmake
@@ -0,0 +1,7 @@
+add_library(ZLIB::ZLIB INTERFACE IMPORTED)
+set_target_properties(ZLIB::ZLIB PROPERTIES
+ INTERFACE_COMPILE_OPTIONS "-sUSE_ZLIB=1"
+ INTERFACE_LINK_LIBRARIES "-sUSE_ZLIB=1"
+)
+
+set(ZLIB_FOUND on)