# This file is part of the "Learn WebGPU for C++" book. # https://eliemichel.github.io/LearnWebGPU # # MIT License # Copyright (c) 2022-2024 Elie Michel and the wgpu-native authors # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. include(FetchContent) set(WEBGPU_BACKEND "WGPU_STATIC" CACHE STRING "Backend implementation of WebGPU. Possible values are EMSCRIPTEN, WGPU, WGPU_STATIC and DAWN (it does not matter when using emcmake)") # FetchContent's GIT_SHALLOW option is buggy and does not actually do a shallow # clone. This macro takes care of it. macro(FetchContent_DeclareShallowGit Name GIT_REPOSITORY GitRepository GIT_TAG GitTag) FetchContent_Declare( "${Name}" # This is what it'd look line if GIT_SHALLOW was indeed working: #GIT_REPOSITORY "${GitRepository}" #GIT_TAG "${GitTag}" #GIT_SHALLOW ON # Manual download mode instead: DOWNLOAD_COMMAND cd "${FETCHCONTENT_BASE_DIR}/${Name}-src" && git init && git fetch --depth=1 "${GitRepository}" "${GitTag}" && git reset --hard FETCH_HEAD ) endmacro() if (NOT TARGET webgpu) string(TOUPPER ${WEBGPU_BACKEND} WEBGPU_BACKEND_U) if (EMSCRIPTEN OR WEBGPU_BACKEND_U STREQUAL "EMSCRIPTEN") FetchContent_DeclareShallowGit( webgpu-backend-emscripten GIT_REPOSITORY https://github.com/eliemichel/WebGPU-distribution GIT_TAG e0038567ca1e35ffa9a848760eb6c49450264305 # emscripten-v3.1.61 + fix ) FetchContent_MakeAvailable(webgpu-backend-emscripten) elseif (WEBGPU_BACKEND_U STREQUAL "WGPU") FetchContent_DeclareShallowGit( webgpu-backend-wgpu GIT_REPOSITORY https://github.com/eliemichel/WebGPU-distribution GIT_TAG ac055bef9d8c37f28e7706e4bd32153cbc0c210f # wgpu-v0.19.4.1 + fix ) FetchContent_MakeAvailable(webgpu-backend-wgpu) elseif (WEBGPU_BACKEND_U STREQUAL "WGPU_STATIC") FetchContent_DeclareShallowGit( webgpu-backend-wgpu-static GIT_REPOSITORY https://github.com/eliemichel/WebGPU-distribution GIT_TAG 3612311d4df171027513a3ad5dcd8a77d93c447f # wgpu-static-v0.19.4.1 + fix ) FetchContent_MakeAvailable(webgpu-backend-wgpu-static) elseif (WEBGPU_BACKEND_U STREQUAL "DAWN") FetchContent_DeclareShallowGit( webgpu-backend-dawn GIT_REPOSITORY https://github.com/eliemichel/WebGPU-distribution GIT_TAG b3082d247df326c2e2dd1c64d5a148bc3cf1167f # dawn-6512 + emscripten-v3.1.61 + fix ) FetchContent_MakeAvailable(webgpu-backend-dawn) else() message(FATAL_ERROR "Invalid value for WEBGPU_BACKEND: possible values are EMSCRIPTEN, WGPU, WGPU_STATIC and DAWN, but '${WEBGPU_BACKEND_U}' was provided.") endif() endif()