7.8 KB、163行 表示 生 Blame 履歴
1## How to Build
2
3
4---
5
6### Using CMake
7#### Building for desktop (WebGPU-native) with Google Dawn:
8 1. `git clone https://github.com/google/dawn dawn`
9 2. `cmake -B build -DIMGUI_DAWN_DIR=dawn`
10 3. `cmake --build build`
11The resulting binary will be found at one of the following locations:
12 * build/Debug/example_sdl2_wgpu[.exe]
13 * build/example_sdl2_wgpu[.exe]
14
15#### Building for desktop (WebGPU-Native) with WGPU:
16 1. download WGPU-Native autogenerated binary modules for your platform/compiler from: https://github.com/gfx-rs/wgpu-native/releases
17 2. unzip the downloaded file in `your_preferred_folder`
18 3. `cmake -B build -DIMGUI_WGPU_DIR=your_preferred_folder` ("full path" or "relative" starting from current directory)
19 4. `cmake --build build`
20The resulting binary will be found at one of the following locations:
21 * build/Debug/example_sdl2_wgpu[.exe]
22 * build/example_sdl2_wgpu[.exe]
23
24#### Building for Emscripten:
25 1. Install Emscripten SDK following the instructions: https://emscripten.org/docs/getting_started/downloads.html
26 2. Install Ninja build system
27 3. `emcmake cmake -G Ninja -B build`
28 - (optional) `-DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path/to/emdawnwebgpu_package/emdawnwebgpu.port.py"`, see below
29 4. `cmake --build build`
30
31#### Sync Emscripten with latest Google Dawn:
32If you want to sync Emscripten with latest DAWN release it's necessary to download the `port-emdawnwgpu-package` (released daily by Google) here:
33https://github.com/google/dawn/releases
34Unpack it in your preferred folder and to replace the step 3 with:
35
363. `emcmake cmake -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path/to/emdawnwebgpu_package/emdawnwebgpu.port.py" -G Ninja -B build`
37
38**N.B.**
39For the WASM code produced by Emscripten to work correctly, it will also be necessary to have the "corresponding" (or newer) version of Google Canary (nightly build for developers) that includes the latest changes
40
41
42---
43
44### CMake by step
45
46#### Generate Dawn Native:
47
48- `cmake -G Ninja -DIMGUI_DAWN_DIR=path_to_sdk_dir -B where_to_build_dir`
49 - Using `IMGUI_DAWN_DIR` set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
50
51#### Generate WGPU Native:
52
53- `cmake -G Ninja -DIMGUI_WGPU_DIR=path_to_sdk_dir -B where_to_build_dir`
54
55 - Using `IMGUI_WGPU_DIR` set `IMGUI_IMPL_WEBGPU_BACKEND_WGPU` compiler define
56
57#### Generate Emscripten:
58
59- `emcmake cmake -G Ninja -B where_to_build_dir`\
60CMake checks the EMSCRIPEN version then:
61 - if EMS >= 4.0.10 uses `--use-port=emdawnwebgpu` flag to build
62 - it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
63 - if EMS < 4.0.10 the build aborts (`-sUSE_WEBGPU=1` is no longer supported by our examples and our WGPU backend)
64
65#### Generate Emscripten using external WebGPU library (emdawnwebgpu_pkg)
66
67- `emcmake cmake -G Ninja -DIMGUI_EMSCRIPTEN_WEBGPU_FLAG="--use-port=path_to_emdawnwebgpu_pkg" -B where_to_build_dir`
68 - it set `IMGUI_IMPL_WEBGPU_BACKEND_DAWN` compiler define
69 - *To use external WebGPU library it's necessary to have EMS >= 4.0.10 or the minimum requirements specified by the package:*
70 - https://github.com/google/dawn/releases
71
72#### Build time
73
74Once the procedure for the specific builder is generated, the build command is **always the same**:
75
76- Build using CMake
77 - `cmake --build where_to_build_dir`
78 - It will use selected builder to build the example.
79
80- Build explicitly:
81 - `cd where_to_build_dir`
82 - `ninja`
83 - This is the builder chosen during the generation phase
84
85---
86
87### CMake useful options
88#### Generator types (alternative to **ninja** builder):
89- `-G Ninja` to build with __ninja__ builder
90- `-G "Unix Makefiles"` to build with __make__ builder
91- `-G "Visual Studio 17 2022" -A x64` to create a VS 2022 solution (.sln) file, Windows only
92 - **Native build only**
93 - Not **officially** supported to build Google Dawn
94
95Example:
96- using **make** instead **ninja**:
97 - `cmake -G "Unix Makefiles" -DIMGUI_DAWN_DIR=path_to_sdk_dir -B where_to_build_dir`
98
99**Syntax is case sensitive and the "" are necessary in case of spaces between words*
100
101#### Directories
102- The directory path can be absolute or relative (starting from the current directory)
103- It's necessary to use different `where_to_build_dir` for different CMake generations
104
105
106#### Build type
107The default build type is **Debug**
108It is possible to use a different build type using:
109- `-DCMAKE_BUILD_TYPE=Release`
110- `-DCMAKE_BUILD_TYPE=MinSizeRel`
111- `-DCMAKE_BUILD_TYPE=RelWithDebInfo`
112
113Example:
114- building **Release**:
115 - `cmake -G ninja -DIMGUI_WGPU_DIR=path_to_sdk_dir -DCMAKE_BUILD_TYPE=Release -B where_to_build_dir `
116
117#### GLFW / SDL2 / SDL3 includes, libraries, search paths and package manager
118
119Includes and libraries, by default, are searched in system/compiler paths (environment variables): you can add the path to your development tools to the environment variables without having to modify the `CMakeLists.txt` file.
120- e.g. CLang search in path specified from the following environment variables:
121 - include files: CPATH, C_INCLUDE_PATH, CPLUS_INCLUDE_PATH
122 - library files: LIBRARY_PATH
123
124If you are using a package manager (**vcpkg** / **conan** / ... ) you need/can to specify it, adding to cmake command:
125- `-DCMAKE_TOOLCHAIN_FILE=path/to/package_manager.cmake`
126
127Examples:
128
129- using **vcpkg** package manager it's necessary adding:
130 - `-DCMAKE_TOOLCHAIN_FILE=<vcpkg_root_dir>/scripts/buildsystems/vcpkg.cmake`
131
132- full cmake command using **vcpkg** package manager:
133 - `cmake -G Ninja -DIMGUI_DAWN_DIR=path_to_sdk_dir -DCMAKE_TOOLCHAIN_FILE=<vcpkg_root_dir>/scripts/buildsystems/vcpkg.cmake -B where_to_build_dir`
134
135---
136
137
138### Using makefile
139
140- You need to install Emscripten from https://emscripten.org/docs/getting_started/downloads.html, and have the environment variables set, as described in https://emscripten.org/docs/getting_started/downloads.html#installation-instructions
141
142- Depending on your configuration, in Windows you may need to run `emsdk/emsdk_env.bat` in your console to access the Emscripten command-line tools.
143
144- You may also refer to our [Continuous Integration setup](https://github.com/ocornut/imgui/tree/master/.github/workflows) for Emscripten setup.
145
146- Then build using `make -f Makefile.emscripten` while in the `example_glfw_wgpu/` directory.
147
148- Requires recent Emscripten as WGPU is still a work-in-progress API.
149
150---
151
152## How to Run
153
154To run on a local machine:
155- Make sure your browse supports WGPU and it is enabled. WGPU is still WIP not enabled by default in most browser.
156- `make serve` will use Python3 to spawn a local webserver, you can then browse http://localhost:8000 to access your build.
157- Otherwise, generally you will need a local webserver:
158 - Quoting [https://emscripten.org/docs/getting_started](https://emscripten.org/docs/getting_started/Tutorial.html#generating-html):<br>
159_"Unfortunately several browsers (including Chrome, Safari, and Internet Explorer) do not support file:// [XHR](https://emscripten.org/docs/site/glossary.html#term-xhr) requests, and can’t load extra files needed by the HTML (like a .wasm file, or packaged file data as mentioned lower down). For these browsers you’ll need to serve the files using a [local webserver](https://emscripten.org/docs/getting_started/FAQ.html#faq-local-webserver) and then open http://localhost:8000/hello.html."_
160 - Emscripten SDK has a handy `emrun` command: `emrun web/example_glfw_wgpu.html --browser firefox` which will spawn a temporary local webserver (in Firefox). See https://emscripten.org/docs/compiling/Running-html-files-with-emrun.html for details.
161 - You may use Python 3 builtin webserver: `python -m http.server -d web` (this is what `make serve` uses).
162 - You may use Python 2 builtin webserver: `cd web && python -m SimpleHTTPServer`.
163 - If you are accessing the files over a network, certain browsers, such as Firefox, will restrict Gamepad API access to secure contexts only (e.g. https only).