Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame^] | 1 | cmake_minimum_required(VERSION 3.9) |
| 2 | |
| 3 | set(CMAKE_VERBOSE_MAKEFILE ON) |
| 4 | |
| 5 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
| 6 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 7 | |
| 8 | project(FlatBuffersFuzzerTests) |
| 9 | |
| 10 | set(CMAKE_CXX_FLAGS |
| 11 | "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -pedantic -Werror -Wextra -Wno-unused-parameter -fsigned-char") |
| 12 | |
| 13 | set(CMAKE_CXX_FLAGS |
| 14 | "${CMAKE_CXX_FLAGS} -g -fsigned-char -fno-omit-frame-pointer") |
| 15 | |
| 16 | # Typical slowdown introduced by MemorySanitizer (memory) is 3x. |
| 17 | # '-fsanitize=address' not allowed with '-fsanitize=memory' |
| 18 | if(YES) |
| 19 | set(CMAKE_CXX_FLAGS |
| 20 | "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer,address,undefined") |
| 21 | else() |
| 22 | set(CMAKE_CXX_FLAGS |
| 23 | "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer,memory,undefined -fsanitize-memory-track-origins=2") |
| 24 | endif() |
| 25 | |
| 26 | set(CMAKE_CXX_FLAGS |
| 27 | "${CMAKE_CXX_FLAGS} -fsanitize-coverage=edge,trace-cmp") |
| 28 | |
| 29 | # enable link-time optimisation |
| 30 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") |
| 31 | |
| 32 | # https://llvm.org/docs/Passes.html |
| 33 | # save IR to see call graph |
| 34 | # make one bitcode file:> llvm-link *.bc -o out.bc |
| 35 | # print call-graph:> opt out.bc -analyze -print-callgraph &> callgraph.txt |
| 36 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -save-temps -flto") |
| 37 | |
| 38 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld") |
| 39 | |
| 40 | set(FLATBUFFERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../") |
| 41 | |
| 42 | set(FlatBuffers_Library_SRCS |
| 43 | ${FLATBUFFERS_DIR}/include/flatbuffers/code_generators.h |
| 44 | ${FLATBUFFERS_DIR}/include/flatbuffers/base.h |
| 45 | ${FLATBUFFERS_DIR}/include/flatbuffers/flatbuffers.h |
| 46 | ${FLATBUFFERS_DIR}/include/flatbuffers/hash.h |
| 47 | ${FLATBUFFERS_DIR}/include/flatbuffers/idl.h |
| 48 | ${FLATBUFFERS_DIR}/include/flatbuffers/util.h |
| 49 | ${FLATBUFFERS_DIR}/include/flatbuffers/reflection.h |
| 50 | ${FLATBUFFERS_DIR}/include/flatbuffers/reflection_generated.h |
| 51 | ${FLATBUFFERS_DIR}/include/flatbuffers/stl_emulation.h |
| 52 | ${FLATBUFFERS_DIR}/include/flatbuffers/flexbuffers.h |
| 53 | ${FLATBUFFERS_DIR}/include/flatbuffers/registry.h |
| 54 | ${FLATBUFFERS_DIR}/include/flatbuffers/minireflect.h |
| 55 | ${FLATBUFFERS_DIR}/src/code_generators.cpp |
| 56 | ${FLATBUFFERS_DIR}/src/idl_parser.cpp |
| 57 | ${FLATBUFFERS_DIR}/src/idl_gen_text.cpp |
| 58 | ${FLATBUFFERS_DIR}/src/reflection.cpp |
| 59 | ${FLATBUFFERS_DIR}/src/util.cpp |
| 60 | ${FLATBUFFERS_DIR}/tests/test_assert.cpp |
| 61 | ) |
| 62 | |
| 63 | include_directories(${FLATBUFFERS_DIR}/include) |
| 64 | include_directories(${FLATBUFFERS_DIR}/tests) |
| 65 | add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS}) |
| 66 | |
| 67 | # FLATBUFFERS_ASSERT should assert in Release as well. |
| 68 | # Redefine FLATBUFFERS_ASSERT macro definition. |
| 69 | # Declare as PUBLIC to cover asserts in all included header files. |
| 70 | target_compile_definitions(flatbuffers PUBLIC |
| 71 | FLATBUFFERS_ASSERT=fuzzer_assert_impl) |
| 72 | target_compile_definitions(flatbuffers PUBLIC |
| 73 | FLATBUFFERS_ASSERT_INCLUDE="${CMAKE_CURRENT_SOURCE_DIR}/fuzzer_assert.h") |
| 74 | |
| 75 | if(NOT DEFINED FLATBUFFERS_MAX_PARSING_DEPTH) |
| 76 | # Force checking of RecursionError in the test |
| 77 | set(FLATBUFFERS_MAX_PARSING_DEPTH 8) |
| 78 | endif() |
| 79 | message(STATUS "FLATBUFFERS_MAX_PARSING_DEPTH: ${FLATBUFFERS_MAX_PARSING_DEPTH}") |
| 80 | target_compile_definitions(flatbuffers PRIVATE FLATBUFFERS_MAX_PARSING_DEPTH=8) |
| 81 | |
| 82 | # Setup fuzzer tests. |
| 83 | |
| 84 | add_executable(scalar_fuzzer flatbuffers_scalar_fuzzer.cc) |
| 85 | target_link_libraries(scalar_fuzzer PRIVATE flatbuffers) |
| 86 | |
| 87 | add_executable(parser_fuzzer flatbuffers_parser_fuzzer.cc) |
| 88 | target_link_libraries(parser_fuzzer PRIVATE flatbuffers) |
| 89 | |
| 90 | add_executable(verifier_fuzzer flatbuffers_verifier_fuzzer.cc) |
| 91 | target_link_libraries(verifier_fuzzer PRIVATE flatbuffers) |