1 include(CompilerRTCompile)
3 set(LIBFUZZER_UNITTEST_CFLAGS
4 ${COMPILER_RT_UNITTEST_CFLAGS}
5 ${COMPILER_RT_GTEST_CFLAGS}
6 -I${COMPILER_RT_SOURCE_DIR}/lib/fuzzer
11 set(FUZZER_SUPPORTED_OS osx)
14 add_custom_target(FuzzerUnitTests)
15 set_target_properties(FuzzerUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
17 add_custom_target(FuzzedDataProviderUnitTests)
18 set_target_properties(FuzzedDataProviderUnitTests PROPERTIES FOLDER "Compiler-RT Tests")
20 set(LIBFUZZER_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS})
21 list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS --driver-mode=g++)
24 list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -Wl,-defaultlib:libcmt,-defaultlib:oldnames)
27 list(APPEND LIBFUZZER_UNITTEST_CFLAGS -isysroot ${DARWIN_osx_SYSROOT})
28 list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -isysroot ${DARWIN_osx_SYSROOT})
30 list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -lpthread)
33 if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
34 COMPILER_RT_LIBCXX_PATH AND
35 COMPILER_RT_LIBCXXABI_PATH)
36 list(APPEND LIBFUZZER_UNITTEST_CFLAGS -nostdinc++ -fno-exceptions)
37 list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -nostdlib++ -fno-exceptions)
40 if ("-fvisibility=hidden" IN_LIST LIBFUZZER_CFLAGS)
41 # Match visibility settings.
42 list(APPEND LIBFUZZER_UNITTEST_CFLAGS "-fvisibility=hidden")
45 if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST FUZZER_SUPPORTED_ARCH)
46 # libFuzzer unit tests are only run on the host machine.
47 set(arch ${COMPILER_RT_DEFAULT_TARGET_ARCH})
49 set(LIBFUZZER_TEST_RUNTIME RTFuzzerTest.${arch})
51 set(LIBFUZZER_TEST_RUNTIME_OBJECTS
52 $<TARGET_OBJECTS:RTfuzzer.osx>)
54 set(LIBFUZZER_TEST_RUNTIME_OBJECTS
55 $<TARGET_OBJECTS:RTfuzzer.${arch}>)
57 add_library(${LIBFUZZER_TEST_RUNTIME} STATIC
58 ${LIBFUZZER_TEST_RUNTIME_OBJECTS})
59 set_target_properties(${LIBFUZZER_TEST_RUNTIME} PROPERTIES
60 ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
61 FOLDER "Compiler-RT Runtime tests")
63 if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
64 COMPILER_RT_LIBCXX_PATH AND
65 COMPILER_RT_LIBCXXABI_PATH)
66 file(GLOB libfuzzer_headers ../*.h)
67 set(LIBFUZZER_TEST_RUNTIME_DEPS libcxx_fuzzer_${arch}-build ${libfuzzer_headers})
68 set(LIBFUZZER_TEST_RUNTIME_CFLAGS -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1)
69 set(LIBFUZZER_TEST_RUNTIME_LINK_FLAGS ${LIBCXX_${arch}_PREFIX}/lib/libc++.a)
72 set(FuzzerTestObjects)
73 generate_compiler_rt_tests(FuzzerTestObjects
74 FuzzerUnitTests "Fuzzer-${arch}-Test" ${arch}
75 SOURCES FuzzerUnittest.cpp ${COMPILER_RT_GTEST_SOURCE}
76 RUNTIME ${LIBFUZZER_TEST_RUNTIME}
77 DEPS llvm_gtest ${LIBFUZZER_TEST_RUNTIME_DEPS}
78 CFLAGS ${LIBFUZZER_UNITTEST_CFLAGS} ${LIBFUZZER_TEST_RUNTIME_CFLAGS}
79 LINK_FLAGS ${LIBFUZZER_UNITTEST_LINK_FLAGS} ${LIBFUZZER_TEST_RUNTIME_LINK_FLAGS})
80 set_target_properties(FuzzerUnitTests PROPERTIES
81 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
83 set(FuzzedDataProviderTestObjects)
84 generate_compiler_rt_tests(FuzzedDataProviderTestObjects
85 FuzzedDataProviderUnitTests "FuzzerUtils-${arch}-Test" ${arch}
86 SOURCES FuzzedDataProviderUnittest.cpp ${COMPILER_RT_GTEST_SOURCE}
87 DEPS llvm_gtest ${LIBFUZZER_TEST_RUNTIME_DEPS} ${COMPILER_RT_SOURCE_DIR}/include/fuzzer/FuzzedDataProvider.h
88 CFLAGS ${LIBFUZZER_UNITTEST_CFLAGS} ${LIBFUZZER_TEST_RUNTIME_CFLAGS}
89 LINK_FLAGS ${LIBFUZZER_UNITTEST_LINK_FLAGS} ${LIBFUZZER_TEST_RUNTIME_LINK_FLAGS})
90 set_target_properties(FuzzedDataProviderUnitTests PROPERTIES
91 RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})