[cmake] Add build rules for libprotobuf-mutator
LPM wants to use the Protobuf package, which does not integrate nicely
with our existing build rules. Given that LPM is a handful of files,
just use our own library target for this.
Change-Id: Ie7cdcd49e455b72630d9be97ff19f98b7e5b81fe
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/189712
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8675f42..c474df6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -264,6 +264,7 @@
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_LPM_DIR "${DAWN_THIRD_PARTY_DIR}/libprotobuf-mutator/src" "Directory in which to find libprotobuf")
set_if_not_defined(DAWN_SPIRV_TOOLS_DIR "${DAWN_THIRD_PARTY_DIR}/spirv-tools/src" "Directory in which to find SPIRV-Tools")
set_if_not_defined(DAWN_SPIRV_HEADERS_DIR "${DAWN_THIRD_PARTY_DIR}/spirv-headers/src" "Directory in which to find SPIRV-Headers")
diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt
index 18cf96a..6e7534e 100644
--- a/src/tint/CMakeLists.txt
+++ b/src/tint/CMakeLists.txt
@@ -553,6 +553,8 @@
elseif(${DEPENDENCY} STREQUAL "gtest")
target_include_directories(${TARGET} PRIVATE ${gmock_SOURCE_DIR}/include)
target_link_libraries(${TARGET} PRIVATE gmock)
+ elseif(${DEPENDENCY} STREQUAL "libprotobuf-mutator")
+ target_link_libraries(${TARGET} PRIVATE libprotobuf-mutator)
elseif(${DEPENDENCY} STREQUAL "metal")
find_library(CoreGraphicsFramework CoreGraphics REQUIRED)
find_library(FoundationFramework Foundation REQUIRED)
diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt
index 5ceeb73..d60758d 100644
--- a/third_party/CMakeLists.txt
+++ b/third_party/CMakeLists.txt
@@ -103,6 +103,11 @@
add_subdirectory(${DAWN_ABSEIL_DIR} "${CMAKE_CURRENT_BINARY_DIR}/abseil")
endif()
+if (NOT TARGET libprotobuf-mutator)
+ message(STATUS "Dawn: using LPM at ${DAWN_LPM_DIR}")
+ include("libprotobuf-mutator/BUILD.cmake")
+endif()
+
if (NOT TARGET Vulkan-Headers)
message(STATUS "Dawn: using Vulkan-Headers at ${DAWN_VULKAN_HEADERS_DIR}")
add_subdirectory(${DAWN_VULKAN_HEADERS_DIR} "${CMAKE_CURRENT_BINARY_DIR}/vulkan-headers")
diff --git a/third_party/libprotobuf-mutator/BUILD.cmake b/third_party/libprotobuf-mutator/BUILD.cmake
new file mode 100644
index 0000000..844bef5
--- /dev/null
+++ b/third_party/libprotobuf-mutator/BUILD.cmake
@@ -0,0 +1,41 @@
+# Copyright 2024 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.
+
+# A minimal set of libraries for LPM
+add_library(libprotobuf-mutator
+ "${DAWN_LPM_DIR}/src/libfuzzer/libfuzzer_mutator.cc"
+ "${DAWN_LPM_DIR}/src/libfuzzer/libfuzzer_macro.cc"
+ "${DAWN_LPM_DIR}/src/binary_format.cc"
+ "${DAWN_LPM_DIR}/src/mutator.cc"
+ "${DAWN_LPM_DIR}/src/text_format.cc"
+ "${DAWN_LPM_DIR}/src/utf8_fix.cc")
+target_include_directories(libprotobuf-mutator PUBLIC "${DAWN_LPM_DIR}")
+target_link_libraries(libprotobuf-mutator
+ libprotobuf)
+set_target_properties(libprotobuf-mutator PROPERTIES
+ COMPILE_FLAGS "${NO_FUZZING_FLAGS}"
+ SOVERSION 0)