Split root CmakeLists.txt into smaller nested ones.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a61aa9b..51d6951 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -92,123 +92,22 @@
set(PROTOBUF_CXXFLAGS "${CMAKE_CXX_FLAGS} ${NO_FUZZING_FLAGS} -w")
include(protobuf)
-# Libraries
-protobuf_generate_cpp(XML_PROTO_SRCS
- XML_PROTO_HDRS
- src/xml/xml.proto)
-
-add_library(protobuf-mutator
- src/libfuzzer_protobuf_mutator.cc
- src/protobuf_mutator.cc
- src/xml/libfuzzer_xml_mutator.cc
- src/xml/xml_writer.cc
- ${XML_PROTO_SRCS})
-target_link_libraries(protobuf-mutator
- ${PROTOBUF_LIBRARY})
-set_property(TARGET protobuf-mutator
- PROPERTY COMPILE_FLAGS "${NO_FUZZING_FLAGS}")
-
-
-# Binaries
-add_executable(xml_converter
- src/xml/xml_converter.cc)
-target_link_libraries(xml_converter
- protobuf-mutator)
-
-# Tests
enable_testing()
+
include(googletest)
-protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS src/protobuf_mutator.proto)
-add_executable(protobuf_mutator_test
- src/protobuf_mutator_test.cc
- src/weighted_reservoir_sampler_test.cc
- ${PROTO_SRCS})
-target_link_libraries(protobuf_mutator_test
- protobuf-mutator
- ${ZLIB_LIBRARIES}
- ${GTEST_BOTH_LIBRARIES}
- ${CMAKE_THREAD_LIBS_INIT})
ProcessorCount(CPU_COUNT)
-math(EXPR TEST_SHARDS_COUNT 2*${CPU_COUNT})
-math(EXPR TEST_SHARDS_MAX ${TEST_SHARDS_COUNT}-1)
-foreach(SHARD RANGE ${TEST_SHARDS_MAX})
- add_test(test.protobuf_mutator_test_${SHARD} protobuf_mutator_test --gtest_color=yes AUTO)
- set_property(
- TEST test.protobuf_mutator_test_${SHARD}
- APPEND PROPERTY ENVIRONMENT
- GTEST_SHARD_INDEX=${SHARD}
- GTEST_TOTAL_SHARDS=${TEST_SHARDS_COUNT})
-endforeach(SHARD)
-
add_custom_target(check
- COMMAND ${CMAKE_CTEST_COMMAND} -j${CPU_COUNT} --output-on-failure
- DEPENDS protobuf_mutator_test)
+ COMMAND ${CMAKE_CTEST_COMMAND} -j${CPU_COUNT} --output-on-failure)
-# Examples
+add_subdirectory(src)
+
if ("${LIB_PROTO_MUTATOR_FUZZER_LIBRARIES}" STREQUAL "" AND
NOT "${FUZZING_FLAGS}" STREQUAL "")
include(libfuzzer)
endif()
if (NOT "${LIB_PROTO_MUTATOR_FUZZER_LIBRARIES}" STREQUAL "")
- protobuf_generate_cpp(LIB_FUZZER_EXAMPLE_PROTO_SRCS
- LIB_FUZZER_EXAMPLE_PROTO_HDRS
- examples/libfuzzer/libfuzzer_example.proto)
- add_executable(libfuzzer_example
- examples/libfuzzer/libfuzzer_example.cc
- ${LIB_FUZZER_EXAMPLE_PROTO_SRCS})
- target_link_libraries(libfuzzer_example
- protobuf-mutator
- ${LIB_PROTO_MUTATOR_FUZZER_LIBRARIES}
- ${CMAKE_THREAD_LIBS_INIT})
- set_property(TARGET libfuzzer_example
- PROPERTY COMPILE_FLAGS ${FUZZING_FLAGS})
- set_property(TARGET libfuzzer_example
- PROPERTY LINK_FLAGS ${FUZZING_FLAGS})
- target_sources(protobuf_mutator_test
- PRIVATE examples/libfuzzer/libfuzzer_example_test.cc)
- add_dependencies(protobuf_mutator_test libfuzzer_example)
-
- set(LIBXML2_CFLAGS "${CMAKE_C_FLAGS} ${FUZZING_FLAGS} -w")
- set(LIBXML2_CXXFLAGS "${CMAKE_CXX_FLAGS} ${FUZZING_FLAGS} -w")
- include(libxml2)
- add_executable(libxml2_example
- examples/libxml2/libxml2_example.cc)
- target_link_libraries(libxml2_example
- protobuf-mutator
- ${LIB_PROTO_MUTATOR_FUZZER_LIBRARIES}
- ${CMAKE_THREAD_LIBS_INIT}
- ${LIBXML2_LIBRARIES}
- ${ZLIB_LIBRARIES}
- ${LIBLZMA_LIBRARIES})
- set_property(TARGET libxml2_example
- PROPERTY COMPILE_FLAGS ${FUZZING_FLAGS})
- set_property(TARGET libxml2_example
- PROPERTY LINK_FLAGS ${FUZZING_FLAGS})
-
- target_sources(protobuf_mutator_test
- PRIVATE examples/libxml2/libxml2_example_test.cc)
- add_dependencies(protobuf_mutator_test libxml2_example)
-
- set(EXPAT_CFLAGS "${CMAKE_C_FLAGS} ${FUZZING_FLAGS} -w")
- set(EXPAT_CXXFLAGS "${CMAKE_CXX_FLAGS} ${FUZZING_FLAGS} -w")
- include(expat)
- add_executable(expat_example
- examples/expat/expat_example.cc)
- target_link_libraries(expat_example
- protobuf-mutator
- ${LIB_PROTO_MUTATOR_FUZZER_LIBRARIES}
- ${CMAKE_THREAD_LIBS_INIT}
- ${EXPAT_LIBRARIES}
- ${ZLIB_LIBRARIES}
- ${LIBLZMA_LIBRARIES})
- set_property(TARGET expat_example
- PROPERTY COMPILE_FLAGS ${FUZZING_FLAGS})
- set_property(TARGET expat_example
- PROPERTY LINK_FLAGS ${FUZZING_FLAGS})
-
- target_sources(protobuf_mutator_test
- PRIVATE examples/expat/expat_example_test.cc)
- add_dependencies(protobuf_mutator_test expat_example)
+ add_subdirectory(examples)
endif()
+
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..f7a4d5d
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,17 @@
+# Copyright 2017 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+add_subdirectory(expat)
+add_subdirectory(libfuzzer)
+add_subdirectory(libxml2)
diff --git a/examples/expat/CMakeLists.txt b/examples/expat/CMakeLists.txt
new file mode 100644
index 0000000..e10d910
--- /dev/null
+++ b/examples/expat/CMakeLists.txt
@@ -0,0 +1,37 @@
+# Copyright 2017 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(EXPAT_CFLAGS "${CMAKE_C_FLAGS} ${FUZZING_FLAGS} -w")
+set(EXPAT_CXXFLAGS "${CMAKE_CXX_FLAGS} ${FUZZING_FLAGS} -w")
+include(expat)
+
+add_executable(expat_example
+ expat_example.cc)
+target_link_libraries(expat_example
+ protobuf-mutator-xml
+ ${LIB_PROTO_MUTATOR_FUZZER_LIBRARIES}
+ ${EXPAT_LIBRARIES})
+set_property(TARGET expat_example
+ PROPERTY COMPILE_FLAGS ${FUZZING_FLAGS})
+set_property(TARGET expat_example
+ PROPERTY LINK_FLAGS ${FUZZING_FLAGS})
+
+add_executable(expat_example_test
+ expat_example_test.cc)
+add_dependencies(expat_example_test expat_example)
+target_link_libraries(expat_example_test
+ ${GTEST_BOTH_LIBRARIES}
+ ${CMAKE_THREAD_LIBS_INIT})
+add_test(test.expat_example_test expat_example_test --gtest_color=yes AUTO)
+add_dependencies(check expat_example_test)
diff --git a/examples/libfuzzer/CMakeLists.txt b/examples/libfuzzer/CMakeLists.txt
new file mode 100644
index 0000000..173363c
--- /dev/null
+++ b/examples/libfuzzer/CMakeLists.txt
@@ -0,0 +1,37 @@
+# Copyright 2017 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+protobuf_generate_cpp(LIB_FUZZER_EXAMPLE_PROTO_SRCS
+ LIB_FUZZER_EXAMPLE_PROTO_HDRS
+ libfuzzer_example.proto)
+add_executable(libfuzzer_example
+ libfuzzer_example.cc
+ ${LIB_FUZZER_EXAMPLE_PROTO_SRCS})
+target_link_libraries(libfuzzer_example
+ protobuf-mutator
+ ${LIB_PROTO_MUTATOR_FUZZER_LIBRARIES})
+set_property(TARGET libfuzzer_example
+ PROPERTY COMPILE_FLAGS ${FUZZING_FLAGS})
+set_property(TARGET libfuzzer_example
+ PROPERTY LINK_FLAGS ${FUZZING_FLAGS})
+
+add_executable(libfuzzer_example_test
+ libfuzzer_example_test.cc)
+add_dependencies(libfuzzer_example_test libfuzzer_example)
+target_link_libraries(libfuzzer_example_test
+ ${GTEST_BOTH_LIBRARIES}
+ ${CMAKE_THREAD_LIBS_INIT})
+add_test(test.libfuzzer_example_test libfuzzer_example_test --gtest_color=yes AUTO)
+
+add_dependencies(check libfuzzer_example_test)
diff --git a/examples/libfuzzer/libfuzzer_example.cc b/examples/libfuzzer/libfuzzer_example.cc
index e497fe9..51a583e 100644
--- a/examples/libfuzzer/libfuzzer_example.cc
+++ b/examples/libfuzzer/libfuzzer_example.cc
@@ -15,7 +15,7 @@
#include <cstddef>
#include <cstdint>
-#include "libfuzzer_example.pb.h" // NOLINT
+#include "examples/libfuzzer/libfuzzer_example.pb.h"
#include "src/libfuzzer_protobuf_mutator.h"
using libfuzzer_example::Msg;
diff --git a/examples/libfuzzer/libfuzzer_example_test.cc b/examples/libfuzzer/libfuzzer_example_test.cc
index b40aa91..d18b4cb 100644
--- a/examples/libfuzzer/libfuzzer_example_test.cc
+++ b/examples/libfuzzer/libfuzzer_example_test.cc
@@ -24,7 +24,7 @@
auto dir = mkdtemp(dir_template);
ASSERT_TRUE(dir);
- std::string cmd = "./libfuzzer_example -max_len=70 -artifact_prefix=" +
+ std::string cmd = "./libfuzzer_example -max_len=150 -artifact_prefix=" +
std::string(dir) + "/ " + dir + "/";
int retvalue = std::system(cmd.c_str());
EXPECT_EQ(kDefaultLibFuzzerError, WSTOPSIG(retvalue));
diff --git a/examples/libxml2/CMakeLists.txt b/examples/libxml2/CMakeLists.txt
new file mode 100644
index 0000000..f39e35d
--- /dev/null
+++ b/examples/libxml2/CMakeLists.txt
@@ -0,0 +1,38 @@
+# Copyright 2017 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set(LIBXML2_CFLAGS "${CMAKE_C_FLAGS} ${FUZZING_FLAGS} -w")
+set(LIBXML2_CXXFLAGS "${CMAKE_CXX_FLAGS} ${FUZZING_FLAGS} -w")
+include(libxml2)
+add_executable(libxml2_example
+ libxml2_example.cc)
+target_link_libraries(libxml2_example
+ protobuf-mutator-xml
+ ${LIB_PROTO_MUTATOR_FUZZER_LIBRARIES}
+ ${LIBXML2_LIBRARIES}
+ ${ZLIB_LIBRARIES}
+ ${LIBLZMA_LIBRARIES})
+set_property(TARGET libxml2_example
+ PROPERTY COMPILE_FLAGS ${FUZZING_FLAGS})
+set_property(TARGET libxml2_example
+ PROPERTY LINK_FLAGS ${FUZZING_FLAGS})
+
+add_executable(libxml2_example_test
+ libxml2_example_test.cc)
+add_dependencies(libxml2_example_test libxml2_example)
+target_link_libraries(libxml2_example_test
+ ${GTEST_BOTH_LIBRARIES}
+ ${CMAKE_THREAD_LIBS_INIT})
+add_test(test.libxml2_example_test libxml2_example_test --gtest_color=yes AUTO)
+add_dependencies(check libxml2_example_test)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..c7ef341
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,49 @@
+# Copyright 2017 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+add_subdirectory(xml)
+
+add_library(protobuf-mutator
+ libfuzzer_protobuf_mutator.cc
+ protobuf_mutator.cc)
+target_link_libraries(protobuf-mutator
+ ${PROTOBUF_LIBRARY})
+set_property(TARGET protobuf-mutator
+ PROPERTY COMPILE_FLAGS "${NO_FUZZING_FLAGS}")
+
+protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS protobuf_mutator.proto)
+
+add_executable(protobuf_mutator_test
+ protobuf_mutator_test.cc
+ weighted_reservoir_sampler_test.cc
+ ${PROTO_SRCS})
+target_link_libraries(protobuf_mutator_test
+ protobuf-mutator
+ ${ZLIB_LIBRARIES}
+ ${GTEST_BOTH_LIBRARIES}
+ ${CMAKE_THREAD_LIBS_INIT})
+
+ProcessorCount(CPU_COUNT)
+math(EXPR TEST_SHARDS_COUNT 2*${CPU_COUNT})
+math(EXPR TEST_SHARDS_MAX ${TEST_SHARDS_COUNT}-1)
+foreach(SHARD RANGE ${TEST_SHARDS_MAX})
+ add_test(test.protobuf_mutator_test_${SHARD} protobuf_mutator_test --gtest_color=yes AUTO)
+ set_property(
+ TEST test.protobuf_mutator_test_${SHARD}
+ APPEND PROPERTY ENVIRONMENT
+ GTEST_SHARD_INDEX=${SHARD}
+ GTEST_TOTAL_SHARDS=${TEST_SHARDS_COUNT})
+endforeach(SHARD)
+
+add_dependencies(check protobuf_mutator_test)
diff --git a/src/protobuf_mutator_test.cc b/src/protobuf_mutator_test.cc
index 3649b1d..6549e32 100644
--- a/src/protobuf_mutator_test.cc
+++ b/src/protobuf_mutator_test.cc
@@ -23,7 +23,7 @@
#include "google/protobuf/text_format.h"
#include "google/protobuf/util/message_differencer.h"
#include "gtest/gtest.h"
-#include "protobuf_mutator.pb.h" // NOLINT
+#include "src/protobuf_mutator.pb.h"
using google::protobuf::TextFormat;
using google::protobuf::util::MessageDifferencer;
diff --git a/src/xml/CMakeLists.txt b/src/xml/CMakeLists.txt
new file mode 100644
index 0000000..d0a1b83
--- /dev/null
+++ b/src/xml/CMakeLists.txt
@@ -0,0 +1,33 @@
+# Copyright 2017 Google Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Libraries
+protobuf_generate_cpp(XML_PROTO_SRCS
+ XML_PROTO_HDRS
+ xml.proto)
+
+add_library(protobuf-mutator-xml
+ libfuzzer_xml_mutator.cc
+ xml_writer.cc
+ ${XML_PROTO_SRCS})
+target_link_libraries(protobuf-mutator-xml
+ protobuf-mutator)
+set_property(TARGET protobuf-mutator-xml
+ PROPERTY COMPILE_FLAGS "${NO_FUZZING_FLAGS}")
+
+
+add_executable(xml_converter
+ xml_converter.cc)
+target_link_libraries(xml_converter
+ protobuf-mutator-xml)
diff --git a/src/xml/libfuzzer_xml_mutator.cc b/src/xml/libfuzzer_xml_mutator.cc
index 5501d25..ac6a5a1 100644
--- a/src/xml/libfuzzer_xml_mutator.cc
+++ b/src/xml/libfuzzer_xml_mutator.cc
@@ -16,7 +16,7 @@
#include "src/libfuzzer_protobuf_mutator.h"
#include "src/xml/xml_writer.h"
-#include "xml.pb.h" // NOLINT
+#include "src/xml/xml.pb.h"
using protobuf_mutator::xml::Input;
diff --git a/src/xml/xml_converter.cc b/src/xml/xml_converter.cc
index 283a0af..6bdc516 100644
--- a/src/xml/xml_converter.cc
+++ b/src/xml/xml_converter.cc
@@ -19,7 +19,7 @@
#include "src/libfuzzer_protobuf_mutator.h"
#include "src/xml/xml_writer.h"
-#include "xml.pb.h" // NOLINT
+#include "src/xml/xml.pb.h"
using protobuf_mutator::xml::Input;
diff --git a/src/xml/xml_writer.cc b/src/xml/xml_writer.cc
index fddb0f5..e68c4ed 100644
--- a/src/xml/xml_writer.cc
+++ b/src/xml/xml_writer.cc
@@ -17,7 +17,7 @@
#include <algorithm>
#include <sstream>
-#include "xml.pb.h" // NOLINT
+#include "src/xml/xml.pb.h"
namespace protobuf_mutator {
namespace xml {