Tests: Add cases covering FindHDF5 variables and imported targets
This commit is contained in:
parent
0e87e6c1a4
commit
ad9e151045
@ -1450,6 +1450,7 @@ if(BUILD_TESTING)
|
||||
GnuTLS
|
||||
GSL
|
||||
GTK2
|
||||
HDF5
|
||||
Iconv
|
||||
ICU
|
||||
ImageMagick
|
||||
|
84
Tests/FindHDF5/CMakeLists.txt
Normal file
84
Tests/FindHDF5/CMakeLists.txt
Normal file
@ -0,0 +1,84 @@
|
||||
# These tests may be configured by cache entries:
|
||||
#
|
||||
# CMake_TEST_FindHDF5:BOOL=ON
|
||||
# Enable this directory.
|
||||
#
|
||||
# CMake_TEST_FindHDF5_<variant>_<lang>_COMPILER:FILEPATH=...
|
||||
# Enable testing for a variant/language combination with the given wrapper.
|
||||
# Variants: Serial, OpenMPI, MPICH
|
||||
# Languages: C, CXX, Fortran
|
||||
#
|
||||
# CMake_TEST_FindHDF5_<variant>_<lang>_COMPILER_EXPLICIT:BOOL=ON
|
||||
# Pass the above wrapper path to the test as HDF5_<lang>_COMPILER_EXECUTABLE.
|
||||
|
||||
set(test_langs C CXX)
|
||||
if(CMAKE_Fortran_COMPILER)
|
||||
list(APPEND test_langs Fortran)
|
||||
endif()
|
||||
|
||||
# Test detection without any special hints.
|
||||
add_test(NAME FindHDF5.Default COMMAND
|
||||
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Tests/FindHDF5/Test"
|
||||
"${CMake_BINARY_DIR}/Tests/FindHDF5/Test-Default"
|
||||
${build_generator_args}
|
||||
--build-project TestFindHDF5
|
||||
--build-options ${build_options} -DTEST_SERIAL=1 "-DTEST_LANGS=${test_langs}"
|
||||
)
|
||||
|
||||
foreach(variant Serial OpenMPI MPICH)
|
||||
set(wrapper "")
|
||||
set(wrapper_langs "")
|
||||
set(wrapper_as_compiler "")
|
||||
foreach(lang IN LISTS test_langs)
|
||||
if(CMake_TEST_FindHDF5_${variant}_${lang}_COMPILER)
|
||||
list(APPEND wrapper_langs ${lang})
|
||||
list(APPEND wrapper_as_compiler -DCMAKE_${lang}_COMPILER=${CMake_TEST_FindHDF5_${variant}_${lang}_COMPILER})
|
||||
if(CMake_TEST_FindHDF5_${variant}_${lang}_COMPILER_EXPLICIT)
|
||||
list(APPEND wrapper -DHDF5_${lang}_COMPILER_EXECUTABLE=${CMake_TEST_FindHDF5_${variant}_${lang}_COMPILER})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT wrapper_langs)
|
||||
continue()
|
||||
endif()
|
||||
|
||||
if(variant STREQUAL "Serial")
|
||||
set(test_kind -DTEST_SERIAL=1)
|
||||
else()
|
||||
set(test_kind -DTEST_PARALLEL=1)
|
||||
endif()
|
||||
|
||||
# Test detection using the HDF5 compiler wrappers as a reference.
|
||||
add_test(NAME FindHDF5.${variant} COMMAND
|
||||
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Tests/FindHDF5/Test"
|
||||
"${CMake_BINARY_DIR}/Tests/FindHDF5/Test-${variant}"
|
||||
${build_generator_args}
|
||||
--build-project TestFindHDF5
|
||||
--build-options ${build_options} ${test_kind} "-DTEST_LANGS=${wrapper_langs}" ${wrapper}
|
||||
)
|
||||
if(CMake_TEST_FindHDF5_${variant}_ENVMOD)
|
||||
set_property(TEST FindHDF5.${variant} PROPERTY ENVIRONMENT_MODIFICATION ${CMake_TEST_FindHDF5_${variant}_ENVMOD})
|
||||
endif()
|
||||
|
||||
# Test detection using the HDF5 compiler wrappers as the compiler.
|
||||
# Skip this if there are spaces in the path. The HDF5 wrappers do not like them.
|
||||
if(NOT CMAKE_CURRENT_BINARY_DIR MATCHES " ")
|
||||
add_test(NAME FindHDF5.${variant}-Wrapper COMMAND
|
||||
${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
|
||||
--build-and-test
|
||||
"${CMake_SOURCE_DIR}/Tests/FindHDF5/Test"
|
||||
"${CMake_BINARY_DIR}/Tests/FindHDF5/Test-${variant}-Wrapper"
|
||||
${build_generator_args}
|
||||
--build-project TestFindHDF5
|
||||
--build-options ${build_options} ${test_kind} "-DTEST_LANGS=${wrapper_langs}" -D TEST_WRAPPER_AS_COMPILER=1 ${wrapper_as_compiler}
|
||||
)
|
||||
if(CMake_TEST_FindHDF5_${variant}_ENVMOD)
|
||||
set_property(TEST FindHDF5.${variant}-Wrapper PROPERTY ENVIRONMENT_MODIFICATION ${CMake_TEST_FindHDF5_${variant}_ENVMOD})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
58
Tests/FindHDF5/Test/CMakeLists.txt
Normal file
58
Tests/FindHDF5/Test/CMakeLists.txt
Normal file
@ -0,0 +1,58 @@
|
||||
cmake_minimum_required(VERSION 3.26)
|
||||
project(TestFindHDF5 LANGUAGES ${TEST_LANGS})
|
||||
message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)")
|
||||
|
||||
if(TEST_PARALLEL)
|
||||
set(HDF5_PREFER_PARALLEL 1)
|
||||
endif()
|
||||
|
||||
find_package(HDF5 REQUIRED COMPONENTS ${TEST_LANGS} HL)
|
||||
|
||||
set(variables HDF5_FOUND HDF5_VERSION)
|
||||
if(NOT TEST_WRAPPER_AS_COMPILER)
|
||||
list(APPEND variables HDF5_INCLUDE_DIRS HDF5_LIBRARIES HDF5_HL_LIBRARIES)
|
||||
foreach(lang ${TEST_LANGS})
|
||||
list(APPEND variables
|
||||
HDF5_${lang}_COMPILER_EXECUTABLE
|
||||
HDF5_${lang}_INCLUDE_DIRS
|
||||
HDF5_${lang}_LIBRARIES
|
||||
HDF5_${lang}_HL_LIBRARIES
|
||||
)
|
||||
endforeach()
|
||||
endif()
|
||||
foreach(var IN LISTS variables)
|
||||
message(STATUS "${var}='${${var}}'")
|
||||
endforeach()
|
||||
foreach(var IN LISTS variables)
|
||||
if(NOT DEFINED ${var})
|
||||
message(SEND_ERROR "Variable '${var}' is not defined!")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(targets HDF5::HDF5)
|
||||
if(CMAKE_C_COMPILER_LOADED)
|
||||
list(APPEND targets hdf5::hdf5 hdf5::hdf5_hl)
|
||||
endif()
|
||||
if(CMAKE_CXX_COMPILER_LOADED)
|
||||
list(APPEND targets hdf5::hdf5_cpp hdf5::hdf5_hl_cpp)
|
||||
endif()
|
||||
if(CMAKE_Fortran_COMPILER_LOADED)
|
||||
list(APPEND targets hdf5::hdf5_fortran hdf5::hdf5_hl_fortran)
|
||||
endif()
|
||||
foreach(target IN LISTS targets)
|
||||
if(NOT TARGET ${target})
|
||||
message(SEND_ERROR "Target '${target}' not defined!")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
message(STATUS "HDF5_IS_PARALLEL='${HDF5_IS_PARALLEL}'")
|
||||
if(TEST_SERIAL)
|
||||
if(HDF5_IS_PARALLEL)
|
||||
message(SEND_ERROR "HDF5_IS_PARALLEL is true in serial test.")
|
||||
endif()
|
||||
endif()
|
||||
if(TEST_PARALLEL)
|
||||
if(NOT HDF5_IS_PARALLEL)
|
||||
message(SEND_ERROR "HDF5_IS_PARALLEL is false in parallel test.")
|
||||
endif()
|
||||
endif()
|
Loading…
Reference in New Issue
Block a user