1# SPDX-License-Identifier: BSD-3-Clause 2 3cmake_minimum_required(VERSION 3.10) 4 5project(SOF_FUZZ_IPC C) 6 7include(../../scripts/cmake/misc.cmake) 8 9add_executable(fuzz_ipc 10 fuzz_ipc.c 11) 12 13sof_append_relative_path_definitions(fuzz_ipc) 14 15set(sof_source_directory "${PROJECT_SOURCE_DIR}/../..") 16set(sof_install_directory "${PROJECT_BINARY_DIR}/sof_ep/install") 17set(sof_binary_directory "${PROJECT_BINARY_DIR}/sof_ep/build") 18 19set(config_h ${sof_binary_directory}/library_autoconfig.h) 20 21target_compile_options(fuzz_ipc PRIVATE -g -O3 -Wall -Werror -Wmissing-prototypes 22 -Wimplicit-fallthrough -DCONFIG_LIBRARY -imacros${config_h}) 23 24target_link_libraries(fuzz_ipc PRIVATE -ldl -lm) 25 26install(TARGETS fuzz_ipc DESTINATION bin) 27 28if(NOT DEFINED ENV{OUT}) 29 message(FATAL_ERROR 30 "Missing key env vars, please only build with oss-fuzz, see README in tools/oss-fuzz") 31endif() 32 33include(ExternalProject) 34 35ExternalProject_Add(sof_ep 36 DOWNLOAD_COMMAND "" 37 SOURCE_DIR "${sof_source_directory}" 38 PREFIX "${PROJECT_BINARY_DIR}/sof_ep" 39 BINARY_DIR "${sof_binary_directory}" 40 CMAKE_ARGS -DCONFIG_LIBRARY=ON 41 -DCONFIG_LIBRARY_STATIC=ON 42 -DCMAKE_INSTALL_PREFIX=${sof_install_directory} 43 -DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE} 44 -DCONFIG_H_PATH=${config_h} 45 -DINIT_CONFIG=library_defconfig 46 BUILD_ALWAYS 1 47 BUILD_BYPRODUCTS "${sof_install_directory}/lib/libsof.so" 48) 49 50add_library(sof_library STATIC IMPORTED) 51set_target_properties(sof_library PROPERTIES IMPORTED_LOCATION "${sof_install_directory}/lib/libsof.a") 52add_dependencies(sof_library sof_ep) 53 54target_link_libraries(fuzz_ipc PRIVATE sof_library) 55target_include_directories(fuzz_ipc PRIVATE ${sof_install_directory}/include) 56target_link_options(fuzz_ipc PUBLIC $ENV{LIB_FUZZING_ENGINE}) 57set_target_properties(fuzz_ipc PROPERTIES RUNTIME_OUTPUT_DIRECTORY $ENV{OUT}) 58 59set_target_properties(fuzz_ipc 60 PROPERTIES 61 INSTALL_RPATH "${sof_install_directory}/lib" 62 INSTALL_RPATH_USE_LINK_PATH TRUE 63) 64