Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
cmake_minimum_required(VERSION 3.19)
project(fuzztest)

option(FUZZTEST_DOWNLOAD_ABSL "Download abseil-cpp using FetchContent." OFF)
option(FUZZTEST_DOWNLOAD_RE2 "Download re2 using FetchContent." OFF)
option(FUZZTEST_DOWNLOAD_GTEST "Download googletest using FetchContent." OFF)
option(FUZZTEST_DOWNLOAD_PROTOBUF "Download protobuf using FetchContent." OFF)
option(FUZZTEST_DOWNLOAD_NLOHMANN "Download nlohmann_json using FetchContent." OFF)
option(FUZZTEST_DOWNLOAD_FLATBUFFERS "Download flatbuffers using FetchContent." OFF)
option(FUZZTEST_DOWNLOAD_DEPENDENCIES "Download all dependencies using FetchContent." ON)

option(FUZZTEST_BUILD_TESTING "Building the tests." OFF)
option(FUZZTEST_BUILD_FLATBUFFERS "Building the flatbuffers support." OFF)
option(FUZZTEST_FUZZING_MODE "Building the fuzztest in fuzzing mode." OFF)
Expand Down
137 changes: 86 additions & 51 deletions cmake/BuildDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,78 +43,113 @@ if(POLICY CMP0135)
set(CMAKE_POLICY_DEFAULT_CMP0135 NEW)
endif()

FetchContent_Declare(
abseil-cpp
GIT_REPOSITORY ${absl_URL}
GIT_TAG ${absl_TAG}
)
if(FUZZTEST_DOWNLOAD_DEPENDENCIES OR FUZZTEST_DOWNLOAD_ABSL)
FetchContent_Declare(
abseil-cpp
GIT_REPOSITORY ${absl_URL}
GIT_TAG ${absl_TAG}
)
else()
find_package(absl REQUIRED)
endif()

FetchContent_Declare(
re2
GIT_REPOSITORY ${re2_URL}
GIT_TAG ${re2_TAG}
)
if(FUZZTEST_DOWNLOAD_DEPENDENCIES OR FUZZTEST_DOWNLOAD_RE2)
FetchContent_Declare(
re2
GIT_REPOSITORY ${re2_URL}
GIT_TAG ${re2_TAG}
)
else()
find_package(re2 REQUIRED)
endif()

FetchContent_Declare(
googletest
GIT_REPOSITORY ${gtest_URL}
GIT_TAG ${gtest_TAG}
)
if(FUZZTEST_DOWNLOAD_DEPENDENCIES OR FUZZTEST_DOWNLOAD_GTEST)
FetchContent_Declare(
googletest
GIT_REPOSITORY ${gtest_URL}
GIT_TAG ${gtest_TAG}
)
else()
find_package(GTest REQUIRED)
endif()

FetchContent_Declare(
antlr_cpp
URL ${antlr_cpp_URL}
URL ${antlr_cpp_URL}
URL_HASH MD5=${antlr_cpp_MD5}
)

if (FUZZTEST_BUILD_FLATBUFFERS)
FetchContent_Declare(
flatbuffers
GIT_REPOSITORY ${flatbuffers_URL}
GIT_TAG ${flatbuffers_TAG}
)
if(FUZZTEST_DOWNLOAD_DEPENDENCIES OR FUZZTEST_DOWNLOAD_FLATBUFFERS)
FetchContent_Declare(
flatbuffers
GIT_REPOSITORY ${flatbuffers_URL}
GIT_TAG ${flatbuffers_TAG}
)
else()
find_package(flatbuffers REQUIRED)
endif()
endif()

if (FUZZTEST_BUILD_TESTING)

FetchContent_Declare(
protobuf
GIT_REPOSITORY ${proto_URL}
GIT_TAG ${proto_TAG}
)

FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY ${nlohmann_json_URL}
GIT_TAG ${nlohmann_json_TAG}
)

if(FUZZTEST_DOWNLOAD_DEPENDENCIES OR FUZZTEST_DOWNLOAD_PROTOBUF)
FetchContent_Declare(
protobuf
GIT_REPOSITORY ${proto_URL}
GIT_TAG ${proto_TAG}
)
else()
find_package(Protobuf REQUIRED)
if(TARGET Protobuf::protobuf AND NOT TARGET protobuf::libprotobuf)
add_library(protobuf::libprotobuf ALIAS Protobuf::protobuf)
endif()
endif ()

if(FUZZTEST_DOWNLOAD_DEPENDENCIES OR FUZZTEST_DOWNLOAD_NLOHMANN)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY ${nlohmann_json_URL}
GIT_TAG ${nlohmann_json_TAG}
)
else()
find_package(nlohmann_json REQUIRED)
endif()
endif ()

set(ABSL_PROPAGATE_CXX_STD ON)
set(ABSL_ENABLE_INSTALL ON)
FetchContent_MakeAvailable(abseil-cpp)
if(FUZZTEST_DOWNLOAD_DEPENDENCIES)
set(ABSL_PROPAGATE_CXX_STD ON)
set(ABSL_ENABLE_INSTALL ON)
FetchContent_MakeAvailable(abseil-cpp)
endif()

set(RE2_BUILD_TESTING OFF)
FetchContent_MakeAvailable(re2)
if(FUZZTEST_DOWNLOAD_DEPENDENCIES OR FUZZTEST_DOWNLOAD_RE2)
set(RE2_BUILD_TESTING OFF)
FetchContent_MakeAvailable(re2)
endif ()

set(GTEST_HAS_ABSL ON)
FetchContent_MakeAvailable(googletest)
if(FUZZTEST_DOWNLOAD_DEPENDENCIES OR FUZZTEST_DOWNLOAD_ABSL)
set(GTEST_HAS_ABSL ON)
FetchContent_MakeAvailable(googletest)
endif()

FetchContent_MakeAvailable(antlr_cpp)

if (FUZZTEST_BUILD_TESTING)

set(protobuf_BUILD_TESTS OFF)
set(protobuf_INSTALL OFF)
FetchContent_MakeAvailable(protobuf)

FetchContent_MakeAvailable(nlohmann_json)

if(FUZZTEST_DOWNLOAD_DEPENDENCIES OR FUZZTEST_DOWNLOAD_PROTOBUF)
set(protobuf_BUILD_TESTS OFF)
set(protobuf_INSTALL OFF)
FetchContent_MakeAvailable(protobuf)
endif()

if(FUZZTEST_DOWNLOAD_DEPENDENCIES OR FUZZTEST_DOWNLOAD_NLOHMANN)
FetchContent_MakeAvailable(nlohmann_json)
endif()
endif ()

if (FUZZTEST_BUILD_FLATBUFFERS)
set(FLATBUFFERS_BUILD_TESTS OFF)
set(FLATBUFFERS_BUILD_INSTALL OFF)
FetchContent_MakeAvailable(flatbuffers)
if(FUZZTEST_DOWNLOAD_DEPENDENCIES OR FUZZTEST_DOWNLOAD_FLATBUFFERS)
set(FLATBUFFERS_BUILD_TESTS OFF)
set(FLATBUFFERS_BUILD_INSTALL OFF)
FetchContent_MakeAvailable(flatbuffers)
endif()
endif()