|
| 1 | +# SPDX-FileCopyrightText: 2006-2025, Knut Reinert & Freie Universität Berlin |
| 2 | +# SPDX-FileCopyrightText: 2016-2025, Knut Reinert & MPI für molekulare Genetik |
| 3 | +# SPDX-License-Identifier: BSD-3-Clause |
| 4 | + |
| 5 | +cmake_minimum_required (VERSION 3.25) |
| 6 | + |
| 7 | +option (SEQAN_STD_WITH_WERROR "Report compiler warnings as errors." ON) |
| 8 | + |
| 9 | +add_library (seqan-std_test INTERFACE) |
| 10 | +target_link_libraries (seqan-std_test INTERFACE seqan::std) |
| 11 | +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") |
| 12 | + target_compile_options (seqan-std_test INTERFACE "-pedantic" "-Wall" "-Wextra") |
| 13 | + if (SEQAN_STD_WITH_WERROR) |
| 14 | + target_compile_options (seqan-std_test INTERFACE "-Werror") |
| 15 | + message (STATUS "Building tests with -Werror.") |
| 16 | + endif () |
| 17 | + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14) |
| 18 | + target_compile_options (seqan-std_test INTERFACE "-Wnrvo") |
| 19 | + endif () |
| 20 | +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
| 21 | + target_compile_options (seqan-std_test INTERFACE "/W4") |
| 22 | + if (SEQAN_STD_WITH_WERROR) |
| 23 | + target_compile_options (seqan-std_test INTERFACE "/WX") |
| 24 | + message (STATUS "Building tests with /WX.") |
| 25 | + endif () |
| 26 | +endif () |
| 27 | + |
| 28 | +set (target "header_test") |
| 29 | +file (WRITE "${CMAKE_CURRENT_BINARY_DIR}/${target}.cpp" "int main() { return 0; }") |
| 30 | +add_executable (${target} ${CMAKE_CURRENT_BINARY_DIR}/${target}.cpp) |
| 31 | +target_link_libraries (${target} seqan-std_test) |
| 32 | +add_test (NAME "header/${target}" COMMAND ${target}) |
| 33 | + |
| 34 | +get_target_property (header_files seqan-std HEADER_SET_HEADERS) |
| 35 | +foreach (absolute_header_path ${header_files}) |
| 36 | + file (RELATIVE_PATH header "${SEQAN_STD_INCLUDE_DIR}" "${absolute_header_path}") |
| 37 | + get_filename_component (header_test_name "${absolute_header_path}" NAME_WE) |
| 38 | + |
| 39 | + foreach (header_sub_test "header-guard" "no-self-include") |
| 40 | + set (header_target "${header_test_name}-${header_sub_test}") |
| 41 | + set (header_target_source "${CMAKE_CURRENT_BINARY_DIR}/${target}_files/${header_target}.cpp") |
| 42 | + |
| 43 | + # we use add_custom_command to detect changes to a header file, which will update the generated source file |
| 44 | + add_custom_command (OUTPUT "${header_target_source}" |
| 45 | + COMMAND "${CMAKE_COMMAND}" # |
| 46 | + "-DHEADER_FILE_ABSOLUTE=${absolute_header_path}" |
| 47 | + "-DHEADER_FILE_INCLUDE=${header}" |
| 48 | + "-DHEADER_TARGET_SOURCE=${header_target_source}" |
| 49 | + "-DHEADER_SUB_TEST=${header_sub_test}" # |
| 50 | + "-P" "${CMAKE_CURRENT_SOURCE_DIR}/generate_header_source.cmake" |
| 51 | + DEPENDS "${absolute_header_path}" |
| 52 | + "${CMAKE_CURRENT_SOURCE_DIR}/generate_header_source.cmake") |
| 53 | + |
| 54 | + add_library (${header_target} OBJECT "${header_target_source}") |
| 55 | + target_link_libraries (${header_target} seqan-std_test) |
| 56 | + target_sources (${target} PRIVATE $<TARGET_OBJECTS:${header_target}>) |
| 57 | + endforeach () |
| 58 | +endforeach () |
0 commit comments