143 lines · plain
1set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} FuzzerCLI)2set(CXX_FLAGS_NOFUZZ ${CMAKE_CXX_FLAGS})3set(DUMMY_MAIN DummyClangFuzzer.cpp)4if(LLVM_LIB_FUZZING_ENGINE)5 unset(DUMMY_MAIN)6elseif(LLVM_USE_SANITIZE_COVERAGE)7 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer")8 set(CXX_FLAGS_NOFUZZ "${CXX_FLAGS_NOFUZZ} -fsanitize=fuzzer-no-link")9 unset(DUMMY_MAIN)10endif()11 12# Needed by LLVM's CMake checks because this file defines multiple targets.13set(LLVM_OPTIONAL_SOURCES14 ClangFuzzer.cpp15 ClangObjectiveCFuzzer.cpp16 DummyClangFuzzer.cpp17 ExampleClangProtoFuzzer.cpp18 ExampleClangLoopProtoFuzzer.cpp19 ExampleClangLLVMProtoFuzzer.cpp20 )21 22if(CLANG_ENABLE_PROTO_FUZZER)23 # Create protobuf .h and .cc files, and put them in a library for use by24 # clang-proto-fuzzer components.25 find_package(Protobuf REQUIRED)26 add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI)27 include_directories(${PROTOBUF_INCLUDE_DIRS})28 include_directories(${CMAKE_CURRENT_BINARY_DIR})29 protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS cxx_proto.proto)30 protobuf_generate_cpp(LOOP_PROTO_SRCS LOOP_PROTO_HDRS cxx_loop_proto.proto)31 set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES} ${PROTO_SRCS})32 add_clang_library(clangCXXProto33 ${PROTO_SRCS}34 ${PROTO_HDRS}35 36 LINK_LIBS37 ${PROTOBUF_LIBRARIES}38 )39 40 add_clang_library(clangCXXLoopProto41 ${LOOP_PROTO_SRCS}42 ${LOOP_PROTO_HDRS}43 44 LINK_LIBS45 ${PROTOBUF_LIBRARIES}46 )47 48 # Build and include libprotobuf-mutator49 include(ProtobufMutator)50 include_directories(${ProtobufMutator_INCLUDE_DIRS})51 52 # Build the protobuf->C++ translation library and driver.53 add_clang_subdirectory(proto-to-cxx)54 55 # Build the protobuf->LLVM IR translation library and driver.56 add_clang_subdirectory(proto-to-llvm)57 58 # Build the fuzzer initialization library.59 add_clang_subdirectory(fuzzer-initialize)60 61 # Build the protobuf fuzzer62 add_clang_executable(clang-proto-fuzzer63 ${DUMMY_MAIN}64 ExampleClangProtoFuzzer.cpp65 )66 67 # Build the loop protobuf fuzzer68 add_clang_executable(clang-loop-proto-fuzzer69 ${DUMMY_MAIN}70 ExampleClangLoopProtoFuzzer.cpp71 )72 73 # Build the llvm protobuf fuzzer74 add_clang_executable(clang-llvm-proto-fuzzer75 ${DUMMY_MAIN}76 ExampleClangLLVMProtoFuzzer.cpp77 )78 79 set(COMMON_PROTO_FUZZ_LIBRARIES80 ${ProtobufMutator_LIBRARIES}81 ${PROTOBUF_LIBRARIES}82 ${LLVM_LIB_FUZZING_ENGINE}83 clangFuzzerInitialize84 )85 86 target_link_libraries(clang-proto-fuzzer87 PRIVATE88 ${COMMON_PROTO_FUZZ_LIBRARIES}89 clangHandleCXX90 clangCXXProto91 clangProtoToCXX92 )93 target_link_libraries(clang-loop-proto-fuzzer94 PRIVATE95 ${COMMON_PROTO_FUZZ_LIBRARIES}96 clangHandleCXX97 clangCXXLoopProto98 clangLoopProtoToCXX99 )100 target_link_libraries(clang-llvm-proto-fuzzer101 PRIVATE102 ${COMMON_PROTO_FUZZ_LIBRARIES}103 clangHandleLLVM104 clangCXXLoopProto105 clangLoopProtoToLLVM106 )107 108endif()109 110add_clang_subdirectory(handle-cxx)111add_clang_subdirectory(handle-llvm)112add_clang_subdirectory(dictionary)113 114add_clang_executable(clang-fuzzer115 EXCLUDE_FROM_ALL116 ${DUMMY_MAIN}117 ClangFuzzer.cpp118 119 DEPENDS120 ClangDriverOptions121 )122 123target_link_libraries(clang-fuzzer124 PRIVATE125 ${LLVM_LIB_FUZZING_ENGINE}126 clangHandleCXX127 )128 129add_clang_executable(clang-objc-fuzzer130 EXCLUDE_FROM_ALL131 ${DUMMY_MAIN}132 ClangObjectiveCFuzzer.cpp133 134 DEPENDS135 ClangDriverOptions136 )137 138target_link_libraries(clang-objc-fuzzer139 PRIVATE140 ${LLVM_LIB_FUZZING_ENGINE}141 clangHandleCXX142 )143