diff options
author | Brad King <brad.king@kitware.com> | 2023-03-30 15:23:03 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-03-30 19:05:59 (GMT) |
commit | 75bb2a2ee412d303903123913555a7d9129539b5 (patch) | |
tree | 19b916eb792adf48236017c24594e0526f74692f /Tests | |
parent | 919de8785b8781a78f69c102226d8ca65eff526c (diff) | |
download | CMake-75bb2a2ee412d303903123913555a7d9129539b5.zip CMake-75bb2a2ee412d303903123913555a7d9129539b5.tar.gz CMake-75bb2a2ee412d303903123913555a7d9129539b5.tar.bz2 |
Tests: Extend FindHDF5 tests to link and run executables
Verify that this works using both targets and variables.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/FindHDF5/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/FindHDF5/Test/CMakeLists.txt | 48 | ||||
-rw-r--r-- | Tests/FindHDF5/Test/test_C.c | 12 | ||||
-rw-r--r-- | Tests/FindHDF5/Test/test_CXX.cxx | 14 | ||||
-rw-r--r-- | Tests/FindHDF5/Test/test_Fortran.f90 | 6 |
5 files changed, 83 insertions, 0 deletions
diff --git a/Tests/FindHDF5/CMakeLists.txt b/Tests/FindHDF5/CMakeLists.txt index 373759e..6bc551a 100644 --- a/Tests/FindHDF5/CMakeLists.txt +++ b/Tests/FindHDF5/CMakeLists.txt @@ -25,6 +25,7 @@ add_test(NAME FindHDF5.Default COMMAND ${build_generator_args} --build-project TestFindHDF5 --build-options ${build_options} -DTEST_SERIAL=1 "-DTEST_LANGS=${test_langs}" + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) foreach(variant Serial OpenMPI MPICH) @@ -60,6 +61,7 @@ foreach(variant Serial OpenMPI MPICH) ${build_generator_args} --build-project TestFindHDF5 --build-options ${build_options} ${test_kind} "-DTEST_LANGS=${wrapper_langs}" ${wrapper} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) if(CMake_TEST_FindHDF5_${variant}_ENVMOD) set_property(TEST FindHDF5.${variant} PROPERTY ENVIRONMENT_MODIFICATION ${CMake_TEST_FindHDF5_${variant}_ENVMOD}) @@ -76,6 +78,7 @@ foreach(variant Serial OpenMPI MPICH) ${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} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> ) if(CMake_TEST_FindHDF5_${variant}_ENVMOD) set_property(TEST FindHDF5.${variant}-Wrapper PROPERTY ENVIRONMENT_MODIFICATION ${CMake_TEST_FindHDF5_${variant}_ENVMOD}) diff --git a/Tests/FindHDF5/Test/CMakeLists.txt b/Tests/FindHDF5/Test/CMakeLists.txt index 53ad633..da1b369 100644 --- a/Tests/FindHDF5/Test/CMakeLists.txt +++ b/Tests/FindHDF5/Test/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.26) project(TestFindHDF5 LANGUAGES ${TEST_LANGS}) +include(CTest) message(STATUS "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)") if(TEST_PARALLEL) @@ -56,3 +57,50 @@ if(TEST_PARALLEL) message(SEND_ERROR "HDF5_IS_PARALLEL is false in parallel test.") endif() endif() + +if(TEST_PARALLEL) + set(MPI_CXX_SKIP_MPICXX TRUE) + set(MPI_CXX_VALIDATE_SKIP_MPICXX TRUE) + find_package(MPI REQUIRED) + set(mpi_C_tgt MPI::MPI_C) + set(mpi_C_inc ${MPI_C_INCLUDE_PATH}) + set(mpi_C_lib ${MPI_C_LINK_FLAGS} ${MPI_C_LIBRARIES}) + set(mpi_Fortran_tgt MPI::MPI_Fortran) + set(mpi_Fortran_inc ${MPI_Fortran_INCLUDE_PATH}) + set(mpi_Fortran_lib ${MPI_Fortran_LIBRARIES}) +endif() + +if(CMAKE_C_COMPILER_LOADED) + add_executable(test_C_tgt test_C.c) + target_link_libraries(test_C_tgt PRIVATE hdf5::hdf5 ${mpi_C_tgt}) + add_test(NAME test_C_tgt COMMAND test_C_tgt test_C_tgt.h5) + + add_executable(test_C_var test_C.c) + target_include_directories(test_C_var PRIVATE ${HDF5_C_INCLUDE_DIRS} ${mpi_C_inc}) + target_link_libraries(test_C_var PRIVATE ${HDF5_C_LIBRARIES} ${mpi_C_lib}) + add_test(NAME test_C_var COMMAND test_C_var test_C_var.h5) +endif() + +if(CMAKE_CXX_COMPILER_LOADED) + add_executable(test_CXX_tgt test_CXX.cxx) + target_link_libraries(test_CXX_tgt PRIVATE hdf5::hdf5_cpp + hdf5::hdf5 # FIXME: hdf5::hdf5_cpp should link hdf5::hdf5 automatically. + ${mpi_C_tgt}) + add_test(NAME test_CXX_tgt COMMAND test_CXX_tgt test_CXX_tgt.h5) + + add_executable(test_CXX_var test_CXX.cxx) + target_include_directories(test_CXX_var PRIVATE ${HDF5_CXX_INCLUDE_DIRS} ${mpi_C_inc}) + target_link_libraries(test_CXX_var PRIVATE ${HDF5_CXX_LIBRARIES} ${mpi_C_lib}) + add_test(NAME test_CXX_var COMMAND test_CXX_var test_CXX_var.h5) +endif() + +if(CMAKE_Fortran_COMPILER_LOADED) + add_executable(test_Fortran_tgt test_Fortran.f90) + target_link_libraries(test_Fortran_tgt PRIVATE hdf5::hdf5_fortran ${mpi_Fortran_tgt}) + add_test(NAME test_Fortran_tgt COMMAND test_Fortran_tgt) + + add_executable(test_Fortran_var test_Fortran.f90) + target_include_directories(test_Fortran_var PRIVATE ${HDF5_Fortran_INCLUDE_DIRS} ${mpi_Fortran_inc}) + target_link_libraries(test_Fortran_var PRIVATE ${HDF5_Fortran_LIBRARIES} ${mpi_Fortran_lib}) + add_test(NAME test_Fortran_var COMMAND test_Fortran_var) +endif() diff --git a/Tests/FindHDF5/Test/test_C.c b/Tests/FindHDF5/Test/test_C.c new file mode 100644 index 0000000..4c18364 --- /dev/null +++ b/Tests/FindHDF5/Test/test_C.c @@ -0,0 +1,12 @@ +#include <hdf5.h> + +int main(int argc, const char* argv[]) +{ + hid_t fid; + if (argc != 2) { + return 1; + } + fid = H5Fcreate(argv[1], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + H5Fclose(fid); + return 0; +} diff --git a/Tests/FindHDF5/Test/test_CXX.cxx b/Tests/FindHDF5/Test/test_CXX.cxx new file mode 100644 index 0000000..93fb462 --- /dev/null +++ b/Tests/FindHDF5/Test/test_CXX.cxx @@ -0,0 +1,14 @@ +#include <H5Cpp.h> + +#ifndef H5_NO_NAMESPACE +using namespace H5; +#endif + +int main(int argc, const char* argv[]) +{ + if (argc != 2) { + return 1; + } + H5File f(argv[1], H5F_ACC_TRUNC); + return 0; +} diff --git a/Tests/FindHDF5/Test/test_Fortran.f90 b/Tests/FindHDF5/Test/test_Fortran.f90 new file mode 100644 index 0000000..4c12c8c --- /dev/null +++ b/Tests/FindHDF5/Test/test_Fortran.f90 @@ -0,0 +1,6 @@ +program hdf5_hello + use hdf5 + integer error + call h5open_f(error) + call h5close_f(error) +end |