The project, WebGPU-Distribution (GitHub - eliemichel/WebGPU-distribution: Distributions of WebGPU for native and web development, easy to integrate and interchangeable.), is designed to be used in your project via add_subdirectory. The “main” branch conditionally selects a more specific branch of the same repository to download via FetchContent, based on whether the build is Emscripten or not and whether you want wgpu or Dawn implementation on native. That fetched content in turn may download a pre-compiled wgpu distribution. (I am using wgpu for native and Emscripten for web.)
The batteries-included / one-touch method the project author designed works well for the tutorial of which that project is a component, however I organize my development environment differently. To avoid duplication of large game engine dependency libraries and to enforce a uniform standard, I install all of the dependencies of my projects to a common prefix directory, and use find_package to get them. Whenever a 3rd party library does not support this, I fork it and add that install code myself.
I think I understand the basic steps of adding CMake install code, and this has worked for me for several dependencies so far. In my own words:
-
Change
target_include_directories
to use generator expressions. -
List the header files in a variable and pass that to
install(FILES ...)
. -
Add
install(TARGETS ...)
for each target with exports and install destination. -
Generate config files and pass that to
install(FILES ...)
. -
Use
install(EXPORT ...)
to install exports created during step three.
However when I got to WebGPU-Distribution, I couldn’t figure out how to adapt these steps to the way that project works. (I invite you to simply read the cmake file I’m talking about that I couldn’t figure out how to add install code to; it’s not very long: https://github.com/eliemichel/WebGPU-distribution/blob/main/webgpu.cmake).
Should I write code in the main branch of (my fork of) the WebGPU-Distribution project that reaches into ${CMAKE_CURRENT_BINARY_DIR} to hoist the downloaded wgpu DLLs with install(FILES …) into my common install directory? Should I add install code to each non-main branch (but then how do I kick off the install from main?) Should I convert the project from using FetchContent to use ExternalProject instead? Should I “git clone” each branch as a separate top-level folder (in my projects folder) and manually install each for just the one target configuration each applies to?