1 | set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} FuzzMutate) |
2 | set(CXX_FLAGS_NOFUZZ ${CMAKE_CXX_FLAGS}) |
3 | set(DUMMY_MAIN DummyClangFuzzer.cpp) |
4 | if(LLVM_LIB_FUZZING_ENGINE) |
5 | unset(DUMMY_MAIN) |
6 | elseif(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) |
10 | endif() |
11 | |
12 | # Needed by LLVM's CMake checks because this file defines multiple targets. |
13 | set(LLVM_OPTIONAL_SOURCES |
14 | ClangFuzzer.cpp |
15 | DummyClangFuzzer.cpp |
16 | ExampleClangProtoFuzzer.cpp |
17 | ExampleClangLoopProtoFuzzer.cpp |
18 | ExampleClangLLVMProtoFuzzer.cpp |
19 | ) |
20 | |
21 | if(CLANG_ENABLE_PROTO_FUZZER) |
22 | # Create protobuf .h and .cc files, and put them in a library for use by |
23 | # clang-proto-fuzzer components. |
24 | find_package(Protobuf REQUIRED) |
25 | add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI) |
26 | include_directories(${PROTOBUF_INCLUDE_DIRS}) |
27 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
28 | protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS cxx_proto.proto) |
29 | protobuf_generate_cpp(LOOP_PROTO_SRCS LOOP_PROTO_HDRS cxx_loop_proto.proto) |
30 | set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES} ${PROTO_SRCS}) |
31 | add_clang_library(clangCXXProto |
32 | ${PROTO_SRCS} |
33 | ${PROTO_HDRS} |
34 | |
35 | LINK_LIBS |
36 | ${PROTOBUF_LIBRARIES} |
37 | ) |
38 | |
39 | add_clang_library(clangCXXLoopProto |
40 | ${LOOP_PROTO_SRCS} |
41 | ${LOOP_PROTO_HDRS} |
42 | |
43 | LINK_LIBS |
44 | ${PROTOBUF_LIBRARIES} |
45 | ) |
46 | |
47 | # Build and include libprotobuf-mutator |
48 | include(ProtobufMutator) |
49 | include_directories(${ProtobufMutator_INCLUDE_DIRS}) |
50 | |
51 | # Build the protobuf->C++ translation library and driver. |
52 | add_clang_subdirectory(proto-to-cxx) |
53 | |
54 | # Build the protobuf->LLVM IR translation library and driver. |
55 | add_clang_subdirectory(proto-to-llvm) |
56 | |
57 | # Build the fuzzer initialization library. |
58 | add_clang_subdirectory(fuzzer-initialize) |
59 | |
60 | # Build the protobuf fuzzer |
61 | add_clang_executable(clang-proto-fuzzer |
62 | ${DUMMY_MAIN} |
63 | ExampleClangProtoFuzzer.cpp |
64 | ) |
65 | |
66 | # Build the loop protobuf fuzzer |
67 | add_clang_executable(clang-loop-proto-fuzzer |
68 | ${DUMMY_MAIN} |
69 | ExampleClangLoopProtoFuzzer.cpp |
70 | ) |
71 | |
72 | # Build the llvm protobuf fuzzer |
73 | add_clang_executable(clang-llvm-proto-fuzzer |
74 | ${DUMMY_MAIN} |
75 | ExampleClangLLVMProtoFuzzer.cpp |
76 | ) |
77 | |
78 | set(COMMON_PROTO_FUZZ_LIBRARIES |
79 | ${ProtobufMutator_LIBRARIES} |
80 | ${PROTOBUF_LIBRARIES} |
81 | ${LLVM_LIB_FUZZING_ENGINE} |
82 | clangFuzzerInitialize |
83 | ) |
84 | |
85 | target_link_libraries(clang-proto-fuzzer |
86 | PRIVATE |
87 | ${COMMON_PROTO_FUZZ_LIBRARIES} |
88 | clangHandleCXX |
89 | clangCXXProto |
90 | clangProtoToCXX |
91 | ) |
92 | target_link_libraries(clang-loop-proto-fuzzer |
93 | PRIVATE |
94 | ${COMMON_PROTO_FUZZ_LIBRARIES} |
95 | clangHandleCXX |
96 | clangCXXLoopProto |
97 | clangLoopProtoToCXX |
98 | ) |
99 | target_link_libraries(clang-llvm-proto-fuzzer |
100 | PRIVATE |
101 | ${COMMON_PROTO_FUZZ_LIBRARIES} |
102 | clangHandleLLVM |
103 | clangCXXLoopProto |
104 | clangLoopProtoToLLVM |
105 | ) |
106 | |
107 | endif() |
108 | |
109 | add_clang_subdirectory(handle-cxx) |
110 | add_clang_subdirectory(handle-llvm) |
111 | |
112 | add_clang_executable(clang-fuzzer |
113 | EXCLUDE_FROM_ALL |
114 | ${DUMMY_MAIN} |
115 | ClangFuzzer.cpp |
116 | ) |
117 | |
118 | target_link_libraries(clang-fuzzer |
119 | PRIVATE |
120 | ${LLVM_LIB_FUZZING_ENGINE} |
121 | clangHandleCXX |
122 | ) |
123 | |