Makefile.emscripten 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #
  2. # Makefile to use with emscripten
  3. # See https://emscripten.org/docs/getting_started/downloads.html
  4. # for installation instructions.
  5. #
  6. # This Makefile assumes you have loaded emscripten's environment.
  7. # (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead)
  8. #
  9. # Running `make` will produce three files:
  10. # - web/index.html (current stored in the repository)
  11. # - web/index.js
  12. # - web/index.wasm
  13. #
  14. # All three are needed to run the demo.
  15. CC = emcc
  16. CXX = em++
  17. WEB_DIR = web
  18. EXE = $(WEB_DIR)/index.js
  19. IMGUI_DIR = ../..
  20. SOURCES = main.cpp
  21. SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
  22. SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_wgpu.cpp
  23. OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
  24. UNAME_S := $(shell uname -s)
  25. CPPFLAGS =
  26. LDFLAGS =
  27. EMS =
  28. ##---------------------------------------------------------------------
  29. ## EMSCRIPTEN OPTIONS
  30. ##---------------------------------------------------------------------
  31. # ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
  32. EMS += -s DISABLE_EXCEPTION_CATCHING=1
  33. LDFLAGS += -s USE_GLFW=3 -s USE_WEBGPU=1
  34. LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1
  35. # Emscripten allows preloading a file or folder to be accessible at runtime.
  36. # The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts"
  37. # See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html
  38. # (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.)
  39. USE_FILE_SYSTEM ?= 0
  40. ifeq ($(USE_FILE_SYSTEM), 0)
  41. LDFLAGS += -s NO_FILESYSTEM=1
  42. CPPFLAGS += -DIMGUI_DISABLE_FILE_FUNCTIONS
  43. endif
  44. ifeq ($(USE_FILE_SYSTEM), 1)
  45. LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts
  46. endif
  47. ##---------------------------------------------------------------------
  48. ## FINAL BUILD FLAGS
  49. ##---------------------------------------------------------------------
  50. CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
  51. #CPPFLAGS += -g
  52. CPPFLAGS += -Wall -Wformat -Os $(EMS)
  53. #LDFLAGS += --shell-file shell_minimal.html
  54. LDFLAGS += $(EMS)
  55. ##---------------------------------------------------------------------
  56. ## BUILD RULES
  57. ##---------------------------------------------------------------------
  58. %.o:%.cpp
  59. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  60. %.o:$(IMGUI_DIR)/%.cpp
  61. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  62. %.o:$(IMGUI_DIR)/backends/%.cpp
  63. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  64. all: $(EXE)
  65. @echo Build complete for $(EXE)
  66. $(WEB_DIR):
  67. mkdir $@
  68. serve: all
  69. python3 -m http.server -d $(WEB_DIR)
  70. $(EXE): $(OBJS) $(WEB_DIR)
  71. $(CXX) -o $@ $(OBJS) $(LDFLAGS)
  72. clean:
  73. rm -f $(EXE) $(OBJS) $(WEB_DIR)/*.js $(WEB_DIR)/*.wasm $(WEB_DIR)/*.wasm.pre