Hello everyone!
As the title says, I'm trying to find a way to integrate Dawn into my CMake project. There's a couple of reasons why:
1. Dawn is not packaged in vcpkg or Conan, which are the two most popular C++ package managers
2. Dawn own CMake scripts don't export its targets and has no installation scripts, making it impossible to simply install the libs and find them
3. Dawn has many dependencies, and without exported targets a CMake script has to find all the link dependencies of Dawn and manually link them
My solution was to use Dawn with add_subdirectory or FetchContent, since I would have access to Dawn's CMake targets which allows a much simpler integration into my project.
On MacOS it was quite easy, I simply had to trick Dawn's CMake script to think all dependencies are present and disable Vulkan build. On linux on the other hand, I have to enable vulkan and my trick don't seem to work just as well.
Here's how I integrated Dawn into my buildsystem. I start with a Finddawn.cmake file:
if(NOT dawn_POPULATED)
# I don't want to run the tests
set(TINT_BUILD_TESTS OFF CACHE BOOL INTERNAL)
set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS OFF CACHE STRING INTERNAL)
# I'll only use wgsl
set(TINT_BUILD_SPV_READER OFF CACHE BOOL INTERNAL)
# I want to statically link
set(BUILD_SHARED_LIBS OFF CACHE STRING INTERNAL)
# No need to build samples to use dawn
set(BUILD_SAMPLES OFF CACHE BOOL INTERNAL)
# dawn dependencies
find_package(glslang CONFIG REQUIRED)
find_package(SPIRV-Tools REQUIRED)
find_package(SPIRV-Tools-opt CONFIG REQUIRED)
add_library(SPIRV-Tools ALIAS SPIRV-Tools-static)
find_path(SPIRV_HEADERS_INCLUDE_DIRS "spirv/1.0/GLSL.std.450.h")
add_library(SPIRV-Headers INTERFACE IMPORTED GLOBAL)
target_include_directories(SPIRV-Headers INTERFACE "${SPIRV_HEADERS_INCLUDE_DIRS}")
find_path(VULKAN_HEADERS_INCLUDE_DIRS "vk_video/vulkan_video_codec_h264std.h")
add_library(Vulkan-Headers INTERFACE IMPORTED GLOBAL)
target_include_directories(Vulkan-Headers INTERFACE "${VULKAN_HEADERS_INCLUDE_DIRS}")
find_package(absl CONFIG REQUIRED)
add_library(libabsl ALIAS absl::strings)
add_library(absl_strings ALIAS absl::strings)
add_library(absl_str_format_internal ALIAS absl::str_format_internal)
set(multiValueArgs "")
FetchContent_MakeAvailable(dawn)
unset(multiValueArgs)
endif()
set(dawn_FOUND TRUE)
I have the dependencies fetched using vcpkg:
{
"name": "my-project",
"version-string": "0.1.0",
"dependencies": [
{
"name": "glfw3",
"platform": "!wasm32"
},
{
"name": "abseil",
"platform": "!wasm32"
},
{
"name": "glslang",
"platform": "!wasm32"
},
{
"name": "spirv-cross",
"platform": "!wasm32"
},
{
"name": "spirv-headers",
"platform": "!wasm32"
},
{
"name": "spirv-tools",
"platform": "!wasm32"
},
{
"name": "vulkan-headers",
"platform": "!wasm32"
}
]
}
Have this FetchContent command somewhere in my scripts:
Then finally, find the package and link to it:
find_package(dawn REQUIRED)
target_link_libraries(my-executable PRIVATE
glfw
dawn_utils
dawn_internal_config
dawn_native
dawn_proc
dawncpp
)
This trick worked pretty well on MacOS, but on linux I'm not sure how to adapt my Finddawn.cmake so that it works with dawn? Is there any other way I can integrate dawn into my project? What is the recommended way to statically link dawn to an executable? I haven't found any documented ways to actually use it.
I can provide any other information if needed. I can create a sample project too if that's what you need to help me. Thank you for your help.