xref: /openbsd-src/gnu/llvm/clang/tools/clang-fuzzer/CMakeLists.txt (revision 12c855180aad702bbcca06e0398d774beeafb155)
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_SOURCES
14  ClangFuzzer.cpp
15  ClangObjectiveCFuzzer.cpp
16  DummyClangFuzzer.cpp
17  ExampleClangProtoFuzzer.cpp
18  ExampleClangLoopProtoFuzzer.cpp
19  ExampleClangLLVMProtoFuzzer.cpp
20  )
21
22if(CLANG_ENABLE_PROTO_FUZZER)
23  # Create protobuf .h and .cc files, and put them in a library for use by
24  # 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(clangCXXProto
33    ${PROTO_SRCS}
34    ${PROTO_HDRS}
35
36    LINK_LIBS
37    ${PROTOBUF_LIBRARIES}
38    )
39
40  add_clang_library(clangCXXLoopProto
41    ${LOOP_PROTO_SRCS}
42    ${LOOP_PROTO_HDRS}
43
44    LINK_LIBS
45    ${PROTOBUF_LIBRARIES}
46    )
47
48  # Build and include libprotobuf-mutator
49  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 fuzzer
62  add_clang_executable(clang-proto-fuzzer
63    ${DUMMY_MAIN}
64    ExampleClangProtoFuzzer.cpp
65    )
66
67  # Build the loop protobuf fuzzer
68  add_clang_executable(clang-loop-proto-fuzzer
69    ${DUMMY_MAIN}
70    ExampleClangLoopProtoFuzzer.cpp
71    )
72
73  # Build the llvm protobuf fuzzer
74  add_clang_executable(clang-llvm-proto-fuzzer
75    ${DUMMY_MAIN}
76    ExampleClangLLVMProtoFuzzer.cpp
77    )
78
79  set(COMMON_PROTO_FUZZ_LIBRARIES
80    ${ProtobufMutator_LIBRARIES}
81    ${PROTOBUF_LIBRARIES}
82    ${LLVM_LIB_FUZZING_ENGINE}
83    clangFuzzerInitialize
84    )
85
86  target_link_libraries(clang-proto-fuzzer
87    PRIVATE
88    ${COMMON_PROTO_FUZZ_LIBRARIES}
89    clangHandleCXX
90    clangCXXProto
91    clangProtoToCXX
92    )
93  target_link_libraries(clang-loop-proto-fuzzer
94    PRIVATE
95    ${COMMON_PROTO_FUZZ_LIBRARIES}
96    clangHandleCXX
97    clangCXXLoopProto
98    clangLoopProtoToCXX
99    )
100  target_link_libraries(clang-llvm-proto-fuzzer
101    PRIVATE
102    ${COMMON_PROTO_FUZZ_LIBRARIES}
103    clangHandleLLVM
104    clangCXXLoopProto
105    clangLoopProtoToLLVM
106    )
107
108endif()
109
110add_clang_subdirectory(handle-cxx)
111add_clang_subdirectory(handle-llvm)
112add_clang_subdirectory(dictionary)
113
114add_clang_executable(clang-fuzzer
115  EXCLUDE_FROM_ALL
116  ${DUMMY_MAIN}
117  ClangFuzzer.cpp
118  )
119
120target_link_libraries(clang-fuzzer
121  PRIVATE
122  ${LLVM_LIB_FUZZING_ENGINE}
123  clangHandleCXX
124  )
125
126add_clang_executable(clang-objc-fuzzer
127  EXCLUDE_FROM_ALL
128  ${DUMMY_MAIN}
129  ClangObjectiveCFuzzer.cpp
130  )
131
132target_link_libraries(clang-objc-fuzzer
133  PRIVATE
134  ${LLVM_LIB_FUZZING_ENGINE}
135  clangHandleCXX
136  )
137