From 4d7d1697fa5508335f24f57621cd9b0657cea1cc Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 13 Aug 2018 08:23:27 +0200 Subject: [PATCH] Add samples to BUILD.gn and their deps to DEPS Also add missing GLFW DEPS entry --- BUILD.gn | 90 ++++++++++++++++++++++++++++++ DEPS | 17 +++++- examples/CubeReflection.cpp | 6 +- examples/glTFViewer/glTFViewer.cpp | 3 +- third_party/BUILD.gn | 53 ++++++++++++++++++ 5 files changed, 164 insertions(+), 5 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index d81b72259e..97852061ff 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -168,6 +168,10 @@ config("dawn_internal") { } configs = [ ":libdawn_public" ] + + # Only internal Dawn targets can use this config, this means only targets in + # this BUILD.gn file. + visibility = [ ":*" ] } # Executable needs an rpath to find our shared libraries on OSX @@ -885,3 +889,89 @@ test("dawn_end2end_tests") { "src/tests/end2end/ViewportOrientationTests.cpp", ] } + +############################################################################### +# Dawn samples, only in standalone builds +############################################################################### + +if (dawn_standalone) { + # Static library to contain code and dependencies common to all samples + static_library("dawn_sample_utils") { + sources = [ + "examples/SampleUtils.cpp", + "examples/SampleUtils.h", + ] + + # Export all of these as public deps so that `gn check` allows includes + public_deps = [ + ":dawn_common", + ":dawn_utils", + ":libdawn", + ":libdawn_native", + ":libdawn_wire", + "third_party:glfw", + ] + public_configs = [ ":dawn_internal" ] + } + + # Template for samples to avoid listing dawn_sample_utils as a dep every time + template("dawn_sample") { + executable(target_name) { + deps = [ + ":dawn_sample_utils", + ] + forward_variables_from(invoker, "*", [ "deps" ]) + + if (defined(invoker.deps)) { + deps += invoker.deps + } + } + } + + dawn_sample("CppHelloTriangle") { + sources = [ + "examples/CppHelloTriangle.cpp", + ] + } + + dawn_sample("CHelloTriangle") { + sources = [ + "examples/CHelloTriangle.cpp", + ] + } + + dawn_sample("ComputeBoids") { + sources = [ + "examples/ComputeBoids.cpp", + ] + deps = [ + "third_party:glm", + ] + } + + dawn_sample("Animometer") { + sources = [ + "examples/Animometer.cpp", + ] + } + + dawn_sample("CubeReflection") { + sources = [ + "examples/CubeReflection.cpp", + ] + deps = [ + "third_party:glm", + ] + } + + dawn_sample("glTFViewer") { + sources = [ + "examples/glTFViewer/Camera.inl", + "examples/glTFViewer/glTFViewer.cpp", + ] + deps = [ + "third_party:glm", + "third_party:tiny_gltf_loader", + ] + } +} diff --git a/DEPS b/DEPS index 79c5311ffc..573cc62c1c 100644 --- a/DEPS +++ b/DEPS @@ -26,7 +26,7 @@ deps = { 'url': '{chromium_git}/chromium/src/testing@4d706fd80be9e8989aec5235540e7b46d0672826', 'condition': 'dawn_standalone', }, - 'third_party/googletest': { + '{dawn_root}/third_party/googletest': { 'url': '{github_git}/google/googletest.git@98a0d007d7092b72eea0e501bb9ad17908a1a036', 'condition': 'dawn_standalone', }, @@ -55,6 +55,21 @@ deps = { 'condition': 'dawn_standalone', }, + # GLFW for tests and samples + '{dawn_root}/third_party/glfw': { + 'url': '{github_git}/glfw/glfw.git@096efdf798896cff80a0b2db08d7398b703406fe', + 'condition': 'dawn_standalone', + }, + + # Dependencies for samples: stb and GLM + '{dawn_root}/third_party/stb': { + 'url': '{github_git}/nothings/stb.git@c7110588a4d24c4bb5155c184fbb77dd90b3116e', + 'condition': 'dawn_standalone', + }, + '{dawn_root}/third_party/glm': { + 'url': '{github_git}/g-truc/glm.git@06f084063fd6d9aa2ef6904517650700ae47b63d', + 'condition': 'dawn_standalone', + }, } hooks = [ diff --git a/examples/CubeReflection.cpp b/examples/CubeReflection.cpp index 1eae20108d..f4a003c0a1 100644 --- a/examples/CubeReflection.cpp +++ b/examples/CubeReflection.cpp @@ -18,9 +18,9 @@ #include "utils/SystemUtils.h" #include -#include -#include -#include +#include +#include +#include dawn::Device device; diff --git a/examples/glTFViewer/glTFViewer.cpp b/examples/glTFViewer/glTFViewer.cpp index fce4f4fdef..4fc84a65ca 100644 --- a/examples/glTFViewer/glTFViewer.cpp +++ b/examples/glTFViewer/glTFViewer.cpp @@ -18,7 +18,7 @@ #define __STDC_FORMAT_MACROS #endif -#include "SampleUtils.h" +#include "../SampleUtils.h" #include "common/Assert.h" #include "common/Math.h" @@ -36,6 +36,7 @@ #define TINYGLTF_LOADER_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION #define PICOJSON_ASSERT ASSERT +#undef __STDC_FORMAT_MACROS #include #include "GLFW/glfw3.h" diff --git a/third_party/BUILD.gn b/third_party/BUILD.gn index 07ebd47b20..763c2cf8ad 100644 --- a/third_party/BUILD.gn +++ b/third_party/BUILD.gn @@ -368,3 +368,56 @@ static_library("glfw") { ] } } + +############################################################################### +# Header-only dependencies for samples +############################################################################### + +if (dawn_standalone) { + # GLM + config("glm_public_config") { + include_dirs = [ "glm" ] + } + source_set("glm") { + public_configs = [ ":glm_public_config" ] + # GLM is header only but has too many files to list them. + } + + # STB + config("stb_public_config") { + include_dirs = [ "stb" ] + cflags_cc = [ "-Wno-implicit-fallthrough" ] + } + source_set("stb") { + public_configs = [ ":stb_public_config" ] + sources = [ + "stb/stb_image.h", + ] + } + + # PicoJSON + config("picojson_public_config") { + include_dirs = [ "." ] + } + source_set("picojson") { + public_configs = [ ":picojson_public_config" ] + sources = [ + "picojson/picojson.h", + ] + } + + # Tiny glTF Loader + config("tiny_gltf_loader_public_config") { + include_dirs = [ "." ] + } + source_set("tiny_gltf_loader") { + public_configs = [ ":tiny_gltf_loader_public_config" ] + public_deps = [ + ":picojson", + ":stb", + ] + sources = [ + "tinygltfloader/tiny_gltf_loader.h", + ] + } +}