@@ -29,12 +29,39 @@ project(spinning_triangle LANGUAGES C CXX)
2929# Dawn → webgpu_dawn
3030# ---------------------------------------------------------------------------
3131set (WGPU_PATH "" CACHE PATH "Root of the WebGPU native installation (contains include/ and lib/)" )
32- set (WGPU_LIB "webgpu_dawn " CACHE STRING "WebGPU library name (wgpu_native or webgpu_dawn)" )
32+ set (WGPU_LIB "" CACHE STRING "WebGPU library name (wgpu_native or webgpu_dawn); auto-detected if empty " )
3333
3434if (NOT WGPU_PATH)
3535 message (FATAL_ERROR "Set WGPU_PATH to the root of your WebGPU native installation." )
3636endif ()
3737
38+ # When WGPU_PATH changes, discard any previously auto-detected WGPU_LIB so
39+ # detection re-runs against the new path.
40+ if (NOT "${WGPU_PATH} " STREQUAL "${_WGPU_PATH_LAST} " AND _WGPU_LIB_AUTO)
41+ unset (WGPU_LIB CACHE )
42+ set (WGPU_LIB "" CACHE STRING "WebGPU library name (wgpu_native or webgpu_dawn); auto-detected if empty" )
43+ endif ()
44+ set (_WGPU_PATH_LAST "${WGPU_PATH} " CACHE INTERNAL "" )
45+
46+ if (NOT WGPU_LIB)
47+ # Always unset the find_library results so they re-probe the current WGPU_PATH.
48+ unset (_WGPU_NATIVE_LIB CACHE )
49+ unset (_WEBGPU_DAWN_LIB CACHE )
50+ find_library (_WGPU_NATIVE_LIB NAMES wgpu_native wgpu_native.dll PATHS "${WGPU_PATH} /lib" NO_DEFAULT_PATH )
51+ find_library (_WEBGPU_DAWN_LIB NAMES webgpu_dawn PATHS "${WGPU_PATH} /lib" NO_DEFAULT_PATH )
52+ if (_WGPU_NATIVE_LIB)
53+ set (WGPU_LIB "wgpu_native" CACHE STRING "WebGPU library name (wgpu_native or webgpu_dawn); auto-detected if empty" FORCE )
54+ elseif (_WEBGPU_DAWN_LIB)
55+ set (WGPU_LIB "webgpu_dawn" CACHE STRING "WebGPU library name (wgpu_native or webgpu_dawn); auto-detected if empty" FORCE )
56+ else ()
57+ message (FATAL_ERROR "Could not detect a WebGPU library in ${WGPU_PATH} /lib. Set WGPU_LIB explicitly (wgpu_native or webgpu_dawn)." )
58+ endif ()
59+ set (_WGPU_LIB_AUTO TRUE CACHE INTERNAL "" )
60+ message (STATUS "WebGPU library auto-detected: ${WGPU_LIB} " )
61+ else ()
62+ set (_WGPU_LIB_AUTO FALSE CACHE INTERNAL "" )
63+ endif ()
64+
3865# ---------------------------------------------------------------------------
3966# Tracy root — defaults to two directories above this CMakeLists.txt.
4067# ---------------------------------------------------------------------------
0 commit comments