[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / tools / clang-fuzzer / CMakeLists.txt
blobe68ed8bbcb0694327f5b1eed847bbba3a7d497af
1 set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} FuzzerCLI)
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()
12 # Needed by LLVM's CMake checks because this file defines multiple targets.
13 set(LLVM_OPTIONAL_SOURCES
14   ClangFuzzer.cpp
15   ClangObjectiveCFuzzer.cpp
16   DummyClangFuzzer.cpp
17   ExampleClangProtoFuzzer.cpp
18   ExampleClangLoopProtoFuzzer.cpp
19   ExampleClangLLVMProtoFuzzer.cpp
20   )
22 if(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}
36     LINK_LIBS
37     ${PROTOBUF_LIBRARIES}
38     )
40   add_clang_library(clangCXXLoopProto
41     ${LOOP_PROTO_SRCS}
42     ${LOOP_PROTO_HDRS}
44     LINK_LIBS
45     ${PROTOBUF_LIBRARIES}
46     )
48   # Build and include libprotobuf-mutator
49   include(ProtobufMutator)
50   include_directories(${ProtobufMutator_INCLUDE_DIRS})
52   # Build the protobuf->C++ translation library and driver.
53   add_clang_subdirectory(proto-to-cxx)
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)
61   # Build the protobuf fuzzer
62   add_clang_executable(clang-proto-fuzzer
63     ${DUMMY_MAIN}
64     ExampleClangProtoFuzzer.cpp
65     )
67   # Build the loop protobuf fuzzer
68   add_clang_executable(clang-loop-proto-fuzzer
69     ${DUMMY_MAIN}
70     ExampleClangLoopProtoFuzzer.cpp
71     )
73   # Build the llvm protobuf fuzzer
74   add_clang_executable(clang-llvm-proto-fuzzer
75     ${DUMMY_MAIN}
76     ExampleClangLLVMProtoFuzzer.cpp
77     )
79   set(COMMON_PROTO_FUZZ_LIBRARIES
80     ${ProtobufMutator_LIBRARIES}
81     ${PROTOBUF_LIBRARIES}
82     ${LLVM_LIB_FUZZING_ENGINE}
83     clangFuzzerInitialize
84     )
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     )
108 endif()
110 add_clang_subdirectory(handle-cxx)
111 add_clang_subdirectory(handle-llvm)
112 add_clang_subdirectory(dictionary)
114 add_clang_executable(clang-fuzzer
115   EXCLUDE_FROM_ALL
116   ${DUMMY_MAIN}
117   ClangFuzzer.cpp
118   )
120 target_link_libraries(clang-fuzzer
121   PRIVATE
122   ${LLVM_LIB_FUZZING_ENGINE}
123   clangHandleCXX
124   )
126 add_clang_executable(clang-objc-fuzzer
127   EXCLUDE_FROM_ALL
128   ${DUMMY_MAIN}
129   ClangObjectiveCFuzzer.cpp
130   )
132 target_link_libraries(clang-objc-fuzzer
133   PRIVATE
134   ${LLVM_LIB_FUZZING_ENGINE}
135   clangHandleCXX
136   )