Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 1 | # 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 | |
| 15 | cmake_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 Wallez | 42450c6 | 2020-04-10 17:04:31 +0000 | [diff] [blame] | 20 | # case any of the generator files changes. We should also remove the CACHE "" FORCE stuff to |
dan sinclair | 1877c27 | 2020-10-20 19:46:21 +0000 | [diff] [blame] | 21 | # 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 Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 23 | |
| 24 | project( |
| 25 | Dawn |
| 26 | DESCRIPTION "Dawn, a WebGPU implementation" |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 27 | LANGUAGES C CXX |
| 28 | ) |
| 29 | |
| 30 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 31 | |
| 32 | if(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) |
| 36 | endif() |
| 37 | |
| 38 | set(DAWN_BUILD_GEN_DIR "${Dawn_BINARY_DIR}/gen") |
| 39 | set(DAWN_GENERATOR_DIR "${Dawn_SOURCE_DIR}/generator") |
| 40 | set(DAWN_SRC_DIR "${Dawn_SOURCE_DIR}/src") |
| 41 | set(DAWN_INCLUDE_DIR "${DAWN_SRC_DIR}/include") |
| 42 | set(DAWN_TEMPLATE_DIR "${DAWN_GENERATOR_DIR}/templates") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 43 | |
| 44 | set(DAWN_DUMMY_FILE "${DAWN_SRC_DIR}/Dummy.cpp") |
| 45 | |
| 46 | ################################################################################ |
| 47 | # Configuration options |
| 48 | ################################################################################ |
| 49 | |
| 50 | # Default values for the backend-enabling options |
| 51 | set(ENABLE_D3D12 OFF) |
| 52 | set(ENABLE_METAL OFF) |
| 53 | set(ENABLE_OPENGL OFF) |
| 54 | set(ENABLE_VULKAN OFF) |
Corentin Wallez | d353ca0 | 2020-02-18 02:12:35 +0000 | [diff] [blame] | 55 | set(USE_X11 OFF) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 56 | if (WIN32) |
| 57 | set(ENABLE_D3D12 ON) |
| 58 | set(ENABLE_VULKAN ON) |
| 59 | elseif(APPLE) |
| 60 | set(ENABLE_METAL ON) |
| 61 | elseif(UNIX) |
| 62 | set(ENABLE_OPENGL ON) |
| 63 | set(ENABLE_VULKAN ON) |
Corentin Wallez | d353ca0 | 2020-02-18 02:12:35 +0000 | [diff] [blame] | 64 | set(USE_X11 ON) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 65 | endif() |
| 66 | |
| 67 | option(DAWN_ENABLE_D3D12 "Enable compilation of the D3D12 backend" ${ENABLE_D3D12}) |
| 68 | option(DAWN_ENABLE_METAL "Enable compilation of the Metal backend" ${ENABLE_METAL}) |
| 69 | option(DAWN_ENABLE_NULL "Enable compilation of the Null backend" ON) |
| 70 | option(DAWN_ENABLE_OPENGL "Enable compilation of the OpenGL backend" ${ENABLE_OPENGL}) |
| 71 | option(DAWN_ENABLE_VULKAN "Enable compilation of the Vulkan backend" ${ENABLE_VULKAN}) |
| 72 | option(DAWN_ALWAYS_ASSERT "Enable assertions on all build types" OFF) |
Corentin Wallez | d353ca0 | 2020-02-18 02:12:35 +0000 | [diff] [blame] | 73 | option(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11}) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 74 | |
| 75 | option(DAWN_BUILD_EXAMPLES "Enables building Dawn's exmaples" ON) |
| 76 | |
Corentin Wallez | e557087 | 2020-10-20 14:26:10 +0000 | [diff] [blame] | 77 | set(DAWN_THIRD_PARTY_DIR "${Dawn_SOURCE_DIR}/third_party" CACHE STRING "Directory in which to find third-party dependencies.") |
| 78 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 79 | set(DAWN_GLFW_DIR "${DAWN_THIRD_PARTY_DIR}/glfw" CACHE STRING "Directory in which to find GLFW") |
| 80 | set(DAWN_GLM_DIR "${DAWN_THIRD_PARTY_DIR}/glm" CACHE STRING "Directory in which to find GLM") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 81 | set(DAWN_JINJA2_DIR "${DAWN_THIRD_PARTY_DIR}/jinja2" CACHE STRING "Directory in which to find Jinja2") |
J-P Nurmi | b3c4cc0 | 2021-01-07 10:35:02 +0000 | [diff] [blame] | 82 | set(DAWN_SPIRV_CROSS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-cross/src" CACHE STRING "Directory in which to find SPIRV-Cross") |
Stephen White | f1fa60b | 2021-01-06 17:41:50 +0000 | [diff] [blame] | 83 | set(DAWN_SPIRV_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-headers/src" CACHE STRING "Directory in which to find SPIRV-Headers") |
| 84 | set(DAWN_SPIRV_TOOLS_DIR "${DAWN_THIRD_PARTY_DIR}/vulkan-deps/spirv-tools/src" CACHE STRING "Directory in which to find SPIRV-Tools") |
dan sinclair | bb3d798 | 2020-10-23 13:10:20 +0000 | [diff] [blame] | 85 | set(DAWN_TINT_DIR "${DAWN_THIRD_PARTY_DIR}/tint" CACHE STRING "Directory in which to find Tint") |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 86 | |
| 87 | ################################################################################ |
| 88 | # Dawn's public and internal "configs" |
| 89 | ################################################################################ |
| 90 | |
| 91 | # The public config contains only the include paths for the Dawn headers. |
| 92 | add_library(dawn_public_config INTERFACE) |
| 93 | target_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 |
| 99 | add_library(dawn_internal_config INTERFACE) |
| 100 | target_include_directories(dawn_internal_config INTERFACE |
| 101 | "${DAWN_SRC_DIR}" |
| 102 | "${DAWN_BUILD_GEN_DIR}/src" |
| 103 | ) |
| 104 | target_link_libraries(dawn_internal_config INTERFACE dawn_public_config) |
| 105 | |
| 106 | # Compile definitions for the internal config |
| 107 | if (DAWN_ALWAYS_ASSERT OR $<CONFIG:Debug>) |
| 108 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_ASSERTS") |
| 109 | endif() |
| 110 | if (DAWN_ENABLE_D3D12) |
| 111 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_D3D12") |
| 112 | endif() |
| 113 | if (DAWN_ENABLE_METAL) |
| 114 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_METAL") |
| 115 | endif() |
| 116 | if (DAWN_ENABLE_NULL) |
| 117 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_NULL") |
| 118 | endif() |
| 119 | if (DAWN_ENABLE_OPENGL) |
| 120 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_OPENGL") |
| 121 | endif() |
| 122 | if (DAWN_ENABLE_VULKAN) |
| 123 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_ENABLE_BACKEND_VULKAN") |
| 124 | endif() |
Corentin Wallez | d353ca0 | 2020-02-18 02:12:35 +0000 | [diff] [blame] | 125 | if (DAWN_USE_X11) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 126 | target_compile_definitions(dawn_internal_config INTERFACE "DAWN_USE_X11") |
| 127 | endif() |
Corentin Wallez | 3346697 | 2020-02-24 13:27:28 +0000 | [diff] [blame] | 128 | if (WIN32) |
| 129 | target_compile_definitions(dawn_internal_config INTERFACE "NOMINMAX" "WIN32_LEAN_AND_MEAN") |
| 130 | endif() |
| 131 | |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 132 | set(CMAKE_CXX_STANDARD "14") |
| 133 | |
| 134 | ################################################################################ |
| 135 | # Run on all subdirectories |
| 136 | ################################################################################ |
| 137 | |
| 138 | add_subdirectory(third_party) |
| 139 | add_subdirectory(src/common) |
| 140 | add_subdirectory(generator) |
| 141 | add_subdirectory(src/dawn) |
| 142 | add_subdirectory(src/dawn_platform) |
| 143 | add_subdirectory(src/dawn_native) |
| 144 | add_subdirectory(src/dawn_wire) |
dan sinclair | bb3d798 | 2020-10-23 13:10:20 +0000 | [diff] [blame] | 145 | # TODO(dawn:269): Remove once the implementation-based swapchains are removed. |
| 146 | add_subdirectory(src/utils) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 147 | |
| 148 | if (DAWN_BUILD_EXAMPLES) |
David Neto | 762b7c3 | 2020-10-27 19:38:27 +0000 | [diff] [blame] | 149 | #TODO(dawn:269): Add this once implementation-based swapchains are removed. |
| 150 | #add_subdirectory(src/utils) |
Corentin Wallez | 7fe6efb | 2020-02-05 17:16:05 +0000 | [diff] [blame] | 151 | add_subdirectory(examples) |
| 152 | endif() |