CMakeLists.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Building for desktop (WebGPU-native) with Dawn:
  2. # 1. git clone https://github.com/google/dawn dawn
  3. # 2. cmake -B build -DIMGUI_DAWN_DIR=dawn
  4. # 3. cmake --build build
  5. # The resulting binary will be found at one of the following locations:
  6. # * build/Debug/example_glfw_wgpu[.exe]
  7. # * build/example_glfw_wgpu[.exe]
  8. # Building for Emscripten:
  9. # 1. Install Emscripten SDK following the instructions: https://emscripten.org/docs/getting_started/downloads.html
  10. # 2. Install Ninja build system
  11. # 3. emcmake cmake -G Ninja -B build
  12. # 3. cmake --build build
  13. # 4. emrun build/index.html
  14. cmake_minimum_required(VERSION 3.10.2)
  15. project(imgui_example_glfw_wgpu C CXX)
  16. if(NOT CMAKE_BUILD_TYPE)
  17. set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
  18. endif()
  19. set(CMAKE_CXX_STANDARD 17) # Dawn requires C++17
  20. # Dear ImGui
  21. set(IMGUI_DIR ../../)
  22. # Libraries
  23. if(EMSCRIPTEN)
  24. set(LIBRARIES glfw)
  25. add_compile_options(-sDISABLE_EXCEPTION_CATCHING=1 -DIMGUI_DISABLE_FILE_FUNCTIONS=1)
  26. else()
  27. # Dawn wgpu desktop
  28. set(DAWN_FETCH_DEPENDENCIES ON)
  29. set(IMGUI_DAWN_DIR CACHE PATH "Path to Dawn repository")
  30. if (NOT IMGUI_DAWN_DIR)
  31. message(FATAL_ERROR "Please specify the Dawn repository by setting IMGUI_DAWN_DIR")
  32. endif()
  33. option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON)
  34. # Dawn builds many things by default - disable things we don't need
  35. option(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" OFF)
  36. option(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" OFF)
  37. option(TINT_BUILD_DOCS "Build documentation" OFF)
  38. option(TINT_BUILD_TESTS "Build tests" OFF)
  39. if (NOT APPLE)
  40. option(TINT_BUILD_MSL_WRITER "Build the MSL output writer" OFF)
  41. endif()
  42. if(WIN32)
  43. option(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" OFF)
  44. option(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
  45. option(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" OFF)
  46. option(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" OFF)
  47. option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" OFF)
  48. option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
  49. endif()
  50. add_subdirectory("${IMGUI_DAWN_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/dawn" EXCLUDE_FROM_ALL)
  51. set(LIBRARIES webgpu_dawn webgpu_cpp webgpu_glfw glfw)
  52. endif()
  53. add_executable(example_glfw_wgpu
  54. main.cpp
  55. # backend files
  56. ${IMGUI_DIR}/backends/imgui_impl_glfw.cpp
  57. ${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp
  58. # Dear ImGui files
  59. ${IMGUI_DIR}/imgui.cpp
  60. ${IMGUI_DIR}/imgui_draw.cpp
  61. ${IMGUI_DIR}/imgui_demo.cpp
  62. ${IMGUI_DIR}/imgui_tables.cpp
  63. ${IMGUI_DIR}/imgui_widgets.cpp
  64. )
  65. target_include_directories(example_glfw_wgpu PUBLIC
  66. ${IMGUI_DIR}
  67. ${IMGUI_DIR}/backends
  68. )
  69. target_link_libraries(example_glfw_wgpu PUBLIC ${LIBRARIES})
  70. # Emscripten settings
  71. if(EMSCRIPTEN)
  72. target_link_options(example_glfw_wgpu PRIVATE
  73. "-sUSE_WEBGPU=1"
  74. "-sUSE_GLFW=3"
  75. "-sWASM=1"
  76. "-sALLOW_MEMORY_GROWTH=1"
  77. "-sNO_EXIT_RUNTIME=0"
  78. "-sASSERTIONS=1"
  79. "-sDISABLE_EXCEPTION_CATCHING=1"
  80. "-sNO_FILESYSTEM=1"
  81. )
  82. set_target_properties(example_glfw_wgpu PROPERTIES OUTPUT_NAME "index")
  83. # copy our custom index.html to build directory
  84. add_custom_command(TARGET example_glfw_wgpu POST_BUILD
  85. COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_LIST_DIR}/web/index.html" $<TARGET_FILE_DIR:example_glfw_wgpu>
  86. )
  87. endif()