blob: f4df57271881102eba7c2f3b9c4d2bd844a10833 [file] [log] [blame]
Juraj Vijtiukf3939c92019-05-14 13:07:38 +02001cmake_minimum_required(VERSION 2.8.12)
2
Juraj Vijtiukd7989422020-09-15 13:54:00 +02003if (ENABLE_FUZZ_TARGETS)
4 set(fuzz_targets lys_parse_mem lyd_parse_mem buf_add_char yang_parse_module)
Juraj Vijtiukf3939c92019-05-14 13:07:38 +02005
Juraj Vijtiukd7989422020-09-15 13:54:00 +02006 if(FUZZER STREQUAL "AFL")
7 foreach(target_name IN LISTS fuzz_targets)
Juraj Vijtiuk2bab6f22020-09-24 13:55:53 +02008 add_executable(${target_name}_fuzz_harness ${target_name}.c main.c $<TARGET_OBJECTS:yangobj>)
9 target_link_libraries(${target_name}_fuzz_harness yang)
10 target_link_libraries(${target_name}_fuzz_harness ${CMAKE_THREADS_LIB_INIT})
Juraj Vijtiukd7989422020-09-15 13:54:00 +020011 endforeach(target_name)
12 elseif(FUZZER STREQUAL "LibFuzzer")
13 foreach(target_name IN LISTS fuzz_targets)
Juraj Vijtiuk2bab6f22020-09-24 13:55:53 +020014 add_executable(${target_name}_fuzz_harness ${target_name}.c $<TARGET_OBJECTS:yangobj>)
Juraj Vijtiukd7989422020-09-15 13:54:00 +020015 set_source_files_properties(${target_name}.c PROPERTIES COMPILE_FLAGS "-fsanitize=fuzzer")
Juraj Vijtiuk2bab6f22020-09-24 13:55:53 +020016 target_link_libraries(${target_name}_fuzz_harness yang "-fsanitize=fuzzer")
Juraj Vijtiukd7989422020-09-15 13:54:00 +020017 endforeach(target_name)
18 endif()
19endif()
20
Juraj Vijtiukbef5faf2020-09-16 15:40:02 +020021if (ENABLE_BUILD_TESTS)
Juraj Vijtiukd7989422020-09-15 13:54:00 +020022 add_executable(fuzz_regression_test fuzz_regression_test.c)
23 set(fuzz_regression_tests lys_parse_mem lyd_parse_mem)
24 foreach(target_name IN LISTS fuzz_regression_tests)
25 file(COPY ${CMAKE_SOURCE_DIR}/tests/fuzz/corpus/${target_name} DESTINATION ${CMAKE_BINARY_DIR}/tests/fuzz/)
Juraj Vijtiuk419cdc62020-09-28 12:43:20 +020026 add_executable(regress_fuzz_${target_name} ${target_name}.c main.c $<TARGET_OBJECTS:yangobj>)
27 set_target_properties(regress_fuzz_${target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests/fuzz/${target_name}")
28 target_link_libraries(regress_fuzz_${target_name} yang)
29 target_link_libraries(regress_fuzz_${target_name} ${CMAKE_THREADS_LIB_INIT})
30 add_test(NAME regress_fuzz_${target_name} COMMAND fuzz_regression_test regress_fuzz_${target_name} . WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/tests/fuzz/${target_name})
Juraj Vijtiuk260407e2020-03-18 10:32:13 +010031 endforeach(target_name)
32endif()