ELFIO/tests/CMakeLists.txt

90 lines
2.2 KiB
CMake
Raw Normal View History

2022-02-11 21:15:39 +00:00
include(FetchContent)
2022-12-15 17:07:46 +00:00
if(${CMAKE_VERSION} VERSION_LESS "3.24.0")
FetchContent_Declare(
googletest
2023-12-13 16:24:31 +00:00
URL https://github.com/google/googletest/archive/530d5c8c84.zip
2022-12-15 17:07:46 +00:00
)
else()
FetchContent_Declare(
googletest
2023-12-13 16:24:31 +00:00
URL https://github.com/google/googletest/archive/530d5c8c84.zip
2022-12-15 17:07:46 +00:00
FIND_PACKAGE_ARGS NAMES GTest
DOWNLOAD_EXTRACT_TIMESTAMP = TRUE
)
endif()
2022-02-11 21:15:39 +00:00
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
2020-10-16 07:14:56 +00:00
# Find all the binary files used for testing and copy them into the build
# directory. This allows the test to be run from the build directory
2020-10-16 07:14:56 +00:00
# First, create an elf_examples folder under the current build directory
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/elf_examples)
# Second, glob all files under elf_examples
file(GLOB elf_examples
LIST_DIRECTORIES
2022-06-21 06:49:46 +00:00
false
CONFIGURE_DEPENDS
elf_examples/*)
# Third, copy each file globbed to the elf_examples folder under the current
# build directory
foreach(example ${elf_examples})
configure_file(${example} ${CMAKE_CURRENT_BINARY_DIR}/elf_examples COPYONLY)
endforeach()
# Lastly, copy the script to run the tests
configure_file(runELFtests ${CMAKE_CURRENT_BINARY_DIR}/runELFtests COPYONLY)
add_executable(
ELFIOTest
ELFIOTest.cpp
ELFIOTest1.cpp
ELFIOTest2.cpp)
target_link_libraries(
ELFIOTest
PRIVATE
2022-06-21 06:49:46 +00:00
elfio::elfio
gtest_main
GTest::gtest_main)
add_test(
NAME
2022-06-21 06:49:46 +00:00
ELFIOTest
COMMAND
2022-06-21 06:49:46 +00:00
${CMAKE_CURRENT_BINARY_DIR}/ELFIOTest
WORKING_DIRECTORY
2022-06-21 06:49:46 +00:00
${CMAKE_CURRENT_BINARY_DIR})
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_executable(
elfio_fuzzer
elfio_fuzzer.cpp)
target_link_libraries(
elfio_fuzzer
PRIVATE
elfio::elfio)
target_compile_options(elfio_fuzzer
2022-06-21 13:39:35 +00:00
PRIVATE $<$<C_COMPILER_ID:Clang>:-g -O1 -fsanitize=fuzzer,address>
2022-06-21 06:49:46 +00:00
)
target_link_libraries(elfio_fuzzer
2022-06-21 13:39:35 +00:00
PRIVATE $<$<C_COMPILER_ID:Clang>:-fsanitize=fuzzer,address>
2022-06-21 06:49:46 +00:00
)
endif()
2020-10-29 22:49:12 +00:00
add_dependencies(check ELFIOTest)
2022-02-11 21:15:39 +00:00
include(GoogleTest)
gtest_discover_tests(ELFIOTest)