CMakeLists.txt 1.2 KB
Newer Older
1 2
# fuzzers: libFuzzer and standalone fuzzing utilities

3
if(BUILD_FUZZERS AND NOT USE_STANDALONE_FUZZERS)
4
	set(CMAKE_REQUIRED_FLAGS "-fsanitize=fuzzer-no-link")
5
	add_c_flag(-fsanitize=fuzzer)
6 7
	add_c_flag(-fsanitize=fuzzer-no-link)
	unset(CMAKE_REQUIRED_FLAGS)
8
endif()
9

10 11
file(GLOB SRC_FUZZERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_fuzzer.c)
foreach(fuzz_target_src ${SRC_FUZZERS})
12 13
	string(REPLACE ".c" "" fuzz_target_name ${fuzz_target_src})
	string(REPLACE "_fuzzer" "" fuzz_name ${fuzz_target_name})
14

15 16 17 18 19 20
	set(${fuzz_target_name}_SOURCES ${fuzz_target_src} ${LIBGIT2_OBJECTS})
	if(USE_STANDALONE_FUZZERS)
		list(APPEND ${fuzz_target_name}_SOURCES "standalone_driver.c")
	endif()
	add_executable(${fuzz_target_name} ${${fuzz_target_name}_SOURCES})
	set_target_properties(${fuzz_target_name} PROPERTIES C_STANDARD 90)
21 22 23 24 25

	target_include_directories(${fuzz_target_name} PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
	target_include_directories(${fuzz_target_name} SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})

	target_link_libraries(${fuzz_target_name} ${LIBGIT2_SYSTEM_LIBS})
26

27 28
	add_test(${fuzz_target_name} "${CMAKE_CURRENT_BINARY_DIR}/${fuzz_target_name}" "${CMAKE_CURRENT_SOURCE_DIR}/corpora/${fuzz_name}")
endforeach()