blob: 161709463fcbaf5630f74b367861d3da8c5dbd80 [file] [log] [blame]
Corentin Wallez7fe6efb2020-02-05 17:16:05 +00001# Copyright 2020 The Dawn Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15cmake_minimum_required(VERSION 3.10)
16
17# When upgrading to CMake 3.11 we can remove DAWN_DUMMY_FILE because source-less add_library
18# becomes available.
19# When upgrading to CMake 3.12 we should add CONFIGURE_DEPENDS to DawnGenerator to rerun CMake in
Corentin Wallez42450c62020-04-10 17:04:31 +000020# case any of the generator files changes. We should also remove the CACHE "" FORCE stuff to
dan sinclair1877c272020-10-20 19:46:21 +000021# override options in third_party dependencies. We can also add the HOMEPAGE_URL
22# entry to the project `HOMEPAGE_URL "https://dawn.googlesource.com/dawn"`
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000023
24project(
25 Dawn
26 DESCRIPTION "Dawn, a WebGPU implementation"
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000027 LANGUAGES C CXX
28)
29
30set_property(GLOBAL PROPERTY USE_FOLDERS ON)
31
32if(NOT CMAKE_BUILD_TYPE)
33 message(WARNING "CMAKE_BUILD_TYPE not set, forcing it to Debug")
34 set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
35 "Build type (Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE)
36endif()
37
38set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen")
39set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator")
40set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src")
41set(DAWN_INCLUDE_DIR "${DAWN_SRC_DIR}/include")
42set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000043
44set(DAWN_DUMMY_FILE "${DAWN_SRC_DIR}/Dummy.cpp")
45
46################################################################################
47# Configuration options
48################################################################################
49
50# Default values for the backend-enabling options
51set(ENABLE_D3D12 OFF)
52set(ENABLE_METAL OFF)
53set(ENABLE_OPENGL OFF)
54set(ENABLE_VULKAN OFF)
Corentin Wallezd353ca02020-02-18 02:12:35 +000055set(USE_X11 OFF)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000056if (WIN32)
57 set(ENABLE_D3D12 ON)
58 set(ENABLE_VULKAN ON)
59elseif(APPLE)
60 set(ENABLE_METAL ON)
61elseif(UNIX)
62 set(ENABLE_OPENGL ON)
63 set(ENABLE_VULKAN ON)
Corentin Wallezd353ca02020-02-18 02:12:35 +000064 set(USE_X11 ON)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000065endif()
66
67option(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12})
68option(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL})
69option(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON)
70option(DAWN_ENABLE_OPENGL "Enable compilation of the OpenGL backend" ${ENABLE_OPENGL})
71option(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN})
72option(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF)
Corentin Wallezd353ca02020-02-18 02:12:35 +000073option(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11})
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000074
75option(DAWN_BUILD_EXAMPLES "Enables building Dawn's exmaples" ON)
76
Corentin Walleze5570872020-10-20 14:26:10 +000077set(DAWN_THIRD_PARTY_DIR "${Dawn_SOURCE_DIR}/third_party" CACHE STRING "Directory in which to find third-party dependencies.")
78
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000079set(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" CACHE STRING "Directory in which to find GLFW")
80set(DAWN_GLM_DIR "${DAWN_THIRD_PARTY_DIR}/glm" CACHE STRING "Directory in which to find GLM")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000081set(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" CACHE STRING "Directory in which to find Jinja2")
J-P Nurmib3c4cc02021-01-07 10:35:02 +000082set(DAWN_SPIRV_CROSS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-cross/src" CACHE STRING "Directory in which to find SPIRV-Cross")
Stephen Whitef1fa60b2021-01-06 17:41:50 +000083set(DAWN_SPIRV_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-headers/src" CACHE STRING "Directory in which to find SPIRV-Headers")
84set(DAWN_SPIRV_TOOLS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-tools/src" CACHE STRING "Directory in which to find SPIRV-Tools")
dan sinclairbb3d7982020-10-23 13:10:20 +000085set(DAWN_TINT_DIR "${DAWN_THIRD_PARTY_DIR}/tint" CACHE STRING "Directory in which to find Tint")
Corentin Wallez7fe6efb2020-02-05 17:16:05 +000086
87################################################################################
88# Dawn's public and internal "configs"
89################################################################################
90
91# The public config contains only the include paths for the Dawn headers.
92add_library(dawn_public_config INTERFACE)
93target_include_directories(dawn_public_config INTERFACE
94 "${DAWN_SRC_DIR}/include"
95 "${DAWN_BUILD_GEN_DIR}/src/include"
96)
97
98# The internal config conatins additional path but includes the dawn_public_config include paths
99add_library(dawn_internal_config INTERFACE)
100target_include_directories(dawn_internal_config INTERFACE
101 "${DAWN_SRC_DIR}"
102 "${DAWN_BUILD_GEN_DIR}/src"
103)
104target_link_libraries(dawn_internal_config INTERFACE dawn_public_config)
105
106# Compile definitions for the internal config
107if (DAWN_ALWAYS_ASSERT OR $<CONFIG:Debug>)
108 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS")
109endif()
110if (DAWN_ENABLE_D3D12)
111 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12")
112endif()
113if (DAWN_ENABLE_METAL)
114 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL")
115endif()
116if (DAWN_ENABLE_NULL)
117 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL")
118endif()
119if (DAWN_ENABLE_OPENGL)
120 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL")
121endif()
122if (DAWN_ENABLE_VULKAN)
123 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN")
124endif()
Corentin Wallezd353ca02020-02-18 02:12:35 +0000125if (DAWN_USE_X11)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000126 target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11")
127endif()
Corentin Wallez33466972020-02-24 13:27:28 +0000128if (WIN32)
129 target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN")
130endif()
131
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000132set(CMAKE_CXX_STANDARD "14")
133
134################################################################################
135# Run on all subdirectories
136################################################################################
137
138add_subdirectory(third_party)
139add_subdirectory(src/common)
140add_subdirectory(generator)
141add_subdirectory(src/dawn)
142add_subdirectory(src/dawn_platform)
143add_subdirectory(src/dawn_native)
144add_subdirectory(src/dawn_wire)
dan sinclairbb3d7982020-10-23 13:10:20 +0000145# TODO(dawn:269): Remove once the implementation-based swapchains are removed.
146add_subdirectory(src/utils)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000147
148if (DAWN_BUILD_EXAMPLES)
David Neto762b7c32020-10-27 19:38:27 +0000149 #TODO(dawn:269): Add this once implementation-based swapchains are removed.
150 #add_subdirectory(src/utils)
Corentin Wallez7fe6efb2020-02-05 17:16:05 +0000151 add_subdirectory(examples)
152endif()