diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 8dcce8d78..a282da319 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -42,34 +42,35 @@ if(HDF5_IS_PARALLEL) set(_CATCH_DISCOVER_TESTS_SCRIPT "${original_catch_script}") endif() -if(HIGHFIVE_TEST_SINGLE_INCLUDES) - file(GLOB public_headers LIST_DIRECTORIES false RELATIVE ${PROJECT_SOURCE_DIR}/include CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/include/highfive/*.hpp) - foreach(PUBLIC_HEADER ${public_headers}) - if(PUBLIC_HEADER STREQUAL "highfive/span.hpp" AND NOT HIGHFIVE_TEST_SPAN) - continue() - endif() +# Test that each public header is self-sufficient. This is done by +# creating a file for each header, that only includes the header. The +# test succeeds if it compiles. +file(GLOB public_headers LIST_DIRECTORIES false RELATIVE ${PROJECT_SOURCE_DIR}/include CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/include/highfive/*.hpp) +foreach(PUBLIC_HEADER ${public_headers}) + if(PUBLIC_HEADER STREQUAL "highfive/span.hpp" AND NOT HIGHFIVE_TEST_SPAN) + continue() + endif() - if(PUBLIC_HEADER STREQUAL "highfive/boost.hpp" AND NOT HIGHFIVE_TEST_BOOST) - continue() - endif() + if(PUBLIC_HEADER STREQUAL "highfive/boost.hpp" AND NOT HIGHFIVE_TEST_BOOST) + continue() + endif() - if(PUBLIC_HEADER STREQUAL "highfive/half_float.hpp" AND NOT HIGHFIVE_TEST_HALF_FLOAT) - continue() - endif() + if(PUBLIC_HEADER STREQUAL "highfive/half_float.hpp" AND NOT HIGHFIVE_TEST_HALF_FLOAT) + continue() + endif() - if(PUBLIC_HEADER STREQUAL "highfive/eigen.hpp" AND NOT HIGHFIVE_TEST_EIGEN) - continue() - endif() + if(PUBLIC_HEADER STREQUAL "highfive/eigen.hpp" AND NOT HIGHFIVE_TEST_EIGEN) + continue() + endif() - get_filename_component(CLASS_NAME ${PUBLIC_HEADER} NAME_WE) - configure_file(tests_import_public_headers.cpp "tests_${CLASS_NAME}.cpp" @ONLY) - add_executable("tests_include_${CLASS_NAME}" "${CMAKE_CURRENT_BINARY_DIR}/tests_${CLASS_NAME}.cpp") - target_link_libraries( - "tests_include_${CLASS_NAME}" PUBLIC - HighFive - HighFiveWarnings - HighFiveFlags - HighFiveOptionalDependencies - ) - endforeach() -endif() + get_filename_component(CLASS_NAME ${PUBLIC_HEADER} NAME_WE) + configure_file(tests_import_public_headers.cpp "tests_${CLASS_NAME}.cpp" @ONLY) + add_executable("tests_include_${CLASS_NAME}" "${CMAKE_CURRENT_BINARY_DIR}/tests_${CLASS_NAME}.cpp") + target_link_libraries( + "tests_include_${CLASS_NAME}" PUBLIC + HighFive + HighFiveWarnings + HighFiveFlags + HighFiveOptionalDependencies + ) +endforeach()