| # Copyright 2022 The Dawn & Tint Authors |
| # |
| # Redistribution and use in source and binary forms, with or without |
| # modification, are permitted provided that the following conditions are met: |
| # |
| # 1. Redistributions of source code must retain the above copyright notice, this |
| # list of conditions and the following disclaimer. |
| # |
| # 2. Redistributions in binary form must reproduce the above copyright notice, |
| # this list of conditions and the following disclaimer in the documentation |
| # and/or other materials provided with the distribution. |
| # |
| # 3. Neither the name of the copyright holder nor the names of its |
| # contributors may be used to endorse or promote products derived from |
| # this software without specific prior written permission. |
| # |
| # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| |
| cmake_minimum_required(VERSION 3.10.2) |
| |
| # When upgrading to CMake 3.11 we can remove SAMPLES_PLACEHOLDER_FILE because source-less add_library |
| # becomes available. |
| # When upgrading to CMake 3.12 we should remove the CACHE "" FORCE stuff to |
| # override options in third_party dependencies. We can also add the HOMEPAGE_URL |
| # entry to the project `HOMEPAGE_URL "https://dawn.googlesource.com/samples"` |
| |
| project( |
| DawnSamples |
| DESCRIPTION "Samples for Dawn, a WebGPU implementation" |
| LANGUAGES C CXX |
| ) |
| enable_testing() |
| |
| set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| |
| set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) |
| set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| set(CMAKE_CXX_STANDARD 17) |
| set(CMAKE_DEBUG_POSTFIX "") |
| |
| if ("${CMAKE_BUILD_TYPE}" STREQUAL "") |
| message(STATUS "No build type selected, default to Debug") |
| set(CMAKE_BUILD_TYPE "Debug") |
| endif() |
| |
| set(SAMPLES_SRC_DIR "${DawnSamples_SOURCE_DIR}/src") |
| |
| set(SAMPLES_PLACEHOLDER_FILE "${SAMPLES_SRC_DIR}/Placeholder.cpp") |
| |
| ################################################################################ |
| # Configuration options |
| ################################################################################ |
| |
| # 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() |
| |
| # Default values for the backend-enabling options |
| set(USE_WAYLAND OFF) |
| set(USE_X11 OFF) |
| |
| if(UNIX) |
| set(USE_X11 ON) |
| endif() |
| |
| # GLFW is not supported in UWP |
| set(SAMPLES_SUPPORTS_GLFW_FOR_WINDOWING OFF) |
| |
| if ((WIN32 AND NOT WINDOWS_STORE) OR (UNIX AND NOT ANDROID)) |
| set(SAMPLES_SUPPORTS_GLFW_FOR_WINDOWING ON) |
| endif() |
| |
| # Current examples are depend on GLFW |
| if (SAMPLES_SUPPORTS_GLFW_FOR_WINDOWING) |
| set(BUILD_SAMPLES ON) |
| endif() |
| |
| option_if_not_defined(SAMPLES_USE_GLFW "Enable compilation of the GLFW windowing utils" ${SAMPLES_SUPPORTS_GLFW_FOR_WINDOWING}) |
| |
| if (NOT SAMPLES_USE_GLFW) |
| message(SEND_ERROR "Dawn samples require GLFW") |
| endif() |
| |
| set_if_not_defined(SAMPLES_THIRD_PARTY_DIR "${DawnSamples_SOURCE_DIR}/third_party" "Directory in which to find third-party dependencies.") |
| |
| set_if_not_defined(SAMPLES_DIR "${SAMPLES_THIRD_PARTY_DIR}/dawn" "Directory in which to find Dawn") |
| set_if_not_defined(SAMPLES_GLFW_DIR "${SAMPLES_THIRD_PARTY_DIR}/glfw" "Directory in which to find GLFW") |
| set_if_not_defined(SAMPLES_DAWN_DIR "${SAMPLES_THIRD_PARTY_DIR}/dawn" "Directory in which to find Dawm") |
| |
| option_if_not_defined(DAWN_USE_WAYLAND "Enable support for Wayland surface" ${USE_WAYLAND}) |
| option_if_not_defined(DAWN_USE_X11 "Enable support for X11 surface" ${USE_X11}) |
| option_if_not_defined(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON) |
| |
| message(STATUS "Samples build GLFW support: ${SAMPLES_USE_GLFW}") |
| |
| message(STATUS "Using python3") |
| find_package(PythonInterp 3 REQUIRED) |
| |
| ################################################################################ |
| # common_compile_options - sets compiler and linker options common for dawn and |
| # tint on the given target |
| ################################################################################ |
| function(common_compile_options TARGET) |
| if (COMPILER_IS_LIKE_GNU) |
| target_compile_options(${TARGET} PRIVATE |
| -fno-exceptions |
| -fno-rtti |
| |
| -Wno-deprecated-builtins |
| -Wno-unknown-warning-option |
| ) |
| |
| endif(COMPILER_IS_LIKE_GNU) |
| |
| if(MSVC) |
| target_compile_options(${TARGET} PUBLIC /utf-8) |
| endif() |
| endfunction() |
| |
| ################################################################################ |
| # Run on all subdirectories |
| ################################################################################ |
| |
| add_subdirectory(third_party) |
| |
| add_subdirectory(src/samples) |
| |