2020-02-05 17:16:05 +00:00
|
|
|
# Copyright 2020 The Dawn Authors
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.10)
|
|
|
|
|
|
|
|
# When upgrading to CMake 3.11 we can remove DAWN_DUMMY_FILE because source-less add_library
|
|
|
|
# becomes available.
|
|
|
|
# When upgrading to CMake 3.12 we should add CONFIGURE_DEPENDS to DawnGenerator to rerun CMake in
|
2020-04-10 17:04:31 +00:00
|
|
|
# case any of the generator files changes. We should also remove the CACHE "" FORCE stuff to
|
2020-10-20 19:46:21 +00:00
|
|
|
# override options in third_party dependencies. We can also add the HOMEPAGE_URL
|
|
|
|
# entry to the project `HOMEPAGE_URL "https://dawn.googlesource.com/dawn"`
|
2020-02-05 17:16:05 +00:00
|
|
|
|
|
|
|
project(
|
|
|
|
Dawn
|
|
|
|
DESCRIPTION "Dawn, a WebGPU implementation"
|
|
|
|
LANGUAGES C CXX
|
|
|
|
)
|
|
|
|
|
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
|
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
message(WARNING "CMAKE_BUILD_TYPE not set, forcing it to Debug")
|
|
|
|
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
|
|
|
|
"Build type (Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen")
|
|
|
|
set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator")
|
|
|
|
set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src")
|
2022-02-04 18:18:18 +00:00
|
|
|
set(DAWN_INCLUDE_DIR "${Dawn_SOURCE_DIR}/include")
|
2020-02-05 17:16:05 +00:00
|
|
|
set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates")
|
|
|
|
|
|
|
|
set(DAWN_DUMMY_FILE "${DAWN_SRC_DIR}/Dummy.cpp")
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Configuration options
|
|
|
|
################################################################################
|
|
|
|
|
2021-09-24 10:38:18 +00:00
|
|
|
# option_if_not_defined(name description default)
|
|
|
|
# Behaves like:
|
|
|
|
# option(name description default)
|
|
|
|
# If a variable is not already defined with the given name, otherwise the
|
|
|
|
# function does nothing.
|
|
|
|
# Simplifies customization by projects that use Dawn as a dependency.
|
|
|
|
function (option_if_not_defined name description default)
|
|
|
|
if(NOT DEFINED ${name})
|
|
|
|
option(${name} ${description} ${default})
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# set_if_not_defined(name value description)
|
|
|
|
# Behaves like:
|
|
|
|
# set(${name} ${value} CACHE STRING ${description})
|
|
|
|
# If a variable is not already defined with the given name, otherwise the
|
|
|
|
# function does nothing.
|
|
|
|
# Simplifies customization by projects that use Dawn as a dependency.
|
|
|
|
function (set_if_not_defined name value description)
|
|
|
|
if(NOT DEFINED ${name})
|
|
|
|
set(${name} ${value} CACHE STRING ${description})
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2020-02-05 17:16:05 +00:00
|
|
|
# Default values for the backend-enabling options
|
|
|
|
set(ENABLE_D3D12 OFF)
|
|
|
|
set(ENABLE_METAL OFF)
|
2021-06-30 15:06:43 +00:00
|
|
|
set(ENABLE_OPENGLES OFF)
|
|
|
|
set(ENABLE_DESKTOP_GL OFF)
|
2020-02-05 17:16:05 +00:00
|
|
|
set(ENABLE_VULKAN OFF)
|
2020-02-18 02:12:35 +00:00
|
|
|
set(USE_X11 OFF)
|
2022-02-04 18:35:55 +00:00
|
|
|
set(BUILD_SAMPLES OFF)
|
2020-02-05 17:16:05 +00:00
|
|
|
if (WIN32)
|
|
|
|
set(ENABLE_D3D12 ON)
|
2021-06-28 08:19:28 +00:00
|
|
|
if (NOT WINDOWS_STORE)
|
2021-06-24 07:00:16 +00:00
|
|
|
# Enable Vulkan in win32 compilation only
|
|
|
|
# since UWP only supports d3d
|
|
|
|
set(ENABLE_VULKAN ON)
|
|
|
|
endif()
|
2020-02-05 17:16:05 +00:00
|
|
|
elseif(APPLE)
|
|
|
|
set(ENABLE_METAL ON)
|
2022-03-25 13:18:46 +00:00
|
|
|
elseif(ANDROID)
|
|
|
|
set(ENABLE_VULKAN ON)
|
|
|
|
set(ENABLE_OPENGLES ON)
|
2020-02-05 17:16:05 +00:00
|
|
|
elseif(UNIX)
|
2021-06-30 15:06:43 +00:00
|
|
|
set(ENABLE_OPENGLES ON)
|
|
|
|
set(ENABLE_DESKTOP_GL ON)
|
2020-02-05 17:16:05 +00:00
|
|
|
set(ENABLE_VULKAN ON)
|
2020-02-18 02:12:35 +00:00
|
|
|
set(USE_X11 ON)
|
2020-02-05 17:16:05 +00:00
|
|
|
endif()
|
|
|
|
|
2021-06-24 07:00:16 +00:00
|
|
|
# GLFW is not supported in UWP
|
2022-03-25 13:18:46 +00:00
|
|
|
if((WIN32 AND NOT WINDOWS_STORE) OR UNIX AND NOT ANDROID)
|
2021-06-24 07:00:16 +00:00
|
|
|
set(DAWN_SUPPORTS_GLFW_FOR_WINDOWING ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Current examples are depend on GLFW
|
|
|
|
if (DAWN_SUPPORTS_GLFW_FOR_WINDOWING)
|
2022-02-04 18:35:55 +00:00
|
|
|
set(BUILD_SAMPLES ON)
|
2021-06-24 07:00:16 +00:00
|
|
|
endif()
|
|
|
|
|
2021-09-24 10:38:18 +00:00
|
|
|
option_if_not_defined(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
|
|
|
|
option_if_not_defined(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
|
|
|
|
option_if_not_defined(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
|
|
|
|
option_if_not_defined(DAWN_ENABLE_DESKTOP_GL "Enable compilation of the OpenGL backend" ${ENABLE_DESKTOP_GL})
|
|
|
|
option_if_not_defined(DAWN_ENABLE_OPENGLES "Enable compilation of the OpenGL ES backend" ${ENABLE_OPENGLES})
|
|
|
|
option_if_not_defined(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
|
|
|
|
option_if_not_defined(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
|
|
|
|
option_if_not_defined(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
|
2020-02-05 17:16:05 +00:00
|
|
|
|
2022-02-04 18:35:55 +00:00
|
|
|
option_if_not_defined(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" ${BUILD_SAMPLES})
|
2021-09-28 11:14:42 +00:00
|
|
|
option_if_not_defined(DAWN_BUILD_NODE_BINDINGS "Enables building Dawn's NodeJS bindings" OFF)
|
|
|
|
|
|
|
|
option_if_not_defined(DAWN_ENABLE_PIC "Build with Position-Independent-Code enabled" OFF)
|
2020-02-05 17:16:05 +00:00
|
|
|
|
2021-09-24 10:38:18 +00:00
|
|
|
set_if_not_defined(DAWN_THIRD_PARTY_DIR "${Dawn_SOURCE_DIR}/third_party" "Directory in which to find third-party dependencies.")
|
2020-10-20 14:26:10 +00:00
|
|
|
|
2021-09-23 20:36:03 +00:00
|
|
|
# Recommended setting for compability with future abseil releases.
|
|
|
|
set(ABSL_PROPAGATE_CXX_STD ON)
|
2021-09-24 10:38:18 +00:00
|
|
|
|
|
|
|
set_if_not_defined(DAWN_ABSEIL_DIR "${DAWN_THIRD_PARTY_DIR}/abseil-cpp" "Directory in which to find Abseil")
|
|
|
|
set_if_not_defined(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW")
|
|
|
|
set_if_not_defined(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" "Directory in which to find Jinja2")
|
|
|
|
set_if_not_defined(DAWN_SPIRV_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-headers/src" "Directory in which to find SPIRV-Headers")
|
|
|
|
set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-tools/src" "Directory in which to find SPIRV-Tools")
|
|
|
|
set_if_not_defined(DAWN_TINT_DIR "${DAWN_THIRD_PARTY_DIR}/tint" "Directory in which to find Tint")
|
2022-04-02 03:02:40 +00:00
|
|
|
set_if_not_defined(DAWN_VULKAN_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/vulkan-headers/src" "Directory in which to find Vulkan-Headers")
|
2020-02-05 17:16:05 +00:00
|
|
|
|
2021-09-28 11:14:42 +00:00
|
|
|
# Dependencies for DAWN_BUILD_NODE_BINDINGS
|
|
|
|
set_if_not_defined(NODE_ADDON_API_DIR "${DAWN_THIRD_PARTY_DIR}/node-addon-api" "Directory in which to find node-addon-api")
|
2021-09-30 18:04:01 +00:00
|
|
|
set_if_not_defined(NODE_API_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/node-api-headers" "Directory in which to find node-api-headers")
|
2021-09-28 11:14:42 +00:00
|
|
|
set_if_not_defined(WEBGPU_IDL_PATH "${DAWN_THIRD_PARTY_DIR}/gpuweb/webgpu.idl" "Path to the webgpu.idl definition file")
|
2021-10-15 14:28:32 +00:00
|
|
|
set_if_not_defined(GO_EXECUTABLE "go" "Golang executable for running the IDL generator")
|
2021-09-28 11:14:42 +00:00
|
|
|
|
2021-06-30 15:06:43 +00:00
|
|
|
# Much of the backend code is shared among desktop OpenGL and OpenGL ES
|
|
|
|
if (${DAWN_ENABLE_DESKTOP_GL} OR ${DAWN_ENABLE_OPENGLES})
|
|
|
|
set(DAWN_ENABLE_OPENGL ON)
|
|
|
|
endif()
|
|
|
|
|
2021-09-28 11:14:42 +00:00
|
|
|
if(DAWN_ENABLE_PIC)
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
endif()
|
|
|
|
|
2020-02-05 17:16:05 +00:00
|
|
|
################################################################################
|
|
|
|
# Dawn's public and internal "configs"
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# The public config contains only the include paths for the Dawn headers.
|
|
|
|
add_library(dawn_public_config INTERFACE)
|
|
|
|
target_include_directories(dawn_public_config INTERFACE
|
2022-02-04 18:18:18 +00:00
|
|
|
"${DAWN_INCLUDE_DIR}"
|
|
|
|
"${DAWN_BUILD_GEN_DIR}/include"
|
2020-02-05 17:16:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# The internal config conatins additional path but includes the dawn_public_config include paths
|
|
|
|
add_library(dawn_internal_config INTERFACE)
|
|
|
|
target_include_directories(dawn_internal_config INTERFACE
|
|
|
|
"${DAWN_SRC_DIR}"
|
|
|
|
"${DAWN_BUILD_GEN_DIR}/src"
|
|
|
|
)
|
|
|
|
target_link_libraries(dawn_internal_config INTERFACE dawn_public_config)
|
|
|
|
|
|
|
|
# Compile definitions for the internal config
|
|
|
|
if (DAWN_ALWAYS_ASSERT OR $<CONFIG:Debug>)
|
|
|
|
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS")
|
|
|
|
endif()
|
|
|
|
if (DAWN_ENABLE_D3D12)
|
|
|
|
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12")
|
|
|
|
endif()
|
|
|
|
if (DAWN_ENABLE_METAL)
|
|
|
|
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL")
|
|
|
|
endif()
|
|
|
|
if (DAWN_ENABLE_NULL)
|
|
|
|
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL")
|
|
|
|
endif()
|
2021-06-30 15:06:43 +00:00
|
|
|
if (DAWN_ENABLE_DESKTOP_GL)
|
|
|
|
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_DESKTOP_GL")
|
|
|
|
endif()
|
|
|
|
if (DAWN_ENABLE_OPENGLES)
|
|
|
|
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGLES")
|
|
|
|
endif()
|
2020-02-05 17:16:05 +00:00
|
|
|
if (DAWN_ENABLE_OPENGL)
|
|
|
|
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL")
|
|
|
|
endif()
|
|
|
|
if (DAWN_ENABLE_VULKAN)
|
|
|
|
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN")
|
|
|
|
endif()
|
2020-02-18 02:12:35 +00:00
|
|
|
if (DAWN_USE_X11)
|
2020-02-05 17:16:05 +00:00
|
|
|
target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11")
|
|
|
|
endif()
|
2020-02-24 13:27:28 +00:00
|
|
|
if (WIN32)
|
|
|
|
target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN")
|
|
|
|
endif()
|
|
|
|
|
2022-01-05 09:26:46 +00:00
|
|
|
set(CMAKE_CXX_STANDARD "17")
|
2020-02-05 17:16:05 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Run on all subdirectories
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
add_subdirectory(third_party)
|
|
|
|
add_subdirectory(generator)
|
|
|
|
add_subdirectory(src/dawn)
|
2022-02-04 18:59:15 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Samples
|
|
|
|
################################################################################
|
2020-02-05 17:16:05 +00:00
|
|
|
|
2022-02-04 18:35:55 +00:00
|
|
|
if (DAWN_BUILD_SAMPLES)
|
2020-10-27 19:38:27 +00:00
|
|
|
#TODO(dawn:269): Add this once implementation-based swapchains are removed.
|
2022-02-04 18:59:15 +00:00
|
|
|
#add_subdirectory(src/utils)
|
2022-02-04 18:35:55 +00:00
|
|
|
add_subdirectory(samples/dawn)
|
2020-02-05 17:16:05 +00:00
|
|
|
endif()
|