onnxruntime
65 строк · 2.9 Кб
1# Copyright (c) Microsoft Corporation. All rights reserved.
2# Licensed under the MIT License.
3
4# Check that the options are properly set for
5# the fuzzing project
6if (onnxruntime_FUZZ_ENABLED)
7message(STATUS "Building dependency protobuf-mutator and libfuzzer")
8
9# set the options used to control the protobuf-mutator build
10set(PROTOBUF_LIBRARIES ${PROTOBUF_LIB})
11set(LIB_PROTO_MUTATOR_TESTING OFF)
12
13# include the protobuf-mutator CMakeLists.txt rather than the projects CMakeLists.txt to avoid target clashes
14# with google test
15add_subdirectory("external/libprotobuf-mutator/src")
16
17# add the appropriate include directory and compilation flags
18# needed by the protobuf-mutator target and the libfuzzer
19set(PROTOBUF_MUT_INCLUDE_DIRS "external/libprotobuf-mutator")
20onnxruntime_add_include_to_target(protobuf-mutator ${PROTOBUF_LIB})
21onnxruntime_add_include_to_target(protobuf-mutator-libfuzzer ${PROTOBUF_LIB})
22target_include_directories(protobuf-mutator PRIVATE ${INCLUDE_DIRECTORIES} ${PROTOBUF_MUT_INCLUDE_DIRS})
23target_include_directories(protobuf-mutator-libfuzzer PRIVATE ${INCLUDE_DIRECTORIES} ${PROTOBUF_MUT_INCLUDE_DIRS})
24target_compile_options(protobuf-mutator PRIVATE "/wd4244" "/wd4245" "/wd4267" "/wd4100" "/wd4456")
25target_compile_options(protobuf-mutator-libfuzzer PRIVATE "/wd4146" "/wd4267")
26
27# add Fuzzing Engine Build Configuration
28message(STATUS "Building Fuzzing engine")
29
30# set Fuzz root directory
31set(SEC_FUZZ_ROOT ${TEST_SRC_DIR}/fuzzing)
32
33# Security fuzzing engine src file reference
34set(SEC_FUZ_SRC "${SEC_FUZZ_ROOT}/src/BetaDistribution.cpp"
35"${SEC_FUZZ_ROOT}/src/OnnxPrediction.cpp"
36"${SEC_FUZZ_ROOT}/src/testlog.cpp"
37"${SEC_FUZZ_ROOT}/src/test.cpp")
38
39# compile the executables
40onnxruntime_add_executable(onnxruntime_security_fuzz ${SEC_FUZ_SRC})
41
42# compile with c++17
43target_compile_features(onnxruntime_security_fuzz PUBLIC cxx_std_17)
44
45# Security fuzzing engine header file reference
46onnxruntime_add_include_to_target(onnxruntime_security_fuzz onnx onnxruntime)
47
48# Assign all include to one variable
49set(SEC_FUZ_INC "${SEC_FUZZ_ROOT}/include")
50set(INCLUDE_FILES ${SEC_FUZ_INC} "$<TARGET_PROPERTY:protobuf-mutator,INCLUDE_DIRECTORIES>")
51
52# add all these include directory to the Fuzzing engine
53target_include_directories(onnxruntime_security_fuzz PRIVATE ${INCLUDE_FILES})
54
55# add link libraries the project
56target_link_libraries(onnxruntime_security_fuzz onnx_proto onnxruntime protobuf-mutator ${PROTOBUF_LIB})
57
58# add the dependencies
59add_dependencies(onnxruntime_security_fuzz onnx_proto onnxruntime protobuf-mutator ${PROTOBUF_LIB})
60
61# copy the dlls to the execution directory
62add_custom_command(TARGET onnxruntime_security_fuzz POST_BUILD
63COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:onnxruntime> $<TARGET_FILE_DIR:onnxruntime_security_fuzz>
64COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:${PROTOBUF_LIB}> $<TARGET_FILE_DIR:onnxruntime_security_fuzz>)
65endif()