fuzzing NEW refactor harness to enable LLVM LibFuzzer and more granular fuzzing

Refactor the harness to call LLVMFuzzerTestOneInput when using
AFL, and simultaneously enable standalone fuzzing with LibFuzzer,
which disables the main function of the harness, and uses
LLVMFuzzerTestOneInput directly.
diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt
index 8ed9c90..1e8cf7b 100644
--- a/tests/fuzz/CMakeLists.txt
+++ b/tests/fuzz/CMakeLists.txt
@@ -1,8 +1,17 @@
 cmake_minimum_required(VERSION 2.8.12)
 
-set(fuzz_targets yangfuzz)
+set(fuzz_targets lys_parse_mem buf_add_char yang_parse_module)
 
-foreach(target_name IN LISTS fuzz_targets)
-    add_executable(${target_name} ${target_name}.c)
-    target_link_libraries(${target_name} yang)
-endforeach(target_name)
+if(FUZZER STREQUAL "AFL")
+	foreach(target_name IN LISTS fuzz_targets)
+	    add_executable(${target_name} ${target_name}.c main.c $<TARGET_OBJECTS:yangobj>)
+	    target_link_libraries(${target_name} yang)
+	    target_link_libraries(${target_name} ${CMAKE_THREADS_LIB_INIT})
+	endforeach(target_name)
+elseif(FUZZER STREQUAL "LibFuzzer")
+	foreach(target_name IN LISTS fuzz_targets)
+		add_executable(${target_name} ${target_name}.c $<TARGET_OBJECTS:yangobj>)
+		set_source_files_properties(${target_name}.c PROPERTIES COMPILE_FLAGS "-fsanitize=fuzzer")
+	    	target_link_libraries(${target_name} yang "-fsanitize=fuzzer")
+	endforeach(target_name)
+endif()