2024-03-24 21:18:10 +08:00
# Building for desktop (WebGPU-native) with Dawn:
2024-04-16 18:08:45 +08:00
# 1. git clone https://github.com/google/dawn dawn
# 2. cmake -B build -DIMGUI_DAWN_DIR=dawn
# 3. cmake --build build
2024-03-24 21:18:10 +08:00
# The resulting binary will be found at one of the following locations:
2024-04-16 19:51:03 +08:00
# * build/Debug/example_glfw_wgpu[.exe]
# * build/example_glfw_wgpu[.exe]
2024-03-24 21:18:10 +08:00
# Building for Emscripten:
# 1. Install Emscripten SDK following the instructions: https://emscripten.org/docs/getting_started/downloads.html
# 2. Install Ninja build system
# 3. emcmake cmake -G Ninja -B build
# 3. cmake --build build
# 4. emrun build/index.html
cmake_minimum_required ( VERSION 3.10.2 )
2024-04-16 19:51:03 +08:00
project ( imgui_example_glfw_wgpu C CXX )
2024-03-24 21:18:10 +08:00
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE )
endif ( )
set ( CMAKE_CXX_STANDARD 17 ) # Dawn requires C++17
# Dear ImGui
set ( IMGUI_DIR ../../ )
# Libraries
if ( EMSCRIPTEN )
2024-07-09 04:04:27 +08:00
if ( EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "3.1.57" )
set ( IMGUI_EMSCRIPTEN_GLFW3 "--use-port=contrib.glfw3" CACHE STRING "Choose between --use-port=contrib.glfw3 and -sUSE_GLFW=3 for GLFW implementation (default to --use-port=contrib.glfw3)" )
else ( )
# cannot use contrib.glfw3 prior to 3.1.57
set ( IMGUI_EMSCRIPTEN_GLFW3 "-sUSE_GLFW=3" CACHE STRING "Use -sUSE_GLFW=3 for GLFW implementation" FORCE )
endif ( )
2024-03-24 21:18:10 +08:00
set ( LIBRARIES glfw )
add_compile_options ( -sDISABLE_EXCEPTION_CATCHING=1 -DIMGUI_DISABLE_FILE_FUNCTIONS=1 )
else ( )
# Dawn wgpu desktop
set ( DAWN_FETCH_DEPENDENCIES ON )
set ( IMGUI_DAWN_DIR CACHE PATH "Path to Dawn repository" )
if ( NOT IMGUI_DAWN_DIR )
message ( FATAL_ERROR "Please specify the Dawn repository by setting IMGUI_DAWN_DIR" )
endif ( )
2024-04-16 18:08:45 +08:00
2024-03-24 21:18:10 +08:00
option ( DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON )
2024-04-16 18:08:45 +08:00
2024-03-24 21:18:10 +08:00
# Dawn builds many things by default - disable things we don't need
option ( DAWN_BUILD_SAMPLES "Enables building Dawn's samples" OFF )
option ( TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" OFF )
option ( TINT_BUILD_DOCS "Build documentation" OFF )
option ( TINT_BUILD_TESTS "Build tests" OFF )
if ( NOT APPLE )
option ( TINT_BUILD_MSL_WRITER "Build the MSL output writer" OFF )
endif ( )
if ( WIN32 )
option ( TINT_BUILD_SPV_READER "Build the SPIR-V input reader" OFF )
option ( TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON )
option ( TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" OFF )
option ( TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" OFF )
option ( TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" OFF )
option ( TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON )
endif ( )
2024-04-16 18:08:45 +08:00
2024-03-24 21:18:10 +08:00
add_subdirectory ( "${IMGUI_DAWN_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/dawn" EXCLUDE_FROM_ALL )
2024-04-16 18:08:45 +08:00
2024-03-24 21:18:10 +08:00
set ( LIBRARIES webgpu_dawn webgpu_cpp webgpu_glfw glfw )
endif ( )
2024-04-16 19:51:03 +08:00
add_executable ( example_glfw_wgpu
2024-03-24 21:18:10 +08:00
m a i n . c p p
# backend files
$ { I M G U I _ D I R } / b a c k e n d s / i m g u i _ i m p l _ g l f w . c p p
$ { I M G U I _ D I R } / b a c k e n d s / i m g u i _ i m p l _ w g p u . c p p
# Dear ImGui files
$ { I M G U I _ D I R } / i m g u i . c p p
$ { I M G U I _ D I R } / i m g u i _ d r a w . c p p
$ { I M G U I _ D I R } / i m g u i _ d e m o . c p p
$ { I M G U I _ D I R } / i m g u i _ t a b l e s . c p p
$ { I M G U I _ D I R } / i m g u i _ w i d g e t s . c p p
)
2024-04-16 19:51:03 +08:00
target_include_directories ( example_glfw_wgpu PUBLIC
2024-03-24 21:18:10 +08:00
$ { I M G U I _ D I R }
$ { I M G U I _ D I R } / b a c k e n d s
)
2024-04-16 19:51:03 +08:00
target_link_libraries ( example_glfw_wgpu PUBLIC ${ LIBRARIES } )
2024-03-24 21:18:10 +08:00
# Emscripten settings
if ( EMSCRIPTEN )
2024-07-09 04:04:27 +08:00
if ( "${IMGUI_EMSCRIPTEN_GLFW3}" STREQUAL "--use-port=contrib.glfw3" )
target_compile_options ( example_glfw_wgpu PUBLIC
" $ { I M G U I _ E M S C R I P T E N _ G L F W 3 } "
)
endif ( )
message ( STATUS "Using ${IMGUI_EMSCRIPTEN_GLFW3} GLFW implementation" )
2024-04-16 19:51:03 +08:00
target_link_options ( example_glfw_wgpu PRIVATE
2024-03-24 21:18:10 +08:00
" - s U S E _ W E B G P U = 1 "
2024-07-09 04:04:27 +08:00
" $ { I M G U I _ E M S C R I P T E N _ G L F W 3 } "
2024-03-24 21:18:10 +08:00
" - s W A S M = 1 "
" - s A L L O W _ M E M O R Y _ G R O W T H = 1 "
" - s N O _ E X I T _ R U N T I M E = 0 "
" - s A S S E R T I O N S = 1 "
" - s D I S A B L E _ E X C E P T I O N _ C A T C H I N G = 1 "
" - s N O _ F I L E S Y S T E M = 1 "
)
2024-04-16 19:51:03 +08:00
set_target_properties ( example_glfw_wgpu PROPERTIES OUTPUT_NAME "index" )
2024-03-24 21:18:10 +08:00
# copy our custom index.html to build directory
2024-04-16 19:51:03 +08:00
add_custom_command ( TARGET example_glfw_wgpu POST_BUILD
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t " $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / w e b / i n d e x . h t m l " $ < T A R G E T _ F I L E _ D I R : e x a m p l e _ g l f w _ w g p u >
2024-03-24 21:18:10 +08:00
)
endif ( )