• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1include(FetchContent)
2
3FetchContent_Declare(
4    googletest
5    URL https://github.com/google/googletest/archive/9a32aee22d771387c494be2d8519fbdf46a713b2.zip
6)
7
8# For Windows: Prevent overriding the parent project's compiler/linker settings
9set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
10
11FetchContent_MakeAvailable(googletest)
12
13enable_testing()
14
15# Find all the binary files used for testing and copy them into the build
16# directory. This allows the test to be run from the build directory
17
18# First, create an elf_examples folder under the current build directory
19file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/elf_examples)
20
21# Second, glob all files under elf_examples
22file(GLOB elf_examples
23    LIST_DIRECTORIES
24    false
25    CONFIGURE_DEPENDS
26    elf_examples/*)
27
28# Third, copy each file globbed to the elf_examples folder under the current
29# build directory
30foreach(example ${elf_examples})
31    configure_file(${example} ${CMAKE_CURRENT_BINARY_DIR}/elf_examples COPYONLY)
32endforeach()
33
34# Lastly, copy the script to run the tests
35configure_file(runELFtests ${CMAKE_CURRENT_BINARY_DIR}/runELFtests COPYONLY)
36
37add_executable(
38    ELFIOTest
39    ELFIOTest.cpp
40    ELFIOTest1.cpp
41    ELFIOTest2.cpp)
42
43target_link_libraries(
44    ELFIOTest
45    PRIVATE
46    elfio::elfio
47    gtest_main)
48
49add_test(
50    NAME
51    ELFIOTest
52    COMMAND
53    ${CMAKE_CURRENT_BINARY_DIR}/ELFIOTest
54    WORKING_DIRECTORY
55    ${CMAKE_CURRENT_BINARY_DIR})
56
57if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
58    add_executable(
59        elfio_fuzzer
60        elfio_fuzzer.cpp)
61
62    target_link_libraries(
63        elfio_fuzzer
64        PRIVATE
65        elfio::elfio)
66
67    target_compile_options(elfio_fuzzer
68        PRIVATE $<$<C_COMPILER_ID:Clang>:-g -O1 -fsanitize=fuzzer,address>
69    )
70
71    target_link_libraries(elfio_fuzzer
72        PRIVATE $<$<C_COMPILER_ID:Clang>:-fsanitize=fuzzer,address>
73    )
74endif()
75
76add_dependencies(check ELFIOTest)
77
78include(GoogleTest)
79gtest_discover_tests(ELFIOTest)
80