[build] Add guards for protobuf
GN: Only assume protobuf is available if tint_standalone or build_with_chromium
CMake: Add DAWN_PROTOBUF_DIR option, enable only if the directory exists
Change-Id: I8835002cb5934f20e6bf8c814199d636af0ebd27
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/161341
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 137cde1..5faeb1b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -258,6 +258,7 @@
set_if_not_defined(DAWN_MARKUPSAFE_DIR "${DAWN_THIRD_PARTY_DIR}/markupsafe" "Directory in which to find MarkupSafe")
set_if_not_defined(DAWN_KHRONOS_DIR "${DAWN_THIRD_PARTY_DIR}/khronos" "Directory in which to find Khronos GL headers")
set_if_not_defined(DAWN_SWIFTSHADER_DIR "${DAWN_THIRD_PARTY_DIR}/swiftshader" "Directory in which to find swiftshader")
+set_if_not_defined(DAWN_PROTOBUF_DIR "${DAWN_THIRD_PARTY_DIR}/protobuf" "Directory in which to find protobuf")
set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools")
set_if_not_defined(DAWN_SPIRV_HEADERS_DIR "${DAWN_VULKAN_DEPS_DIR}/spirv-headers/src" "Directory in which to find SPIRV-Headers")
@@ -497,7 +498,7 @@
set(TINT_LIB_FUZZING_ENGINE_LINK_OPTIONS "" CACHE STRING "Used by OSS-Fuzz to control, via link options, which fuzzing engine should be used")
-set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
+set(TINT_ROOT_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(TINT_SPIRV_HEADERS_DIR ${DAWN_SPIRV_HEADERS_DIR})
set(TINT_SPIRV_TOOLS_DIR ${DAWN_SPIRV_TOOLS_DIR})
@@ -567,6 +568,10 @@
################################################################################
# Run on all subdirectories
################################################################################
+if (EXISTS "${DAWN_PROTOBUF_DIR}")
+ # Needs to come before SPIR-V Tools
+ include("third_party/protobuf.cmake")
+endif()
add_subdirectory(third_party)
diff --git a/scripts/tint_overrides_with_defaults.gni b/scripts/tint_overrides_with_defaults.gni
index adecb7d..de64173 100644
--- a/scripts/tint_overrides_with_defaults.gni
+++ b/scripts/tint_overrides_with_defaults.gni
@@ -42,6 +42,7 @@
}
tint_has_fuzzers = tint_has_build
+tint_has_protobuf = tint_standalone || build_with_chromium
declare_args() {
# Path to tint checkout
@@ -118,6 +119,11 @@
tint_build_syntax_tree_writer = false
}
+ # Build the Syntax Tree writer
+ if (!defined(tint_build_ir_binary)) {
+ tint_build_ir_binary = tint_has_protobuf
+ }
+
# Build unittests
if (!defined(tint_build_unittests)) {
tint_build_unittests = true
diff --git a/src/tint/tint.gni b/src/tint/tint.gni
index d40c570..5613f79 100644
--- a/src/tint/tint.gni
+++ b/src/tint/tint.gni
@@ -27,10 +27,12 @@
import("//build_overrides/build.gni")
-import("//third_party/protobuf/proto_library.gni")
-
import("../../scripts/tint_overrides_with_defaults.gni")
+if (tint_has_protobuf) {
+ import("//third_party/protobuf/proto_library.gni")
+}
+
###############################################################################
# Tint library target
###############################################################################
@@ -65,6 +67,9 @@
# Tint protobuf library target
###############################################################################
template("tint_proto_library") {
+ if (!tint_has_protobuf) {
+ error("Tint needs protobuf to build a proto library")
+ }
proto_library(target_name) {
forward_variables_from(invoker, "*", [ "configs" ])
generate_cc = true
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index ef51797..70dc58d 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -25,9 +25,6 @@
# 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.
-# Needs to come before SPIR-V Tools
-include("protobuf.cmake")
-
# Don't build testing in third_party dependencies
set(BUILD_TESTING OFF)
diff --git a/third_party/protobuf.cmake b/third_party/protobuf.cmake
index 48850d3..731068f 100644
--- a/third_party/protobuf.cmake
+++ b/third_party/protobuf.cmake
@@ -35,7 +35,7 @@
set(protobuf_BUILD_PROTOC_BINARIES ON CACHE BOOL "Build libprotoc and protoc compiler" FORCE)
set(protobuf_DISABLE_RTTI ON CACHE BOOL "Remove runtime type information in the binaries" FORCE)
-add_subdirectory("protobuf/cmake")
+add_subdirectory("${DAWN_PROTOBUF_DIR}/cmake")
target_compile_definitions(libprotobuf PUBLIC "-DGOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE=0")