How to properly static link webgpu_dawn in my project?

134 views
Skip to first unread message

Arias Han

unread,
Nov 15, 2024, 7:07:04 AM11/15/24
to Dawn Graphics
Hi All,

I found that  dawn's cmake only has a shared version(webgpu_dawn). So how should I connect my program to the static version of webgpu_dawn? 

Best regards,
Arias

Cheng

unread,
Feb 21, 2025, 9:13:45 PMFeb 21
to Dawn Graphics
This reply is probably too late but I'm sharing my solution here. There are some hacks abusing internal build settings and it would be great if someone can share a better way.


# Link with dawn statically.
cmake_policy(SET CMP0097 NEW)  # enable GIT_SUBMODULES
FetchContent_Declare(
  dawn
  GIT_REPOSITORY https://dawn.googlesource.com/dawn
  GIT_TAG "chromium/7012"
  GIT_SHALLOW ON
  GIT_SUBMODULES ""  # no submodules
  UPDATE_DISCONNECTED ON  # no update when re-generating
  EXCLUDE_FROM_ALL)
set(DAWN_FETCH_DEPENDENCIES ON)
set(DAWN_USE_GLFW OFF)
set(DAWN_USE_X11 OFF)
set(DAWN_BUILD_SAMPLES OFF)
set(DAWN_BUILD_MONOLITHIC_LIBRARY OFF)
set(TINT_BUILD_CMD_TOOLS OFF)
set(TINT_BUILD_TESTS OFF)
FetchContent_MakeAvailable(dawn)
target_link_libraries(betann PUBLIC $<BUILD_INTERFACE:dawncpp_headers>
                             PRIVATE $<LINK_ONLY:dawn::dawn_common>
                                     $<LINK_ONLY:dawn::dawn_native>)

# Build the procs that call dawn_native directly.
find_package(Python3 REQUIRED)
DawnJSONGenerator(TARGET "webgpu_dawn_native_proc"
                  PRINT_NAME "Dawn native WebGPU procs"
                  OUTPUT_SOURCES WEBGPU_DAWN_NATIVE_PROC_GEN_SOURCES)
target_sources(betann PRIVATE ${WEBGPU_DAWN_NATIVE_PROC_GEN_SOURCES})
Reply all
Reply to author
Forward
0 new messages