Debian Codegraph @

examples/example_glfw_wgpu/Makefile.emscripten

raw
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
16 CC = emcc
17 CXX = em++
18 WEB_DIR = web
19 EXE = $(WEB_DIR)/index.js
20 IMGUI_DIR = ../..
21 SOURCES = main.cpp
22 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
23 SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_wgpu.cpp
24 OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
25 UNAME_S := $(shell uname -s)
26 CPPFLAGS =
27 LDFLAGS =
28 EMS =
29
30 ##---------------------------------------------------------------------
31 ## EMSCRIPTEN OPTIONS
32 ##---------------------------------------------------------------------
33
34 # ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
35 # Note: For glfw, we use emscripten-glfw port (contrib.glfw3) instead of (-s USE_GLFW=3) to get a better support for High DPI displays.
36 EMS += -s DISABLE_EXCEPTION_CATCHING=1 --use-port=contrib.glfw3
37 LDFLAGS += -s USE_WEBGPU=1
38 LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1
39
40 # Build as single file (binary text encoded in .html file)
41 #LDFLAGS += -sSINGLE_FILE
42
43 # Emscripten allows preloading a file or folder to be accessible at runtime.
44 # The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts"
45 # See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html
46 # (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.)
47 USE_FILE_SYSTEM ?= 0
48 ifeq ($(USE_FILE_SYSTEM), 0)
49 LDFLAGS += -s NO_FILESYSTEM=1
50 CPPFLAGS += -DIMGUI_DISABLE_FILE_FUNCTIONS
51 endif
52 ifeq ($(USE_FILE_SYSTEM), 1)
53 LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts
54 endif
55
56 ##---------------------------------------------------------------------
57 ## FINAL BUILD FLAGS
58 ##---------------------------------------------------------------------
59
60 CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
61 #CPPFLAGS += -g
62 CPPFLAGS += -Wall -Wformat -Os $(EMS)
63 #LDFLAGS += --shell-file shell_minimal.html
64 LDFLAGS += $(EMS)
65
66 ##---------------------------------------------------------------------
67 ## BUILD RULES
68 ##---------------------------------------------------------------------
69
70 %.o:%.cpp
71 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
72
73 %.o:$(IMGUI_DIR)/%.cpp
74 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
75
76 %.o:$(IMGUI_DIR)/backends/%.cpp
77 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
78
79 all: $(EXE)
80 @echo Build complete for $(EXE)
81
82 $(WEB_DIR):
83 mkdir $@
84
85 serve: all
86 python3 -m http.server -d $(WEB_DIR)
87
88 $(EXE): $(OBJS) $(WEB_DIR)
89 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
90
91 clean:
92 rm -f $(EXE) $(OBJS) $(WEB_DIR)/*.js $(WEB_DIR)/*.wasm $(WEB_DIR)/*.wasm.pre