From 9234a1df46e67cbe2b56b6697f24a5a97e41fe62 Mon Sep 17 00:00:00 2001 From: Alessandro Gario Date: Sat, 27 Jul 2019 17:08:35 +0200 Subject: [PATCH 1/6] CMake: Add support for all the main targets --- CMakeLists.txt | 267 ++++++++++++++++++++++++++++++++++++++++++++ cmake/options.cmake | 1 + cmake/utils.cmake | 106 ++++++++++++++++++ 3 files changed, 374 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/options.cmake create mode 100644 cmake/utils.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..bc37b39a5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,267 @@ +cmake_minimum_required(VERSION 3.10) +project(afl) + +include(cmake/options.cmake) +include(cmake/utils.cmake) + +set(common_header_list + alloc-inl.h + config.h + debug.h + types.h +) + +function(aflMain) + getProjectVersion(afl_version) + printUserMessages() + + generateCompilerTester() + generateSettingsTarget() + + generateCompilerWrappers() + generateAssemblerWrapper() + generateAFLTargets() + + generateBuildTester() + generateInstallTargets() +endfunction() + +function(printUserMessages) + message(STATUS "Building version: ${afl_version}") + + if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") + message(WARNING "LLVM users: see llvm_mode/README.llvm for a faster alternative to afl-gcc.") + endif() + + if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") + message(WARNING "Fuzzing on MacOS X is slow because of the unusually high overhead of fork() on this OS. Consider using Linux or *BSD. You can also use VirtualBox (virtualbox.org) to put AFL inside a Linux or *BSD VM.") + endif() +endfunction() + +function(generateCompilerWrappers) + # Generate the base wrapper + add_executable(afl-gcc + ${common_header_list} + afl-gcc.c + ) + + dependOnCompilerTest(afl-gcc) + target_link_libraries(afl-gcc PRIVATE c_settings) + + # Create the symbolic links + set(wrapper_list + afl-g++ + afl-clang + afl-clang++ + ) + + foreach(wrapper ${wrapper_list}) + set(link_destination "${CMAKE_CURRENT_BINARY_DIR}/${wrapper}") + + add_custom_command( + OUTPUT "${link_destination}" + COMMAND "${CMAKE_COMMAND}" -E create_symlink afl-gcc "${wrapper}" + COMMENT "Generating: '${wrapper}' symlink" + WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + VERBATIM + ) + + add_custom_target( + "${wrapper}_generator" + DEPENDS "${link_destination}" + ) + + add_dependencies(afl-gcc "${wrapper}_generator") + endforeach() +endfunction() + +function(generateAssemblerWrapper) + # Generate the base executable + add_executable(afl-as + ${common_header_list} + afl-as.h + afl-as.c + ) + + dependOnCompilerTest(afl-as) + target_link_libraries(afl-as PRIVATE c_settings) + + # Generate the symbolic link + set(link_destination "${CMAKE_CURRENT_BINARY_DIR}/as") + + add_custom_command( + OUTPUT "${link_destination}" + COMMAND "${CMAKE_COMMAND}" -E create_symlink afl-as as + COMMENT "Generating: 'as' symlink" + VERBATIM + ) + + add_custom_target(as_generator + DEPENDS "${link_destination}" + ) + + add_dependencies(afl-as as_generator) +endfunction() + +function(generateAFLTargetHelper base_target_name) + set(target_name "afl-${base_target_name}") + set(source_file_name "${target_name}.c") + + add_executable("${target_name}" + ${common_header_list} + "${source_file_name}" + ) + + dependOnCompilerTest("${target_name}") + target_link_libraries("${target_name}" PRIVATE c_settings) +endfunction() + +function(generateAFLTargets) + set(afl_target_list + fuzz + showmap + tmin + analyze + gotcpu + ) + + foreach(afl_target ${afl_target_list}) + generateAFLTargetHelper("${afl_target}") + endforeach() +endfunction() + +function(generateBuildTester) + # Select the wrapper + if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") + set(compiler "afl-clang") + else() + set(compiler "afl-gcc") + endif() + + set(compiler "${CMAKE_CURRENT_BINARY_DIR}/${compiler}") + + # Gather the flags we have both from the environment and from our settings + get_target_property(compile_option_list c_settings INTERFACE_COMPILE_OPTIONS) + if("${compile_option_list}" STREQUAL "compile_option_list-NOTFOUND") + unset(compile_option_list) + endif() + + list(APPEND compile_option_list $ENV{CFLAGS}) + + get_target_property(link_libs c_settings INTERFACE_LINK_LIBRARIES) + if("${link_libs}" STREQUAL "link_libs-NOTFOUND") + unset(link_libs) + endif() + + get_target_property(link_opts c_settings INTERFACE_LINK_OPTIONS) + if("${link_opts}" STREQUAL "link_opts-NOTFOUND") + unset(link_opts) + endif() + + foreach(link_option ${link_libs} ${link_opts}) + if(TARGET "${link_option}") + continue() + endif() + + if("${link_option}" STREQUAL "${CMAKE_DL_LIBS}") + continue() + endif() + + list(APPEND link_option_list "${link_option}") + endforeach() + + list(APPEND link_option_list $ENV{LDFLAGS}) + + # Compile the test binary + set(test_binary_path "${CMAKE_CURRENT_BINARY_DIR}/test-instr") + + add_custom_command( + OUTPUT "${test_binary_path}" + COMMAND "${CMAKE_COMMAND}" -E env --unset=AFL_USE_ASAN --unset=AFL_USE_MSAN AFL_QUIET=1 AFL_INST_RATIO=100 AFL_PATH="${CMAKE_CURRENT_BINARY_DIR}" "${compiler}" ${compile_option_list} "${CMAKE_CURRENT_SOURCE_DIR}/test-instr.c" -o "${test_binary_path}" ${link_option_list} + COMMENT "Generating: test-instr" + VERBATIM + ) + + add_custom_target(test-instr_generator + DEPENDS "${test_binary_path}" + ) + + add_dependencies(test-instr_generator + afl-gcc + afl-as + ) + + # Create the afl-showmap runners + set(showmap_output_path0 "${CMAKE_CURRENT_BINARY_DIR}/.test-instr0") + set(showmap_output_path1 "${CMAKE_CURRENT_BINARY_DIR}/.test-instr1") + + add_custom_command( + OUTPUT "${showmap_output_path0}" "${showmap_output_path1}" + COMMAND "${CMAKE_COMMAND}" -E echo "0" | "$" -m none -q -o "${showmap_output_path0}" "${test_binary_path}" + COMMAND "${CMAKE_COMMAND}" -E echo "1" | "$" -m none -q -o "${showmap_output_path1}" "${test_binary_path}" + COMMAND "${CMAKE_COMMAND}" -E compare_files "${showmap_output_path0}" "${showmap_output_path1}" + COMMENT "Testing the build" + VERBATIM + ) + + add_custom_target( + test_build + DEPENDS "${showmap_output_path0}" "${showmap_output_path1}" + ) + + add_dependencies(test_build test-instr_generator) +endfunction() + +function(generateInstallTargets) + # Targets, symlinks, scripts + set(target_list + afl-gcc + afl-fuzz + afl-showmap + afl-tmin + afl-analyze + afl-gotcpu + afl-as + ) + + set(source_file_list + afl-plot + afl-cmin + afl-whatsup + ) + + set(binary_file_list + afl-clang + afl-clang++ + afl-g++ + as + ) + + set(helper_binary_file_list + afl-as + ) + + install(TARGETS ${target_list} DESTINATION "bin") + + foreach(source_file ${source_file_list}) + install(FILES "${source_file}" DESTINATION "bin" PERMISSIONS WORLD_READ WORLD_EXECUTE) + endforeach() + + foreach(binary_file ${binary_file_list}) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${binary_file}" DESTINATION "bin") + endforeach() + + foreach(binary_file ${helper_binary_file_list}) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${binary_file}" DESTINATION "lib/afl") + endforeach() + + # Documentation + install(FILES "docs/README" "docs/ChangeLog" DESTINATION "share/doc/afl") + install(DIRECTORY "docs/" DESTINATION "share/doc/afl" FILES_MATCHING PATTERN "*.txt") + + # Tests + install(DIRECTORY "testcases/" DESTINATION "share/afl" FILES_MATCHING PATTERN "*") + install(DIRECTORY "dictionaries/" DESTINATION "share/afl" FILES_MATCHING PATTERN "*") +endfunction() + +aflMain() diff --git a/cmake/options.cmake b/cmake/options.cmake new file mode 100644 index 000000000..579d85521 --- /dev/null +++ b/cmake/options.cmake @@ -0,0 +1 @@ +option(AFL_NO_X86 "Set to ON to skip the compiler test") diff --git a/cmake/utils.cmake b/cmake/utils.cmake new file mode 100644 index 000000000..a80ce33ac --- /dev/null +++ b/cmake/utils.cmake @@ -0,0 +1,106 @@ +cmake_minimum_required(VERSION 3.10) + +function(getProjectVersion output_variable) + file(READ "${CMAKE_SOURCE_DIR}/config.h" config_header_contents) + if("${config_header_contents}" STREQUAL "") + set("${output_variable}" "${output_variable}-NOTFOUND" PARENT_SCOPE) + return() + endif() + + string(FIND "${config_header_contents}" "#define VERSION" definition_index) + if(${definition_index} EQUAL -1) + set("${output_variable}" "${output_variable}-NOTFOUND" PARENT_SCOPE) + return() + endif() + + string(SUBSTRING "${config_header_contents}" ${definition_index} -1 config_header_contents) + + string(FIND "${config_header_contents}" "\"" version_start_index) + if(${version_start_index} EQUAL -1) + set("${output_variable}" "${output_variable}-NOTFOUND" PARENT_SCOPE) + return() + endif() + + math(EXPR version_start_index "${version_start_index} + 1") + + string(SUBSTRING "${config_header_contents}" ${version_start_index} -1 config_header_contents) + + string(FIND "${config_header_contents}" "\"" version_end_index) + if(${version_end_index} EQUAL -1) + set("${output_variable}" "${output_variable}-NOTFOUND" PARENT_SCOPE) + return() + endif() + + string(SUBSTRING "${config_header_contents}" 0 ${version_end_index} version_field) + + if("${version_field}" STREQUAL "") + set("${output_variable}" "${output_variable}-NOTFOUND" PARENT_SCOPE) + return() + endif() + + set("${output_variable}" "${version_field}" PARENT_SCOPE) +endfunction() + +function(generateCompilerTester) + if(AFL_NO_X86) + message(WARNING "Note: skipping x86 compilation checks (AFL_NO_X86 set)") + return() + endif() + + set(compiler_test_source "main() { __asm__(\"xorb %al, %al\"); }") + set(compiler_test_source_path "${CMAKE_CURRENT_BINARY_DIR}/test_x86.c") + + add_custom_command( + OUTPUT "${compiler_test_source_path}" + COMMAND "${CMAKE_COMMAND}" -E echo "${compiler_test_source}" > "${compiler_test_source_path}" + COMMENT "Generating: test_x86.c" + VERBATIM + ) + + add_custom_target( + test_x86_generator + DEPENDS "${compiler_test_source_path}" + ) + + set(compiler_test_output_path "${CMAKE_CURRENT_BINARY_DIR}/test_x86.o") + set(compiler_test_log_path "${CMAKE_CURRENT_BINARY_DIR}/test_x86.txt") + + add_custom_command( + OUTPUT "${compiler_test_output_path}" + COMMAND "${CMAKE_C_COMPILER}" -w -x c -c "${compiler_test_source_path}" -o "${compiler_test_output_path}" > "${compiler_test_log_path}" + COMMENT "Testing compiler: ${CMAKE_C_COMPILER} (log: ${compiler_test_log_path})" + VERBATIM + ) + + add_custom_target( + test_x86_runner + DEPENDS "${compiler_test_output_path}" + ) + + add_dependencies(test_x86_runner test_x86_generator) +endfunction() + +function(dependOnCompilerTest target_name) + add_dependencies("${target_name}" test_x86_runner) +endfunction() + +function(generateSettingsTarget) + add_library(c_settings INTERFACE) + + target_compile_options(c_settings INTERFACE + -O3 + -funroll-loops + -Wall + -g + -Wno-pointer-sign + ) + + target_compile_definitions(c_settings INTERFACE + _FORTIFY_SOURCE=2 + AFL_PATH=\"${CMAKE_INSTALL_PREFIX}/lib/afl\" + DOC_PATH=\"${CMAKE_INSTALL_PREFIX}/share/doc/afl\" + BIN_PATH=\"${CMAKE_INSTALL_PREFIX}/bin\" + ) + + target_link_libraries(c_settings INTERFACE ${CMAKE_DL_LIBS}) +endfunction() \ No newline at end of file From bfc1177114aa8d5a854ab0229c9090ecd481ead3 Mon Sep 17 00:00:00 2001 From: Alessandro Gario Date: Sat, 27 Jul 2019 17:50:03 +0200 Subject: [PATCH 2/6] CMake: Add packaging support --- CMakeLists.txt | 10 ++++------ cmake/packaging.cmake | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 cmake/packaging.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index bc37b39a5..312ed13cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(afl) include(cmake/options.cmake) include(cmake/utils.cmake) +include(cmake/packaging.cmake) set(common_header_list alloc-inl.h @@ -12,7 +13,6 @@ set(common_header_list ) function(aflMain) - getProjectVersion(afl_version) printUserMessages() generateCompilerTester() @@ -27,8 +27,6 @@ function(aflMain) endfunction() function(printUserMessages) - message(STATUS "Building version: ${afl_version}") - if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang") message(WARNING "LLVM users: see llvm_mode/README.llvm for a faster alternative to afl-gcc.") endif() @@ -225,8 +223,8 @@ function(generateInstallTargets) ) set(source_file_list - afl-plot - afl-cmin + #afl-plot + #afl-cmin afl-whatsup ) @@ -244,7 +242,7 @@ function(generateInstallTargets) install(TARGETS ${target_list} DESTINATION "bin") foreach(source_file ${source_file_list}) - install(FILES "${source_file}" DESTINATION "bin" PERMISSIONS WORLD_READ WORLD_EXECUTE) + install(FILES ${source_file_list} DESTINATION "bin" PERMISSIONS WORLD_READ WORLD_EXECUTE) endforeach() foreach(binary_file ${binary_file_list}) diff --git a/cmake/packaging.cmake b/cmake/packaging.cmake new file mode 100644 index 000000000..eee36ba56 --- /dev/null +++ b/cmake/packaging.cmake @@ -0,0 +1,36 @@ +getProjectVersion(afl_version) +message(STATUS "AFL version: ${afl_version}") + +SET(CPACK_GENERATOR "DEB;TGZ;ZIP") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "AFL") +set(CPACK_PACKAGE_VENDOR "Google") +set(CPACK_PACKAGE_DESCRIPTION "Security-oriented fuzzer using compile-time instrumentation and genetic algorithms") +SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") + +execute_process( + COMMAND git config --global user.name + RESULT_VARIABLE user_name +) + +execute_process( + COMMAND git config --global user.email + RESULT_VARIABLE user_email +) + +if(NOT "${user_name}" STREQUAL "" AND NOT "${user_email}" STREQUAL "") + set(CPACK_PACKAGE_CONTACT "${user_name} <${user_email}>") +else() + message(WARNING "Setting a dummy maintainer") + set(CPACK_PACKAGE_CONTACT "N/A") +endif() + +string(REPLACE "." ";" version_components "${afl_version}") +list(GET version_components 0 CPACK_PACKAGE_VERSION_MAJOR) + +list(GET version_components 1 version_components) +string(SUBSTRING "${version_components}" 0 2 CPACK_PACKAGE_VERSION_MINOR) +string(SUBSTRING "${version_components}" 2 1 CPACK_PACKAGE_VERSION_PATCH) + +include(CPack) + +message(STATUS "When creating packages, make sure that `make package` is run as root!") From f33fdb8a7f08279033a6cff31f05e66c1e4c872b Mon Sep 17 00:00:00 2001 From: Alessandro Gario Date: Fri, 2 Aug 2019 00:57:12 +0200 Subject: [PATCH 3/6] CMake: Add copyright headers --- CMakeLists.txt | 13 +++++++++++++ cmake/options.cmake | 13 +++++++++++++ cmake/packaging.cmake | 13 +++++++++++++ cmake/utils.cmake | 15 ++++++++++++++- 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 312ed13cd..e083bae02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,16 @@ +# +# Copyright 2013-present Google Inc. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + cmake_minimum_required(VERSION 3.10) project(afl) diff --git a/cmake/options.cmake b/cmake/options.cmake index 579d85521..5b65897f9 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -1 +1,14 @@ +# +# Copyright 2013-present Google Inc. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + option(AFL_NO_X86 "Set to ON to skip the compiler test") diff --git a/cmake/packaging.cmake b/cmake/packaging.cmake index eee36ba56..90c816c4c 100644 --- a/cmake/packaging.cmake +++ b/cmake/packaging.cmake @@ -1,3 +1,16 @@ +# +# Copyright 2013-present Google Inc. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + getProjectVersion(afl_version) message(STATUS "AFL version: ${afl_version}") diff --git a/cmake/utils.cmake b/cmake/utils.cmake index a80ce33ac..31cfee50d 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -1,3 +1,16 @@ +# +# Copyright 2013-present Google Inc. All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# http://www.apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + cmake_minimum_required(VERSION 3.10) function(getProjectVersion output_variable) @@ -103,4 +116,4 @@ function(generateSettingsTarget) ) target_link_libraries(c_settings INTERFACE ${CMAKE_DL_LIBS}) -endfunction() \ No newline at end of file +endfunction() From 62d3706cc34f367b2142931325bea0236de57d0b Mon Sep 17 00:00:00 2001 From: Alessandro Gario Date: Fri, 2 Aug 2019 00:59:43 +0200 Subject: [PATCH 4/6] CMake: Fix macOS packaging issue --- cmake/packaging.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/packaging.cmake b/cmake/packaging.cmake index 90c816c4c..48bb4f32e 100644 --- a/cmake/packaging.cmake +++ b/cmake/packaging.cmake @@ -14,11 +14,16 @@ getProjectVersion(afl_version) message(STATUS "AFL version: ${afl_version}") -SET(CPACK_GENERATOR "DEB;TGZ;ZIP") +if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") + set(CPACK_GENERATOR "ZIP") +else() + set(CPACK_GENERATOR "DEB;TGZ;ZIP") +endif() + set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "AFL") set(CPACK_PACKAGE_VENDOR "Google") set(CPACK_PACKAGE_DESCRIPTION "Security-oriented fuzzer using compile-time instrumentation and genetic algorithms") -SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") +set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}") execute_process( COMMAND git config --global user.name From 481c7f7cbc8e913307e75c8e8f1aa29120d4faa8 Mon Sep 17 00:00:00 2001 From: Alessandro Gario Date: Fri, 2 Aug 2019 01:08:37 +0200 Subject: [PATCH 5/6] CMake: Make sure the git output does not leak to stdout --- cmake/packaging.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/packaging.cmake b/cmake/packaging.cmake index 48bb4f32e..07ff46c95 100644 --- a/cmake/packaging.cmake +++ b/cmake/packaging.cmake @@ -28,11 +28,13 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSIO execute_process( COMMAND git config --global user.name RESULT_VARIABLE user_name + OUTPUT_QUIET ) execute_process( COMMAND git config --global user.email RESULT_VARIABLE user_email + OUTPUT_QUIET ) if(NOT "${user_name}" STREQUAL "" AND NOT "${user_email}" STREQUAL "") From 3a89c214c07d20b3eb8798bf568496b1381eb321 Mon Sep 17 00:00:00 2001 From: Alessandro Gario Date: Fri, 2 Aug 2019 01:20:46 +0200 Subject: [PATCH 6/6] CMake: Improve the test_build target --- CMakeLists.txt | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e083bae02..f8551e11f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,23 +204,54 @@ function(generateBuildTester) # Create the afl-showmap runners set(showmap_output_path0 "${CMAKE_CURRENT_BINARY_DIR}/.test-instr0") - set(showmap_output_path1 "${CMAKE_CURRENT_BINARY_DIR}/.test-instr1") add_custom_command( - OUTPUT "${showmap_output_path0}" "${showmap_output_path1}" + OUTPUT "${showmap_output_path0}" COMMAND "${CMAKE_COMMAND}" -E echo "0" | "$" -m none -q -o "${showmap_output_path0}" "${test_binary_path}" + COMMENT "Generating: ${showmap_output_path0}" + VERBATIM + ) + + add_custom_target( + test-instr0_generator + DEPENDS "${showmap_output_path0}" + ) + + add_dependencies(test-instr0_generator + afl-showmap + test-instr_generator + ) + + set(showmap_output_path1 "${CMAKE_CURRENT_BINARY_DIR}/.test-instr1") + + add_custom_command( + OUTPUT "${showmap_output_path1}" COMMAND "${CMAKE_COMMAND}" -E echo "1" | "$" -m none -q -o "${showmap_output_path1}" "${test_binary_path}" - COMMAND "${CMAKE_COMMAND}" -E compare_files "${showmap_output_path0}" "${showmap_output_path1}" - COMMENT "Testing the build" + COMMENT "Generating: ${showmap_output_path1}" VERBATIM ) + add_custom_target( + test-instr1_generator + DEPENDS "${showmap_output_path1}" + ) + + add_dependencies(test-instr1_generator + afl-showmap + test-instr_generator + ) + add_custom_target( test_build - DEPENDS "${showmap_output_path0}" "${showmap_output_path1}" + COMMAND "${CMAKE_COMMAND}" -E compare_files "${showmap_output_path0}" "${showmap_output_path1}" 2> /dev/null || "${CMAKE_COMMAND}" -E echo "All right, the instrumentation seems to be working!" + COMMENT "Testing the build" + VERBATIM ) - add_dependencies(test_build test-instr_generator) + add_dependencies(test_build + test-instr0_generator + test-instr1_generator + ) endfunction() function(generateInstallTargets)