From 6c022f9f01c7f7d12ee014d11a5683f802d9a2f3 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 20 Mar 2026 14:31:29 +0100 Subject: [PATCH 01/59] add fix for hdf5 2.0.0 --- CMakeLists.txt | 5 ++++- plugins/decl_hdf5/CMakeLists.txt | 6 ++++-- plugins/decl_netcdf/cmake/FindNetCDF.cmake | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9232a10e6..8be96df26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,7 +308,7 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") sbuild_add_dependency(HDF5 "${USE_DEFAULT}" EMBEDDED_PATH "vendor/hdf5-1.12.3" COMPONENTS ${HDF5_COMPONENTS} - MODULE_VARS HDF5_IS_PARALLEL HDF5_VERSION + MODULE_VARS HDF5_IS_PARALLEL HDF5_PROVIDES_PARALLEL HDF5_VERSION CMAKE_CACHE_ARGS -DBUILD_STATIC_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF @@ -326,6 +326,9 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() + if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) + set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") + endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "You requested a parallel HDF5 build (-DBUILD_HDF5_PARALLEL=ON) but a sequential SYSTEM version has been found\n" diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 970eba144..18214a720 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -51,14 +51,16 @@ find_package(HDF5 REQUIRED COMPONENTS C) if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - +if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) + set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") +endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "Parallel HDF5 required, sequential HDF5 only found. Please set -DBUILD_HDF5_PARALLEL=OFF to disable parallel HDF5") endif() set(HDF5_DEPS hdf5::hdf5) # MPI -if("${HDF5_IS_PARALLEL}") +if("${HDF5_IS_PARALLEL}" OR "${HDF5_PROVIDES_PARALLEL}") if("${BUILD_TESTING}" AND "${BUILD_FORTRAN}") set(MPI_COMPONENTS Fortran) endif() diff --git a/plugins/decl_netcdf/cmake/FindNetCDF.cmake b/plugins/decl_netcdf/cmake/FindNetCDF.cmake index 0cdd109d5..b1465e884 100644 --- a/plugins/decl_netcdf/cmake/FindNetCDF.cmake +++ b/plugins/decl_netcdf/cmake/FindNetCDF.cmake @@ -369,7 +369,7 @@ if("${NetCDF_FOUND}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT "${HDF5_IS_PARALLEL}") + if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT ("${HDF5_PROVIDES_PARALLEL}" OR "${HDF5_IS_PARALLEL}")) message(ERROR "Parallel HDF5 required by NetCDF, sequential HDF5 only found.") endif() list(APPEND NetCDF_LINK_LIBRARIES hdf5::hdf5) From 4e881619dea530fc00bc885ac733d59ba15c5d01 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Thu, 9 Apr 2026 09:33:35 +0200 Subject: [PATCH 02/59] Fix MPI condition for HDF5 parallel support --- plugins/decl_hdf5/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 18214a720..26d195ada 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -60,7 +60,7 @@ endif() set(HDF5_DEPS hdf5::hdf5) # MPI -if("${HDF5_IS_PARALLEL}" OR "${HDF5_PROVIDES_PARALLEL}") +if("${HDF5_IS_PARALLEL}") if("${BUILD_TESTING}" AND "${BUILD_FORTRAN}") set(MPI_COMPONENTS Fortran) endif() From b342921239573ba3b942ba7e3d861960eeb83ebc Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 11:47:29 +0200 Subject: [PATCH 03/59] add test for precision conversion --- .../HDF5_C/d2s_precision_read_test.c | 73 ++++++++++++++++++ .../HDF5_C/d2s_precision_write_test.c | 75 +++++++++++++++++++ .../PDI_C/d2s_precision_read_test.c | 68 +++++++++++++++++ .../PDI_C/d2s_precision_write_test.c | 61 +++++++++++++++ 4 files changed, 277 insertions(+) create mode 100644 plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c create mode 100644 plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c create mode 100644 plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c create mode 100644 plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c diff --git a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c new file mode 100644 index 000000000..4f0c0becb --- /dev/null +++ b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include +#include +#include +#include + +#define FILE "d2s_test.h5" + +int main() +{ + printf("HDF5 d2s_precision_read_test started\n"); + hid_t file_id = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT); + if (file_id < 0) { + return 1; + } + + double dset_data[1000]; + for (int i = 0; i < 1000; i++) { + dset_data[i] = 3.14; + } + + hid_t dataset_id = H5Dopen2(file_id, "float_data", H5P_DEFAULT); + if (dataset_id < 0) { + return 1; + } + + herr_t status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); + if (status < 0) { + return 1; + } + + for (int i = 0; i < 1000; i++) { + if (fabs(dset_data[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { + fprintf(stderr, "dset_data[%d]: %f != %f, diff = %f\n ", i, dset_data[i], i * 10.0 + 3.141592653589793, fabs(dset_data[i] - (i * 10.0 + 3.141592653589793))); + return 1; + } + } + + status = H5Dclose(dataset_id); + if (status < 0) { + return 1; + } + status = H5Fclose(file_id); + if (file_id < 0) { + return 1; + } + + printf("HDF5_C d2s_precision_read_test finalized\n"); + return 0; +} diff --git a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c new file mode 100644 index 000000000..4dc917c33 --- /dev/null +++ b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include +#include +#include + +#define FILE "d2s_test.h5" + +int main() +{ + printf("HDF5 d2s_precision_write_test started\n"); + hid_t file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if (file_id < 0) { + return 1; + } + + hsize_t coords[2] = {100, 10}; + hid_t dataspace_id = H5Screate_simple(2, coords, NULL); + if (dataspace_id < 0) { + return 1; + } + + double dset_data[1000]; + for (int i = 0; i < 1000; i++) { + dset_data[i] = i * 10.0 + 3.141592653589793; + } + + hid_t dataset_id = H5Dcreate2(file_id, "/float_data", H5T_NATIVE_FLOAT, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (dataset_id < 0) { + return 1; + } + + herr_t status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); + if (status < 0) { + return 1; + } + + status = H5Sclose(dataspace_id); + if (status < 0) { + return 1; + } + status = H5Dclose(dataset_id); + if (status < 0) { + return 1; + } + status = H5Fclose(file_id); + if (file_id < 0) { + return 1; + } + + printf("HDF5_C d2s_precision_write_test finalized\n"); + return 0; +} diff --git a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c new file mode 100644 index 000000000..9daa53b0f --- /dev/null +++ b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include +#include +#include +#include + +#define FILE "d2s_test.h5" + +int main() +{ + printf("PDI d2s_precision_read_test started\n"); + const char* CONFIG_YAML + = "logging: trace \n" + "data: \n" + " double_data: { size: [100, 10], type: array, subtype: double } \n" + "plugins: \n" + " decl_hdf5: \n" + " - file: d2s_test.h5 \n" + " datasets: \n" + " float_data: {size: [100, 10], type: array, subtype: float }\n" + " read: \n" + " double_data: \n" + " dataset: float_data \n"; + + PC_tree_t conf = PC_parse_string(CONFIG_YAML); + PDI_init(conf); + double test_array[1000]; + for (int i = 0; i < 1000; i++) { + test_array[i] = 3.14; + } + PDI_expose("double_data", test_array, PDI_IN); + + for (int i = 0; i < 1000; i++) { + if (fabs(test_array[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { + fprintf(stderr, "test_array[%d] %f != %f, diff = %f\n ", i, test_array[i], i * 10.0 + 3.141592653589793, fabs(test_array[i] - (i * 10.0 + 3.141592653589793))); + return 1; + } + } + + PDI_finalize(); + PC_tree_destroy(&conf); + + printf("PDI d2s_precision_read_test finalized\n"); + return 0; +} diff --git a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c new file mode 100644 index 000000000..a59faade3 --- /dev/null +++ b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include +#include +#include + +#define FILE "d2s_test.h5" + +int main() +{ + printf("PDI d2s_precision_write_test started\n"); + const char* CONFIG_YAML + = "logging: trace \n" + "data: \n" + " double_data: { size: [100, 10], type: array, subtype: double } \n" + "plugins: \n" + " decl_hdf5: \n" + " - file: d2s_test.h5 \n" + " datasets: \n" + " float_data: {size: [100, 10], type: array, subtype: float }\n" + " write: \n" + " double_data: \n" + " dataset: float_data \n"; + + PC_tree_t conf = PC_parse_string(CONFIG_YAML); + PDI_init(conf); + double test_array[1000]; + + for (int i = 0; i < 1000; i++) { + test_array[i] = i * 10.0 + 3.141592653589793; + } + + PDI_expose("double_data", test_array, PDI_OUT); + PDI_finalize(); + PC_tree_destroy(&conf); + + printf("PDI d2s_precision_write_test finalized\n"); + return 0; +} From 28e39892258adef5ab2cdabcb2f5d9bae65bade9 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 11:49:02 +0200 Subject: [PATCH 04/59] Add 'd2s_precision' to ALL_TEST_NAMES --- plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt b/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt index 7b18f57d1..2d76c9d2e 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt +++ b/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt @@ -27,7 +27,7 @@ cmake_minimum_required(VERSION 3.22...4.2) set(RUNTEST_DIR "${CMAKE_CURRENT_LIST_DIR}/../../cmake/runtest-dir") -set(ALL_TEST_NAMES array dataset group struct variables) +set(ALL_TEST_NAMES array dataset group struct variables d2s_precision ) if("${BUILD_HDF5_PARALLEL}") list(APPEND ALL_TEST_NAMES mpi mpi_independent) endif() From 3c398857c5ec3b80718b4f9a35f3ffd5b6e55b4f Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 13:01:22 +0200 Subject: [PATCH 05/59] Remove parallel HDF5 version check --- plugins/decl_hdf5/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 26d195ada..970eba144 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -51,9 +51,7 @@ find_package(HDF5 REQUIRED COMPONENTS C) if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() -if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) - set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") -endif() + if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "Parallel HDF5 required, sequential HDF5 only found. Please set -DBUILD_HDF5_PARALLEL=OFF to disable parallel HDF5") endif() From dfa8769e19e59d290aa79008c838b25996355e0a Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 13:02:08 +0200 Subject: [PATCH 06/59] Fix HDF5 parallel check in FindNetCDF.cmake --- plugins/decl_netcdf/cmake/FindNetCDF.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/decl_netcdf/cmake/FindNetCDF.cmake b/plugins/decl_netcdf/cmake/FindNetCDF.cmake index b1465e884..0cdd109d5 100644 --- a/plugins/decl_netcdf/cmake/FindNetCDF.cmake +++ b/plugins/decl_netcdf/cmake/FindNetCDF.cmake @@ -369,7 +369,7 @@ if("${NetCDF_FOUND}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT ("${HDF5_PROVIDES_PARALLEL}" OR "${HDF5_IS_PARALLEL}")) + if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT "${HDF5_IS_PARALLEL}") message(ERROR "Parallel HDF5 required by NetCDF, sequential HDF5 only found.") endif() list(APPEND NetCDF_LINK_LIBRARIES hdf5::hdf5) From 94997ce0b7462c816007b1a03a5eb2d98742fa4c Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 13:02:39 +0200 Subject: [PATCH 07/59] Refactor HDF5 version checks in CMakeLists Removed check for HDF5 version greater than 2.0.0 and related variable assignment. --- CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8be96df26..9232a10e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,7 +308,7 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") sbuild_add_dependency(HDF5 "${USE_DEFAULT}" EMBEDDED_PATH "vendor/hdf5-1.12.3" COMPONENTS ${HDF5_COMPONENTS} - MODULE_VARS HDF5_IS_PARALLEL HDF5_PROVIDES_PARALLEL HDF5_VERSION + MODULE_VARS HDF5_IS_PARALLEL HDF5_VERSION CMAKE_CACHE_ARGS -DBUILD_STATIC_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF @@ -326,9 +326,6 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) - set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") - endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "You requested a parallel HDF5 build (-DBUILD_HDF5_PARALLEL=ON) but a sequential SYSTEM version has been found\n" From b980a9d8e0d6c869d2649a5156e441b5638778ed Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 13:43:05 +0200 Subject: [PATCH 08/59] fix indent --- .../HDF5_C/d2s_precision_read_test.c | 19 ++++++++----- .../PDI_C/d2s_precision_read_test.c | 27 ++++++++++++------- .../PDI_C/d2s_precision_write_test.c | 10 +++---- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c index 4f0c0becb..1abb0c990 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c +++ b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c @@ -24,8 +24,8 @@ #include #include -#include #include +#include #define FILE "d2s_test.h5" @@ -52,11 +52,18 @@ int main() return 1; } - for (int i = 0; i < 1000; i++) { - if (fabs(dset_data[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { - fprintf(stderr, "dset_data[%d]: %f != %f, diff = %f\n ", i, dset_data[i], i * 10.0 + 3.141592653589793, fabs(dset_data[i] - (i * 10.0 + 3.141592653589793))); - return 1; - } + for (int i = 0; i < 1000; i++) { + if (fabs(dset_data[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { + fprintf( + stderr, + "dset_data[%d]: %f != %f, diff = %f\n ", + i, + dset_data[i], + i * 10.0 + 3.141592653589793, + fabs(dset_data[i] - (i * 10.0 + 3.141592653589793)) + ); + return 1; + } } status = H5Dclose(dataset_id); diff --git a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c index 9daa53b0f..ac916a623 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c +++ b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c @@ -23,9 +23,9 @@ ******************************************************************************/ #include +#include #include #include -#include #define FILE "d2s_test.h5" @@ -40,10 +40,10 @@ int main() " decl_hdf5: \n" " - file: d2s_test.h5 \n" " datasets: \n" - " float_data: {size: [100, 10], type: array, subtype: float }\n" - " read: \n" - " double_data: \n" - " dataset: float_data \n"; + " float_data: {size: [100, 10], type: array, subtype: float }\n" + " read: \n" + " double_data: \n" + " dataset: float_data \n"; PC_tree_t conf = PC_parse_string(CONFIG_YAML); PDI_init(conf); @@ -53,11 +53,18 @@ int main() } PDI_expose("double_data", test_array, PDI_IN); - for (int i = 0; i < 1000; i++) { - if (fabs(test_array[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { - fprintf(stderr, "test_array[%d] %f != %f, diff = %f\n ", i, test_array[i], i * 10.0 + 3.141592653589793, fabs(test_array[i] - (i * 10.0 + 3.141592653589793))); - return 1; - } + for (int i = 0; i < 1000; i++) { + if (fabs(test_array[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { + fprintf( + stderr, + "test_array[%d] %f != %f, diff = %f\n ", + i, + test_array[i], + i * 10.0 + 3.141592653589793, + fabs(test_array[i] - (i * 10.0 + 3.141592653589793)) + ); + return 1; + } } PDI_finalize(); diff --git a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c index a59faade3..221214455 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c +++ b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c @@ -39,17 +39,17 @@ int main() " decl_hdf5: \n" " - file: d2s_test.h5 \n" " datasets: \n" - " float_data: {size: [100, 10], type: array, subtype: float }\n" - " write: \n" - " double_data: \n" - " dataset: float_data \n"; + " float_data: {size: [100, 10], type: array, subtype: float }\n" + " write: \n" + " double_data: \n" + " dataset: float_data \n"; PC_tree_t conf = PC_parse_string(CONFIG_YAML); PDI_init(conf); double test_array[1000]; for (int i = 0; i < 1000; i++) { - test_array[i] = i * 10.0 + 3.141592653589793; + test_array[i] = i * 10.0 + 3.141592653589793; } PDI_expose("double_data", test_array, PDI_OUT); From 2774595cae5ef7d7bd39261d67c1af7f9b061ef0 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 13:52:11 +0200 Subject: [PATCH 09/59] update decl_hdf5/CHANGELOG.md --- plugins/decl_hdf5/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/decl_hdf5/CHANGELOG.md b/plugins/decl_hdf5/CHANGELOG.md index 7f27d59ca..d36927b02 100644 --- a/plugins/decl_hdf5/CHANGELOG.md +++ b/plugins/decl_hdf5/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added * Add subfiling support [#602](https://github.com/pdidev/pdi/issues/602) +* Add tests for HDF5 precision conversion (data in double precision while dataset declared with simple precision in file) ### Changed From 9e51956c0f6b19934ed72c934c03c508923174ae Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 14:16:24 +0200 Subject: [PATCH 10/59] add cmake fix for version less than 4.3 --- CMakeLists.txt | 15 +- plugins/decl_hdf5/CMakeLists.txt | 3 - plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake | 1423 +++++++++++++++++ .../4.3/SelectLibraryConfigurations.cmake | 187 +++ plugins/decl_netcdf/CMakeLists.txt | 3 + plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake | 1423 +++++++++++++++++ .../4.3/SelectLibraryConfigurations.cmake | 187 +++ plugins/decl_netcdf/cmake/FindNetCDF.cmake | 2 +- 8 files changed, 3235 insertions(+), 8 deletions(-) create mode 100644 plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake create mode 100644 plugins/decl_hdf5/cmake/4.3/SelectLibraryConfigurations.cmake create mode 100644 plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake create mode 100644 plugins/decl_netcdf/cmake/4.3/SelectLibraryConfigurations.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8be96df26..8a8e12c33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,9 +108,19 @@ if("${BUILD_DECL_NETCDF_PLUGIN}") # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 if(4.1 VERSION_GREATER "${CMAKE_VERSION}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake/4.1") + elseif(4.3 VERSION_GREATER "${CMAKE_VERSION}") + # Workaround conpiling with HDF5-2.0.0+ + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake/4.3") endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake") endif() +if("${BUILD_DECL_HDF5_PLUGIN}") + # Workaround conpiling with HDF5-2.0.0+ + if(4.3 VERSION_GREATER "${CMAKE_VERSION}") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake/4.3") + endif() + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake") +endif() set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" CACHE STRING "" FORCE) @@ -308,7 +318,7 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") sbuild_add_dependency(HDF5 "${USE_DEFAULT}" EMBEDDED_PATH "vendor/hdf5-1.12.3" COMPONENTS ${HDF5_COMPONENTS} - MODULE_VARS HDF5_IS_PARALLEL HDF5_PROVIDES_PARALLEL HDF5_VERSION + MODULE_VARS HDF5_IS_PARALLEL HDF5_VERSION CMAKE_CACHE_ARGS -DBUILD_STATIC_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF @@ -326,9 +336,6 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) - set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") - endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "You requested a parallel HDF5 build (-DBUILD_HDF5_PARALLEL=ON) but a sequential SYSTEM version has been found\n" diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 26d195ada..3b3045c2d 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -51,9 +51,6 @@ find_package(HDF5 REQUIRED COMPONENTS C) if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() -if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) - set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") -endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "Parallel HDF5 required, sequential HDF5 only found. Please set -DBUILD_HDF5_PARALLEL=OFF to disable parallel HDF5") endif() diff --git a/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake b/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake new file mode 100644 index 000000000..0a15557f0 --- /dev/null +++ b/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake @@ -0,0 +1,1423 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindHDF5 +-------- + +Finds Hierarchical Data Format (HDF5), a library for reading and writing +self-describing array data: + +.. code-block:: cmake + + find_package(HDF5 [] [COMPONENTS ...] [...]) + +If the HDF5 library is built using its CMake-based build system, it will as +of HDF5 version 1.8.15 provide its own CMake Package Configuration file +(``hdf5-config.cmake``) for use with the :command:`find_package` command in +*config mode*. By default, this module searches for this file and, if found, +returns the results based on the found configuration. + +If the upstream configuration file is not found, this module falls back to +*module mode* and invokes the HDF5 wrapper compiler typically installed +with the HDF5 library. Depending on the configuration, this wrapper +compiler is named either ``h5cc`` (serial) or ``h5pcc`` (parallel). If +found, the wrapper is queried with the ``-show`` argument to determine the +compiler and linker flags required for building an HDF5 client application. +Both serial and parallel versions of the HDF5 wrapper are considered. The +first directory containing either is used. If both versions are found in the +same directory, the serial version is preferred by default. To change this +behavior, set the variable ``HDF5_PREFER_PARALLEL`` to ``TRUE``. + +In addition to finding the include directories and libraries needed to compile +an HDF5 application, this module also attempts to find additional tools +provided by the HDF5 distribution, which can be useful for regression testing +or development workflows. + +Components +^^^^^^^^^^ + +This module supports optional components, which can be specified with the +:command:`find_package` command: + +.. code-block:: cmake + + find_package(HDF5 [COMPONENTS ...]) + +Supported components include: + +``C`` + Finds the ``HDF5`` C library (C bindings). + +``CXX`` + Finds the ``HDF5`` C++ library (C++ bindings). + +``Fortran`` + Finds the ``HDF5`` Fortran library (Fortran bindings). + +``HL`` + This component can be used in combination with other components to find the + high-level (HL) HDF5 library variants for C, CXX, and/or Fortran, which + provide high-level functions. + +If no components are specified, then this module will by default search for the +``C`` component. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following :ref:`Imported Targets`: + +``HDF5::HDF5`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for all found HDF5 binding + libraries (``HDF5_LIBRARIES``), available if HDF5 and all required components + are found. + +``hdf5::hdf5`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 C library, available + if HDF5 library and its ``C`` component are found. + +``hdf5::hdf5_cpp`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 C and C++ libraries, + available if HDF5 library, and its ``C`` and ``CXX`` components are found. + +``hdf5::hdf5_fortran`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 Fortran library, + available if HDF5 library and its ``Fortran`` component are found. + +``hdf5::hdf5_hl`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 high-level C library, + available if HDF5 library and its ``C``, and ``HL`` components are found. + +``hdf5::hdf5_hl_cpp`` + .. versionadded:: 3.19 + + High-level C++ library. + + Target encapsulating the usage requirements for the HDF5 high-level C and + high-level C++ libraries, available if HDF5 library and its ``C``, ``CXX``, + and ``HL`` components are found. + +``hdf5::hdf5_hl_fortran`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 high-level Fortran + library, available if HDF5 library and its ``Fortran``, and ``HL`` components + are found. + +``hdf5::h5diff`` + .. versionadded:: 3.19 + + Imported executable target encapsulating the usage requirements for the + ``h5diff`` executable, available if ``h5diff`` is found. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module defines the following variables: + +``HDF5_FOUND`` + Boolean indicating whether (the requested version of) HDF5 was found. + +``HDF5_VERSION`` + .. versionadded:: 3.3 + + The version of HDF5 library found. + +``HDF5_INCLUDE_DIRS`` + Include directories containing header files needed to use HDF5. + +``HDF5_DEFINITIONS`` + Required compiler definitions for using HDF5. + +``HDF5_LIBRARIES`` + Libraries of all requested bindings needed to link against to use HDF5. + +``HDF5_HL_LIBRARIES`` + Required libraries for the HDF5 high-level API for all bindings, + if the ``HL`` component is enabled. + +``HDF5_IS_PARALLEL`` + Boolean indicating whether the HDF5 library has parallel IO support. + +For each enabled language binding component, a corresponding +``HDF5__LIBRARIES`` variable, and potentially +``HDF5__DEFINITIONS``, will be defined. If the ``HL`` component is +enabled, then ``HDF5__HL_LIBRARIES`` variables will also be defined: + +``HDF5_C_DEFINITIONS`` + Required compiler definitions for HDF5 C bindings. + +``HDF5_CXX_DEFINITIONS`` + Required compiler definitions for HDF5 C++ bindings. + +``HDF5_Fortran_DEFINITIONS`` + Required compiler definitions for HDF5 Fortran bindings. + +``HDF5_C_INCLUDE_DIRS`` + Required include directories for HDF5 C bindings. + +``HDF5_CXX_INCLUDE_DIRS`` + Required include directories for HDF5 C++ bindings. + +``HDF5_Fortran_INCLUDE_DIRS`` + Required include directories for HDF5 Fortran bindings. + +``HDF5_C_LIBRARIES`` + Required libraries for the HDF5 C bindings. + +``HDF5_CXX_LIBRARIES`` + Required libraries for the HDF5 C++ bindings. + +``HDF5_Fortran_LIBRARIES`` + Required libraries for the HDF5 Fortran bindings. + +``HDF5_C_HL_LIBRARIES`` + Required libraries for the high-level C bindings, if the ``HL`` component + is enabled. + +``HDF5_CXX_HL_LIBRARIES`` + Required libraries for the high-level C++ bindings, if the ``HL`` + component is enabled. + +``HDF5_Fortran_HL_LIBRARIES`` + Required libraries for the high-level Fortran bindings, if the ``HL`` + component is enabled. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``HDF5_C_COMPILER_EXECUTABLE`` + The path to the HDF5 C wrapper compiler. + +``HDF5_CXX_COMPILER_EXECUTABLE`` + The path to the HDF5 C++ wrapper compiler. + +``HDF5_Fortran_COMPILER_EXECUTABLE`` + The path to the HDF5 Fortran wrapper compiler. + +``HDF5_C_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary C compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_CXX_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary C++ compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_Fortran_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary Fortran compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_DIFF_EXECUTABLE`` + The path to the HDF5 dataset comparison tool (``h5diff``). + +Hints +^^^^^ + +The following variables can be set before calling the ``find_package(HDF5)`` +to guide the search for HDF5 library: + +``HDF5_PREFER_PARALLEL`` + .. versionadded:: 3.4 + + Set this to boolean true to prefer parallel HDF5 (by default, serial is + preferred). This variable is used only in *module mode*. + +``HDF5_FIND_DEBUG`` + .. versionadded:: 3.9 + + Set this to boolean true to get extra debugging output by this module. + +``HDF5_NO_FIND_PACKAGE_CONFIG_FILE`` + .. versionadded:: 3.8 + + Set this to boolean true to skip finding and using CMake package configuration + file (``hdf5-config.cmake``). + +``HDF5_USE_STATIC_LIBRARIES`` + Set this to boolean value to determine whether or not to prefer a + static link to a dynamic link for ``HDF5`` and all of its dependencies. + + .. versionadded:: 3.10 + Support for ``HDF5_USE_STATIC_LIBRARIES`` on Windows. + +Examples +^^^^^^^^ + +Examples: Finding HDF5 +"""""""""""""""""""""" + +Finding HDF5: + +.. code-block:: cmake + + find_package(HDF5) + +Specifying a minimum required version of HDF5 to find: + +.. code-block:: cmake + + find_package(HDF5 1.8.15) + +Finding HDF5 and making it required (if HDF5 is not found, processing stops with +an error message): + +.. code-block:: cmake + + find_package(HDF5 1.8.15 REQUIRED) + +Searching for static HDF5 libraries: + +.. code-block:: cmake + + set(HDF5_USE_STATIC_LIBRARIES TRUE) + find_package(HDF5) + +Specifying components to find high-level C and C++ functions: + +.. code-block:: cmake + + find_package(HDF5 COMPONENTS C CXX HL) + +Examples: Using HDF5 +"""""""""""""""""""" + +Finding HDF5 and linking it to a project target: + +.. code-block:: cmake + + find_package(HDF5) + target_link_libraries(project_target PRIVATE HDF5::HDF5) + +Using Fortran HDF5 and HDF5-HL functions: + +.. code-block:: cmake + + find_package(HDF5 COMPONENTS Fortran HL) + target_link_libraries(project_target PRIVATE HDF5::HDF5) +#]=======================================================================] + +include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) +include(FindPackageHandleStandardArgs) + +cmake_policy(PUSH) +cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_ + +# We haven't found HDF5 yet. Clear its state in case it is set in the parent +# scope somewhere else. We can't rely on it because different components may +# have been requested for this call. +set(HDF5_FOUND OFF) +set(HDF5_LIBRARIES) +set(HDF5_HL_LIBRARIES) + +# List of the valid HDF5 components +set(HDF5_VALID_LANGUAGE_BINDINGS C CXX Fortran) + +# Validate the list of find components. +if(NOT HDF5_FIND_COMPONENTS) + set(HDF5_LANGUAGE_BINDINGS "C") +else() + set(HDF5_LANGUAGE_BINDINGS) + # add the extra specified components, ensuring that they are valid. + set(HDF5_FIND_HL OFF) + foreach(_component IN LISTS HDF5_FIND_COMPONENTS) + list(FIND HDF5_VALID_LANGUAGE_BINDINGS ${_component} _component_location) + if(NOT _component_location EQUAL -1) + list(APPEND HDF5_LANGUAGE_BINDINGS ${_component}) + elseif(_component STREQUAL "HL") + set(HDF5_FIND_HL ON) + elseif(_component STREQUAL "Fortran_HL") # only for compatibility + list(APPEND HDF5_LANGUAGE_BINDINGS Fortran) + set(HDF5_FIND_HL ON) + set(HDF5_FIND_REQUIRED_Fortran_HL FALSE) + set(HDF5_FIND_REQUIRED_Fortran TRUE) + set(HDF5_FIND_REQUIRED_HL TRUE) + else() + message(FATAL_ERROR "${_component} is not a valid HDF5 component.") + endif() + endforeach() + unset(_component) + unset(_component_location) + if(NOT HDF5_LANGUAGE_BINDINGS) + get_property(_langs GLOBAL PROPERTY ENABLED_LANGUAGES) + foreach(_lang IN LISTS _langs) + if(_lang MATCHES "^(C|CXX|Fortran)$") + list(APPEND HDF5_LANGUAGE_BINDINGS ${_lang}) + endif() + endforeach() + endif() + list(REMOVE_ITEM HDF5_FIND_COMPONENTS Fortran_HL) # replaced by Fortran and HL + list(REMOVE_DUPLICATES HDF5_LANGUAGE_BINDINGS) +endif() + +# Determine whether to search for serial or parallel executable first +if(HDF5_PREFER_PARALLEL) + set(HDF5_C_COMPILER_NAMES h5pcc h5cc) + set(HDF5_CXX_COMPILER_NAMES h5pc++ h5c++) + set(HDF5_Fortran_COMPILER_NAMES h5pfc h5fc) +else() + set(HDF5_C_COMPILER_NAMES h5cc h5pcc) + set(HDF5_CXX_COMPILER_NAMES h5c++ h5pc++) + set(HDF5_Fortran_COMPILER_NAMES h5fc h5pfc) +endif() + +# Prefer h5hl compilers if HDF5_FIND_HL is enabled +if(HDF5_FIND_HL) + list(PREPEND HDF5_C_COMPILER_NAMES h5hlcc) + list(PREPEND HDF5_CXX_COMPILER_NAMES h5hlc++) + list(PREPEND HDF5_Fortran_COMPILER_NAMES h5hlfc) +endif() + +# Test first if the current compilers automatically wrap HDF5 +function(_HDF5_test_regular_compiler_C success version is_parallel) + if(NOT ${success} OR + NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "#include \n" + "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" + "#ifdef H5_HAVE_PARALLEL\n" + "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" + "#endif\n" + "int main(int argc, char **argv) {\n" + " int require = 0;\n" + " require += info_ver[argc];\n" + "#ifdef H5_HAVE_PARALLEL\n" + " require += info_parallel[argc];\n" + "#endif\n" + " hid_t fid;\n" + " fid = H5Fcreate(\"foo.h5\",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);\n" + " return 0;\n" + "}") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_c + ) + endif() + if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c) + file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_c INFO_STRINGS + REGEX "^INFO:" + ) + string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" + INFO_VER "${INFO_STRINGS}" + ) + set(${version} ${CMAKE_MATCH_1}) + if(CMAKE_MATCH_3) + set(${version} ${HDF5_C_VERSION}.${CMAKE_MATCH_3}) + endif() + set(${version} ${${version}} PARENT_SCOPE) + + if(INFO_STRINGS MATCHES "INFO:PARALLEL") + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() +endfunction() + +function(_HDF5_test_regular_compiler_CXX success version is_parallel) + if(NOT ${success} OR + NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "#include \n" + "#ifndef H5_NO_NAMESPACE\n" + "using namespace H5;\n" + "#endif\n" + "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" + "#ifdef H5_HAVE_PARALLEL\n" + "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" + "#endif\n" + "int main(int argc, char **argv) {\n" + " int require = 0;\n" + " require += info_ver[argc];\n" + "#ifdef H5_HAVE_PARALLEL\n" + " require += info_parallel[argc];\n" + "#endif\n" + " H5File file(\"foo.h5\", H5F_ACC_TRUNC);\n" + " return 0;\n" + "}") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_cxx + ) + endif() + if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx) + file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx INFO_STRINGS + REGEX "^INFO:" + ) + string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" + INFO_VER "${INFO_STRINGS}" + ) + set(${version} ${CMAKE_MATCH_1}) + if(CMAKE_MATCH_3) + set(${version} ${HDF5_CXX_VERSION}.${CMAKE_MATCH_3}) + endif() + set(${version} ${${version}} PARENT_SCOPE) + + if(INFO_STRINGS MATCHES "INFO:PARALLEL") + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() +endfunction() + +function(_HDF5_test_regular_compiler_Fortran success is_parallel) + if(NOT ${success}) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "program hdf5_hello\n" + " use hdf5\n" + " integer error\n" + " call h5open_f(error)\n" + " call h5close_f(error)\n" + "end\n") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}") + if(${success}) + execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -showconfig + OUTPUT_VARIABLE config_output + ERROR_VARIABLE config_error + RESULT_VARIABLE config_result + ) + if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)") + # The value may be anything used when HDF5 was configured, + # so see if CMake interprets it as "true". + set(parallelHDF5 "${CMAKE_MATCH_1}") + if(parallelHDF5) + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() + endif() +endfunction() + +# Invoke the HDF5 wrapper compiler. The compiler return value is stored to the +# return_value argument, the text output is stored to the output variable. +function( _HDF5_invoke_compiler language output_var return_value_var version_var is_parallel_var) + set(is_parallel FALSE) + if(HDF5_USE_STATIC_LIBRARIES) + set(lib_type_args -noshlib) + else() + set(lib_type_args -shlib) + endif() + # Verify that the compiler wrapper can actually compile: sometimes the compiler + # wrapper exists, but not the compiler. E.g. Miniconda / Anaconda Python + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} "${_HDF5_TEST_SRC}" + WORKING_DIRECTORY ${_HDF5_TEST_DIR} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE return_value + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.") + endif() + else() + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -show ${lib_type_args} "${_HDF5_TEST_SRC}" + WORKING_DIRECTORY ${_HDF5_TEST_DIR} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE return_value + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "Unable to determine HDF5 ${language} flags from HDF5 wrapper.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "Unable to determine HDF5 ${language} flags from HDF5 wrapper.") + endif() + endif() + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -showconfig + OUTPUT_VARIABLE config_output + ERROR_VARIABLE config_output + RESULT_VARIABLE return_value + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.") + endif() + endif() + string(REGEX MATCH "HDF5 Version: ([a-zA-Z0-9\\.\\-]*)" version "${config_output}") + if(version) + string(REPLACE "HDF5 Version: " "" version "${version}") + string(REPLACE "-patch" "." version "${version}") + endif() + if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)") + # The value may be anything used when HDF5 was configured, + # so see if CMake interprets it as "true". + set(parallelHDF5 "${CMAKE_MATCH_1}") + if(parallelHDF5) + set(is_parallel TRUE) + endif() + endif() + endif() + foreach(var output return_value version is_parallel) + set(${${var}_var} ${${var}} PARENT_SCOPE) + endforeach() +endfunction() + +# Parse a compile line for definitions, includes, library paths, and libraries. +function(_HDF5_parse_compile_line compile_line_var include_paths definitions + library_paths libraries libraries_hl) + + separate_arguments(_compile_args NATIVE_COMMAND "${${compile_line_var}}") + + foreach(_arg IN LISTS _compile_args) + if("${_arg}" MATCHES "^-I(.*)$") + # include directory + list(APPEND include_paths "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-D(.*)$") + # compile definition + list(APPEND definitions "-D${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-L(.*)$") + # library search path + list(APPEND library_paths "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-l(hdf5.*hl.*)$") + # library name (hl) + list(APPEND libraries_hl "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-l(.*)$") + # library name + list(APPEND libraries "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^(.:)?[/\\].*\\.(a|so|dylib|sl|lib)$") + # library file + if(NOT EXISTS "${_arg}") + continue() + endif() + get_filename_component(_lpath "${_arg}" DIRECTORY) + get_filename_component(_lname "${_arg}" NAME_WE) + string(REGEX REPLACE "^lib" "" _lname "${_lname}") + list(APPEND library_paths "${_lpath}") + if(_lname MATCHES "hdf5.*hl") + list(APPEND libraries_hl "${_lname}") + else() + list(APPEND libraries "${_lname}") + endif() + endif() + endforeach() + foreach(var include_paths definitions library_paths libraries libraries_hl) + set(${${var}_var} ${${var}} PARENT_SCOPE) + endforeach() +endfunction() + +# Select a preferred imported configuration from a target +function(_HDF5_select_imported_config target imported_conf) + # We will first assign the value to a local variable _imported_conf, then assign + # it to the function argument at the end. + get_target_property(_imported_conf ${target} MAP_IMPORTED_CONFIG_${CMAKE_BUILD_TYPE}) + if (NOT _imported_conf) + # Get available imported configurations by examining target properties + get_target_property(_imported_conf ${target} IMPORTED_CONFIGURATIONS) + if(HDF5_FIND_DEBUG) + message(STATUS "Found imported configurations: ${_imported_conf}") + endif() + # Find the imported configuration that we prefer. + # We do this by making list of configurations in order of preference, + # starting with ${CMAKE_BUILD_TYPE} and ending with the first imported_conf + set(_preferred_confs ${CMAKE_BUILD_TYPE}) + list(GET _imported_conf 0 _fallback_conf) + list(APPEND _preferred_confs RELWITHDEBINFO RELEASE DEBUG ${_fallback_conf}) + if(HDF5_FIND_DEBUG) + message(STATUS "Start search through imported configurations in the following order: ${_preferred_confs}") + endif() + # Now find the first of these that is present in imported_conf + foreach (_conf IN LISTS _preferred_confs) + if (${_conf} IN_LIST _imported_conf) + set(_imported_conf ${_conf}) + break() + endif() + endforeach() + endif() + if(HDF5_FIND_DEBUG) + message(STATUS "Selected imported configuration: ${_imported_conf}") + endif() + # assign value to function argument + set(${imported_conf} ${_imported_conf} PARENT_SCOPE) +endfunction() + + +if(NOT HDF5_ROOT) + set(HDF5_ROOT $ENV{HDF5_ROOT}) +endif() +if(HDF5_ROOT) + set(_HDF5_SEARCH_OPTS NO_DEFAULT_PATH) +else() + set(_HDF5_SEARCH_OPTS) +endif() + +# Try to find HDF5 using an installed hdf5-config.cmake +if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE) + find_package(HDF5 QUIET NO_MODULE + HINTS ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS} + ) + if( HDF5_FOUND) + if(HDF5_FIND_DEBUG) + message(STATUS "Found HDF5 at ${HDF5_DIR} via NO_MODULE. Now trying to extract locations etc.") + endif() + # Extract information from imported targets + if (DEFINED HDF5_ENABLE_PARALLEL) + # Versions of <2.0.0 use `HDF5_ENABLE_PARALLEL` + set(HDF5_IS_PARALLEL ${HDF5_ENABLE_PARALLEL}) + elseif(DEFINED HDF5_PROVIDES_PARALLEL) + # Versions of >=2.0.0 use `HDF5_PROVIDES_PARALLEL` + set(HDF5_IS_PARALLEL ${HDF5_PROVIDES_PARALLEL}) + else() + set(HDF5_IS_PARALLEL NONE) + endif() + set(HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR}) + set(HDF5_LIBRARIES) + if (NOT TARGET hdf5 AND NOT TARGET hdf5-static AND NOT TARGET hdf5-shared) + # Some HDF5 versions (e.g. 1.8.18) used hdf5::hdf5 etc + set(_target_prefix "hdf5::") + endif() + set(HDF5_C_TARGET ${_target_prefix}hdf5) + set(HDF5_C_HL_TARGET ${_target_prefix}hdf5_hl) + set(HDF5_CXX_TARGET ${_target_prefix}hdf5_cpp) + set(HDF5_CXX_HL_TARGET ${_target_prefix}hdf5_hl_cpp) + set(HDF5_Fortran_TARGET ${_target_prefix}hdf5_fortran) + set(HDF5_Fortran_HL_TARGET ${_target_prefix}hdf5_hl_fortran) + set(HDF5_DEFINITIONS "") + if(HDF5_USE_STATIC_LIBRARIES) + set(_suffix "-static") + else() + set(_suffix "-shared") + endif() + foreach(_lang ${HDF5_LANGUAGE_BINDINGS}) + + #Older versions of hdf5 don't have a static/shared suffix so + #if we detect that occurrence clear the suffix + if(_suffix AND NOT TARGET ${HDF5_${_lang}_TARGET}${_suffix}) + if(NOT TARGET ${HDF5_${_lang}_TARGET}) + #can't find this component with or without the suffix + #so bail out, and let the following locate HDF5 + set(HDF5_FOUND FALSE) + break() + endif() + set(_suffix "") + endif() + + if(HDF5_FIND_DEBUG) + message(STATUS "Trying to get properties of target ${HDF5_${_lang}_TARGET}${_suffix}") + endif() + # Find library for this target. Complicated as on Windows with a DLL, we need to search for the import-lib. + _HDF5_select_imported_config(${HDF5_${_lang}_TARGET}${_suffix} _hdf5_imported_conf) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_location) + # no import lib, just try LOCATION + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_lang_location) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION) + endif() + endif() + if( _hdf5_lang_location ) + set(HDF5_${_lang}_LIBRARY ${_hdf5_lang_location}) + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) + set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) + set(HDF5_${_lang}_FOUND TRUE) + endif() + if(HDF5_FIND_HL) + get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_hl_location) + get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_hl_lang_location) + get_target_property(_hdf5_hl_lang_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION) + endif() + endif() + if( _hdf5_lang_hl_location ) + set(HDF5_${_lang}_HL_LIBRARY ${_hdf5_lang_hl_location}) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) + set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) + set(HDF5_HL_FOUND TRUE) + endif() + unset(_hdf5_lang_hl_location) + endif() + unset(_hdf5_imported_conf) + unset(_hdf5_lang_location) + endforeach() + endif() +endif() + +if(NOT HDF5_FOUND) + set(_HDF5_NEED_TO_SEARCH FALSE) + set(_HDF5_TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5) + set(HDF5_COMPILER_NO_INTERROGATE TRUE) + # Only search for languages we've enabled + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + # First check to see if our regular compiler is one of wrappers + if(_lang STREQUAL "C") + set(_HDF5_TEST_SRC cmake_hdf5_test.c) + if(CMAKE_CXX_COMPILER_LOADED AND NOT CMAKE_C_COMPILER_LOADED) + # CXX project without C enabled + set(_HDF5_TEST_SRC cmake_hdf5_test.cxx) + endif() + _HDF5_test_regular_compiler_C( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_VERSION + HDF5_${_lang}_IS_PARALLEL) + elseif(_lang STREQUAL "CXX") + set(_HDF5_TEST_SRC cmake_hdf5_test.cxx) + _HDF5_test_regular_compiler_CXX( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_VERSION + HDF5_${_lang}_IS_PARALLEL) + elseif(_lang STREQUAL "Fortran") + set(_HDF5_TEST_SRC cmake_hdf5_test.f90) + _HDF5_test_regular_compiler_Fortran( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_IS_PARALLEL) + else() + continue() + endif() + if(HDF5_${_lang}_COMPILER_NO_INTERROGATE) + if(HDF5_FIND_DEBUG) + message(STATUS "HDF5: Using hdf5 compiler wrapper for all ${_lang} compiling") + endif() + set(HDF5_${_lang}_FOUND TRUE) + set(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE + "${CMAKE_${_lang}_COMPILER}" + CACHE FILEPATH "HDF5 ${_lang} compiler wrapper") + set(HDF5_${_lang}_DEFINITIONS) + set(HDF5_${_lang}_INCLUDE_DIRS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + mark_as_advanced(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE) + + set(HDF5_${_lang}_FOUND TRUE) + set(HDF5_HL_FOUND TRUE) + else() + set(HDF5_COMPILER_NO_INTERROGATE FALSE) + # If this language isn't using the wrapper, then try to seed the + # search options with the wrapper + find_program(HDF5_${_lang}_COMPILER_EXECUTABLE + NAMES ${HDF5_${_lang}_COMPILER_NAMES} NAMES_PER_DIR + HINTS ${HDF5_ROOT} + PATH_SUFFIXES bin Bin + DOC "HDF5 ${_lang} Wrapper compiler. Used only to detect HDF5 compile flags." + ${_HDF5_SEARCH_OPTS} + ) + mark_as_advanced( HDF5_${_lang}_COMPILER_EXECUTABLE ) + unset(HDF5_${_lang}_COMPILER_NAMES) + + if(HDF5_${_lang}_COMPILER_EXECUTABLE) + _HDF5_invoke_compiler(${_lang} HDF5_${_lang}_COMPILE_LINE + HDF5_${_lang}_RETURN_VALUE HDF5_${_lang}_VERSION HDF5_${_lang}_IS_PARALLEL) + if(HDF5_${_lang}_RETURN_VALUE EQUAL 0) + if(HDF5_FIND_DEBUG) + message(STATUS "HDF5: Using hdf5 compiler wrapper to determine ${_lang} configuration") + endif() + _HDF5_parse_compile_line( HDF5_${_lang}_COMPILE_LINE + HDF5_${_lang}_INCLUDE_DIRS + HDF5_${_lang}_DEFINITIONS + HDF5_${_lang}_LIBRARY_DIRS + HDF5_${_lang}_LIBRARY_NAMES + HDF5_${_lang}_HL_LIBRARY_NAMES + ) + set(HDF5_${_lang}_LIBRARIES) + + foreach(_lib IN LISTS HDF5_${_lang}_LIBRARY_NAMES) + set(_HDF5_SEARCH_NAMES_LOCAL) + if("x${_lib}" MATCHES "hdf5") + # hdf5 library + set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) + if(HDF5_USE_STATIC_LIBRARIES) + if(WIN32) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) + else() + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) + endif() + endif() + else() + # external library + set(_HDF5_SEARCH_OPTS_LOCAL) + endif() + find_library(HDF5_${_lang}_LIBRARY_${_lib} + NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR + HINTS ${HDF5_${_lang}_LIBRARY_DIRS} + ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS_LOCAL} + ) + unset(_HDF5_SEARCH_OPTS_LOCAL) + unset(_HDF5_SEARCH_NAMES_LOCAL) + if(HDF5_${_lang}_LIBRARY_${_lib}) + list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) + else() + list(APPEND HDF5_${_lang}_LIBRARIES ${_lib}) + endif() + endforeach() + if(HDF5_FIND_HL) + set(HDF5_${_lang}_HL_LIBRARIES) + foreach(_lib IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) + set(_HDF5_SEARCH_NAMES_LOCAL) + if("x${_lib}" MATCHES "hdf5") + # hdf5 library + set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) + if(HDF5_USE_STATIC_LIBRARIES) + if(WIN32) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) + else() + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) + endif() + endif() + else() + # external library + set(_HDF5_SEARCH_OPTS_LOCAL) + endif() + find_library(HDF5_${_lang}_LIBRARY_${_lib} + NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR + HINTS ${HDF5_${_lang}_LIBRARY_DIRS} + ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS_LOCAL} + ) + unset(_HDF5_SEARCH_OPTS_LOCAL) + unset(_HDF5_SEARCH_NAMES_LOCAL) + if(HDF5_${_lang}_LIBRARY_${_lib}) + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) + else() + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${_lib}) + endif() + endforeach() + set(HDF5_HL_FOUND TRUE) + endif() + + set(HDF5_${_lang}_FOUND TRUE) + list(REMOVE_DUPLICATES HDF5_${_lang}_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_${_lang}_INCLUDE_DIRS) + else() + set(_HDF5_NEED_TO_SEARCH TRUE) + endif() + else() + set(_HDF5_NEED_TO_SEARCH TRUE) + endif() + endif() + if(HDF5_${_lang}_VERSION) + if(NOT HDF5_VERSION) + set(HDF5_VERSION ${HDF5_${_lang}_VERSION}) + elseif(NOT HDF5_VERSION VERSION_EQUAL HDF5_${_lang}_VERSION) + message(WARNING "HDF5 Version found for language ${_lang}, ${HDF5_${_lang}_VERSION} is different than previously found version ${HDF5_VERSION}") + endif() + endif() + if(DEFINED HDF5_${_lang}_IS_PARALLEL) + if(NOT DEFINED HDF5_IS_PARALLEL) + set(HDF5_IS_PARALLEL ${HDF5_${_lang}_IS_PARALLEL}) + elseif(NOT HDF5_IS_PARALLEL AND HDF5_${_lang}_IS_PARALLEL) + message(WARNING "HDF5 found for language ${_lang} is parallel but previously found language is not parallel.") + elseif(HDF5_IS_PARALLEL AND NOT HDF5_${_lang}_IS_PARALLEL) + message(WARNING "HDF5 found for language ${_lang} is not parallel but previously found language is parallel.") + endif() + endif() + endforeach() + unset(_HDF5_TEST_DIR) + unset(_HDF5_TEST_SRC) + unset(_lib) +else() + set(_HDF5_NEED_TO_SEARCH TRUE) +endif() + +if(NOT HDF5_FOUND AND HDF5_COMPILER_NO_INTERROGATE) + # No arguments necessary, all languages can use the compiler wrappers + set(HDF5_FOUND TRUE) + set(HDF5_METHOD "Included by compiler wrappers") + set(HDF5_REQUIRED_VARS HDF5_METHOD) +elseif(NOT HDF5_FOUND AND NOT _HDF5_NEED_TO_SEARCH) + # Compiler wrappers aren't being used by the build but were found and used + # to determine necessary include and library flags + set(HDF5_INCLUDE_DIRS) + set(HDF5_LIBRARIES) + set(HDF5_HL_LIBRARIES) + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + if(HDF5_${_lang}_FOUND) + if(NOT HDF5_${_lang}_COMPILER_NO_INTERROGATE) + list(APPEND HDF5_DEFINITIONS ${HDF5_${_lang}_DEFINITIONS}) + list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIRS}) + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) + if(HDF5_FIND_HL) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) + endif() + endif() + endif() + endforeach() + list(REMOVE_DUPLICATES HDF5_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) + set(HDF5_FOUND TRUE) + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES) + if(HDF5_FIND_HL) + list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) + endif() +endif() + +find_program( HDF5_DIFF_EXECUTABLE + NAMES h5diff + HINTS ${HDF5_ROOT} + PATH_SUFFIXES bin Bin + ${_HDF5_SEARCH_OPTS} + DOC "HDF5 file differencing tool." ) +mark_as_advanced( HDF5_DIFF_EXECUTABLE ) + +if( NOT HDF5_FOUND ) + # seed the initial lists of libraries to find with items we know we need + set(HDF5_C_LIBRARY_NAMES hdf5) + set(HDF5_C_HL_LIBRARY_NAMES hdf5_hl ${HDF5_C_LIBRARY_NAMES} ) + + set(HDF5_CXX_LIBRARY_NAMES hdf5_cpp ${HDF5_C_LIBRARY_NAMES}) + set(HDF5_CXX_HL_LIBRARY_NAMES hdf5_hl_cpp ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_CXX_LIBRARY_NAMES}) + + set(HDF5_Fortran_LIBRARY_NAMES hdf5_fortran ${HDF5_C_LIBRARY_NAMES}) + set(HDF5_Fortran_HL_LIBRARY_NAMES hdf5_hl_fortran hdf5hl_fortran ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_Fortran_LIBRARY_NAMES}) + + # suffixes as seen on Linux, MSYS2, ... + set(_lib_suffixes hdf5) + if(NOT HDF5_PREFER_PARALLEL) + list(APPEND _lib_suffixes hdf5/serial) + endif() + if(HDF5_USE_STATIC_LIBRARIES) + set(_inc_suffixes include/static) + else() + set(_inc_suffixes include/shared) + endif() + + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + # The "main" library. + set(_hdf5_main_library "") + + # find the HDF5 libraries + foreach(LIB IN LISTS HDF5_${_lang}_LIBRARY_NAMES) + if(HDF5_USE_STATIC_LIBRARIES) + # According to bug 1643 on the CMake bug tracker, this is the + # preferred method for searching for a static library. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search + # first for the full static library name, but fall back to a + # generic search on the name if the static search fails. + set( THIS_LIBRARY_SEARCH_DEBUG + lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug + lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_D-static ${LIB}_debug-static ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a ${LIB}-static) + else() + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) + set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) + if(WIN32) + list(APPEND HDF5_DEFINITIONS "-DH5_BUILT_AS_DYNAMIC_LIB") + endif() + endif() + find_library(HDF5_${LIB}_LIBRARY_DEBUG + NAMES ${THIS_LIBRARY_SEARCH_DEBUG} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + find_library(HDF5_${LIB}_LIBRARY_RELEASE + NAMES ${THIS_LIBRARY_SEARCH_RELEASE} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + + # Set the "main" library if not already set. + if (NOT _hdf5_main_library) + if (HDF5_${LIB}_LIBRARY_RELEASE) + set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_RELEASE}") + elseif (HDF5_${LIB}_LIBRARY_DEBUG) + set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_DEBUG}") + endif () + endif () + + select_library_configurations( HDF5_${LIB} ) + list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${LIB}_LIBRARY}) + endforeach() + if(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_FOUND TRUE) + endif() + + # Append the libraries for this language binding to the list of all + # required libraries. + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) + + # find the HDF5 include directories + set(_hdf5_inc_extra_paths) + set(_hdf5_inc_extra_suffixes) + if("${_lang}" STREQUAL "Fortran") + set(HDF5_INCLUDE_FILENAME hdf5.mod HDF5.mod) + + # Add library-based search paths for Fortran modules. + if (NOT _hdf5_main_library STREQUAL "") + # gfortran module directory + if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "LCC") + get_filename_component(_hdf5_library_dir "${_hdf5_main_library}" DIRECTORY) + list(APPEND _hdf5_inc_extra_paths "${_hdf5_library_dir}") + unset(_hdf5_library_dir) + list(APPEND _hdf5_inc_extra_suffixes gfortran/modules) + endif () + endif () + elseif("${_lang}" STREQUAL "CXX") + set(HDF5_INCLUDE_FILENAME H5Cpp.h) + else() + set(HDF5_INCLUDE_FILENAME hdf5.h) + endif() + + unset(_hdf5_main_library) + + find_path(HDF5_${_lang}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME} + HINTS ${HDF5_ROOT} + PATHS $ENV{HOME}/.local/include ${_hdf5_inc_extra_paths} + PATH_SUFFIXES include Include ${_inc_suffixes} ${_lib_suffixes} ${_hdf5_inc_extra_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + mark_as_advanced(HDF5_${_lang}_INCLUDE_DIR) + unset(_hdf5_inc_extra_paths) + unset(_hdf5_inc_extra_suffixes) + # set the _DIRS variable as this is what the user will normally use + set(HDF5_${_lang}_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) + list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) + + if(HDF5_FIND_HL) + foreach(LIB IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) + if(HDF5_USE_STATIC_LIBRARIES) + # According to bug 1643 on the CMake bug tracker, this is the + # preferred method for searching for a static library. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search + # first for the full static library name, but fall back to a + # generic search on the name if the static search fails. + set( THIS_LIBRARY_SEARCH_DEBUG + lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug + lib${LIB}d-static.a lib${LIB}_debug-static.a lib${LIB}d-static lib${LIB}_D-static lib${LIB}_debug-static ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a lib${LIB}-static) + else() + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) + set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) + endif() + find_library(HDF5_${LIB}_LIBRARY_DEBUG + NAMES ${THIS_LIBRARY_SEARCH_DEBUG} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + find_library(HDF5_${LIB}_LIBRARY_RELEASE + NAMES ${THIS_LIBRARY_SEARCH_RELEASE} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + + select_library_configurations( HDF5_${LIB} ) + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${LIB}_LIBRARY}) + endforeach() + + # Append the libraries for this language binding to the list of all + # required libraries. + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) + endif() + endforeach() + if(HDF5_FIND_HL AND HDF5_HL_LIBRARIES) + set(HDF5_HL_FOUND TRUE) + endif() + + list(REMOVE_DUPLICATES HDF5_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) + + # If the HDF5 include directory was found, open H5pubconf.h to determine if + # HDF5 was compiled with parallel IO support + set( HDF5_IS_PARALLEL FALSE ) + foreach( _dir IN LISTS HDF5_INCLUDE_DIRS ) + foreach(_hdr "${_dir}/H5pubconf.h" "${_dir}/H5pubconf-64.h" "${_dir}/H5pubconf-32.h") + if( EXISTS "${_hdr}" ) + file( STRINGS "${_hdr}" + HDF5_HAVE_PARALLEL_DEFINE + REGEX "HAVE_PARALLEL 1" ) + if( HDF5_HAVE_PARALLEL_DEFINE ) + set( HDF5_IS_PARALLEL TRUE ) + endif() + unset(HDF5_HAVE_PARALLEL_DEFINE) + + file( STRINGS "${_hdr}" + HDF5_VERSION_DEFINE + REGEX "^[ \t]*#[ \t]*define[ \t]+H5_VERSION[ \t]+" ) + if( "${HDF5_VERSION_DEFINE}" MATCHES + "H5_VERSION[ \t]+\"([0-9\\.]+)(-patch([0-9]+))?\"" ) + set( HDF5_VERSION "${CMAKE_MATCH_1}" ) + if( CMAKE_MATCH_3 ) + set( HDF5_VERSION ${HDF5_VERSION}.${CMAKE_MATCH_3}) + endif() + endif() + unset(HDF5_VERSION_DEFINE) + endif() + endforeach() + endforeach() + unset(_hdr) + unset(_dir) + set( HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL + "HDF5 library compiled with parallel IO support" ) + mark_as_advanced( HDF5_IS_PARALLEL ) + + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS) + if(HDF5_FIND_HL) + list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) + endif() +endif() + +# For backwards compatibility we set HDF5_INCLUDE_DIR to the value of +# HDF5_INCLUDE_DIRS +if( HDF5_INCLUDE_DIRS ) + set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" ) +endif() + +# If HDF5_REQUIRED_VARS is empty at this point, then it's likely that +# something external is trying to explicitly pass already found +# locations +if(NOT HDF5_REQUIRED_VARS) + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS) +endif() + +find_package_handle_standard_args(HDF5 + REQUIRED_VARS ${HDF5_REQUIRED_VARS} + VERSION_VAR HDF5_VERSION + HANDLE_COMPONENTS +) + +unset(_HDF5_SEARCH_OPTS) + +if( HDF5_FOUND AND NOT HDF5_DIR) + # hide HDF5_DIR for the non-advanced user to avoid confusion with + # HDF5_DIR-NOT_FOUND while HDF5 was found. + mark_as_advanced(HDF5_DIR) +endif() + +if (HDF5_FOUND) + if (NOT TARGET HDF5::HDF5) + add_library(HDF5::HDF5 INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_DEFINITIONS}") + set_target_properties(HDF5::HDF5 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + unset(_hdf5_definitions) + target_link_libraries(HDF5::HDF5 INTERFACE ${HDF5_LIBRARIES}) + endif () + + foreach (hdf5_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + if (hdf5_lang STREQUAL "C") + set(hdf5_target_name "hdf5") + elseif (hdf5_lang STREQUAL "CXX") + set(hdf5_target_name "hdf5_cpp") + elseif (hdf5_lang STREQUAL "Fortran") + set(hdf5_target_name "hdf5_fortran") + else () + continue () + endif () + + if (NOT TARGET "hdf5::${hdf5_target_name}") + if (HDF5_COMPILER_NO_INTERROGATE) + add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + else() + if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_lang}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_lang}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") + else () + # Error if we still don't have the location. + message(SEND_ERROR + "HDF5 was found, but a different variable was set which contains " + "the location of the `hdf5::${hdf5_target_name}` library.") + endif () + add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") + if (NOT HDF5_${hdf5_lang}_INCLUDE_DIRS) + set(HDF5_${hdf5_lang}_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS}) + endif () + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + if (_hdf5_location_release) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}") + endif() + if (_hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}") + endif() + if (NOT _hdf5_location_release AND NOT _hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION "${_hdf5_location}") + endif() + if (_hdf5_libtype STREQUAL "SHARED") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) + elseif (_hdf5_libtype STREQUAL "STATIC") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) + endif () + unset(_hdf5_definitions) + unset(_hdf5_libtype) + unset(_hdf5_location) + unset(_hdf5_location_release) + unset(_hdf5_location_debug) + endif () + endif () + + if (NOT HDF5_FIND_HL) + continue () + endif () + + set(hdf5_alt_target_name "") + if (hdf5_lang STREQUAL "C") + set(hdf5_target_name "hdf5_hl") + elseif (hdf5_lang STREQUAL "CXX") + set(hdf5_target_name "hdf5_hl_cpp") + elseif (hdf5_lang STREQUAL "Fortran") + set(hdf5_target_name "hdf5_hl_fortran") + set(hdf5_alt_target_name "hdf5hl_fortran") + else () + continue () + endif () + + if (NOT TARGET "hdf5::${hdf5_target_name}") + if (HDF5_COMPILER_NO_INTERROGATE) + add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + else() + if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_HL_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_lang}_HL_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_lang}_HL_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_lang}_HL_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") + elseif (hdf5_alt_target_name AND DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}}") + else () + # Error if we still don't have the location. + message(SEND_ERROR + "HDF5 was found, but a different variable was set which contains " + "the location of the `hdf5::${hdf5_target_name}` library.") + endif () + add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + if (_hdf5_location_release) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}") + endif() + if (_hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}") + endif() + if (NOT _hdf5_location_release AND NOT _hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION "${_hdf5_location}") + endif() + if (_hdf5_libtype STREQUAL "SHARED") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) + elseif (_hdf5_libtype STREQUAL "STATIC") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) + endif () + unset(_hdf5_definitions) + unset(_hdf5_libtype) + unset(_hdf5_location) + endif () + endif () + endforeach () + unset(hdf5_lang) + + if (HDF5_DIFF_EXECUTABLE AND NOT TARGET hdf5::h5diff) + add_executable(hdf5::h5diff IMPORTED) + set_target_properties(hdf5::h5diff PROPERTIES + IMPORTED_LOCATION "${HDF5_DIFF_EXECUTABLE}") + endif () +endif () + +if (HDF5_FIND_DEBUG) + message(STATUS "HDF5_DIR: ${HDF5_DIR}") + message(STATUS "HDF5_DEFINITIONS: ${HDF5_DEFINITIONS}") + message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}") + message(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}") + message(STATUS "HDF5_HL_LIBRARIES: ${HDF5_HL_LIBRARIES}") + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + message(STATUS "HDF5_${_lang}_DEFINITIONS: ${HDF5_${_lang}_DEFINITIONS}") + message(STATUS "HDF5_${_lang}_INCLUDE_DIR: ${HDF5_${_lang}_INCLUDE_DIR}") + message(STATUS "HDF5_${_lang}_INCLUDE_DIRS: ${HDF5_${_lang}_INCLUDE_DIRS}") + message(STATUS "HDF5_${_lang}_LIBRARY: ${HDF5_${_lang}_LIBRARY}") + message(STATUS "HDF5_${_lang}_LIBRARIES: ${HDF5_${_lang}_LIBRARIES}") + message(STATUS "HDF5_${_lang}_HL_LIBRARY: ${HDF5_${_lang}_HL_LIBRARY}") + message(STATUS "HDF5_${_lang}_HL_LIBRARIES: ${HDF5_${_lang}_HL_LIBRARIES}") + endforeach() + message(STATUS "Defined targets (if any):") + foreach(_lang IN ITEMS "" "_cpp" "_fortran") + foreach(_hl IN ITEMS "" "_hl") + foreach(_prefix IN ITEMS "hdf5::" "") + foreach(_suffix IN ITEMS "-static" "-shared" "") + set (_target ${_prefix}hdf5${_hl}${_lang}${_suffix}) + if (TARGET ${_target}) + message(STATUS "... ${_target}") + else() + #message(STATUS "... ${_target} does not exist") + endif() + endforeach() + endforeach() + endforeach() + endforeach() +endif() +unset(_lang) +unset(_HDF5_NEED_TO_SEARCH) + +cmake_policy(POP) diff --git a/plugins/decl_hdf5/cmake/4.3/SelectLibraryConfigurations.cmake b/plugins/decl_hdf5/cmake/4.3/SelectLibraryConfigurations.cmake new file mode 100644 index 000000000..5fde66e3e --- /dev/null +++ b/plugins/decl_hdf5/cmake/4.3/SelectLibraryConfigurations.cmake @@ -0,0 +1,187 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +SelectLibraryConfigurations +--------------------------- + +This module provides a command to automatically set library variables when +package is available with multiple :ref:`Build Configurations`. It is +intended for use in :ref:`Find Modules` implementing +:command:`find_package()` calls. + +Load this module in a CMake find module with: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + include(SelectLibraryConfigurations) + +Supported build configurations are ``Release`` and ``Debug`` as these are +the most common ones in such packages. + +.. note:: + + This module has been available since early versions of CMake, when the + ``_LIBRARIES`` result variable was used for linking found + packages. When writing standard find modules, :ref:`Imported Targets` should + be preferred. In addition to or as an alternative to this module, imported + targets provide finer control over linking through the + :prop_tgt:`IMPORTED_CONFIGURATIONS` property. + +Commands +^^^^^^^^ + +This module provides the following command: + +.. command:: select_library_configurations + + Sets and adjusts library variables based on debug and release build + configurations: + + .. code-block:: cmake + + select_library_configurations() + + This command is a helper for setting the ``_LIBRARY`` and + ``_LIBRARIES`` result variables when a library might be provided + with multiple build configurations. + + The argument is: + + ```` + The base name of the library, used as a prefix for variable names. This is + the name of the package as used in the ``Find.cmake`` module + filename, or the component name, when find module provides them. + + Prior to calling this command the following cache variables should be set + in the find module (for example, by the :command:`find_library` command): + + ``_LIBRARY_RELEASE`` + A cache variable storing the full path to the ``Release`` build of the + library. If not set or found, this command will set its value to + ``_LIBRARY_RELEASE-NOTFOUND``. + + ``_LIBRARY_DEBUG`` + A cache variable storing the full path to the ``Debug`` build of the + library. If not set or found, this command will set its value to + ``_LIBRARY_DEBUG-NOTFOUND``. + + This command then sets the following local result variables: + + ``_LIBRARY`` + A result variable that is set to the value of + ``_LIBRARY_RELEASE`` variable if found, otherwise it is set to the + value of ``_LIBRARY_DEBUG`` variable if found. If both are found, + the release library value takes precedence. If both are not found, it is set + to value ``_LIBRARY-NOTFOUND``. + + If the :manual:`CMake Generator ` in use supports + build configurations, then this variable will be a list of found libraries + each prepended with the ``optimized`` or ``debug`` keywords specifying which + library should be linked for the given configuration. These keywords are + used by the :command:`target_link_libraries` command. If a build + configuration has not been set or the generator in use does not support + build configurations, then this variable value will not contain these + keywords. + + ``_LIBRARIES`` + A result variable that is set to the same value as the + ``_LIBRARY`` variable. + + .. note:: + + The ``select_library_configurations()`` command should be called before + handling standard find module arguments with + :command:`find_package_handle_standard_args` to ensure that the + ``_FOUND`` result variable is correctly set based on + ``_LIBRARY`` or other related variables. + +Examples +^^^^^^^^ + +Setting library variables based on the build configuration inside a find module +file: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + # Find release and debug build of the library + find_library(Foo_LIBRARY_RELEASE ...) + find_library(Foo_LIBRARY_DEBUG ...) + + # Set Foo_LIBRARY and Foo_LIBRARIES result variables + include(SelectLibraryConfigurations) + select_library_configurations(Foo) + + # Set Foo_FOUND variable and print result message. + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( + Foo + REQUIRED_VARS Foo_LIBRARY ... + ) + +When find module provides components with multiple build configurations: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + include(SelectLibraryConfigurations) + foreach(component IN LISTS Foo_FIND_COMPONENTS) + # ... + select_library_configurations(Foo_${component}) + # ... + endforeach() + +A project can then use this find module as follows: + +.. code-block:: cmake + :caption: ``CMakeLists.txt`` + + find_package(Foo) + target_link_libraries(project_target PRIVATE ${Foo_LIBRARIES}) + # ... +#]=======================================================================] + +# This macro was adapted from the FindQt4 CMake module and is maintained by Will +# Dicharry . + +macro(select_library_configurations basename) + if(NOT ${basename}_LIBRARY_RELEASE) + set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + if(NOT ${basename}_LIBRARY_DEBUG) + set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND + NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND + ( _isMultiConfig OR CMAKE_BUILD_TYPE ) ) + # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for + # single-config generators, set optimized and debug libraries + set( ${basename}_LIBRARY "" ) + foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE ) + list( APPEND ${basename}_LIBRARY optimized "${_libname}" ) + endforeach() + foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG ) + list( APPEND ${basename}_LIBRARY debug "${_libname}" ) + endforeach() + elseif( ${basename}_LIBRARY_RELEASE ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} ) + elseif( ${basename}_LIBRARY_DEBUG ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} ) + else() + set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND") + endif() + + set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" ) + + if( ${basename}_LIBRARY ) + set( ${basename}_FOUND TRUE ) + endif() + + mark_as_advanced( ${basename}_LIBRARY_RELEASE + ${basename}_LIBRARY_DEBUG + ) +endmacro() diff --git a/plugins/decl_netcdf/CMakeLists.txt b/plugins/decl_netcdf/CMakeLists.txt index 96e14ed4d..b3c973139 100644 --- a/plugins/decl_netcdf/CMakeLists.txt +++ b/plugins/decl_netcdf/CMakeLists.txt @@ -34,6 +34,9 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") if("${CMAKE_VERSION}" VERSION_LESS 4.1) # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/4.1") +elseif("${CMAKE_VERSION}" VERSION_LESS 4.3) + # Workaround for compiling with HDF5-2.0.0+ + list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/4.3") endif() option(BUILD_NETCDF_PARALLEL "Build Decl'NetCDF in parallel mode" ON) diff --git a/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake b/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake new file mode 100644 index 000000000..0a15557f0 --- /dev/null +++ b/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake @@ -0,0 +1,1423 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindHDF5 +-------- + +Finds Hierarchical Data Format (HDF5), a library for reading and writing +self-describing array data: + +.. code-block:: cmake + + find_package(HDF5 [] [COMPONENTS ...] [...]) + +If the HDF5 library is built using its CMake-based build system, it will as +of HDF5 version 1.8.15 provide its own CMake Package Configuration file +(``hdf5-config.cmake``) for use with the :command:`find_package` command in +*config mode*. By default, this module searches for this file and, if found, +returns the results based on the found configuration. + +If the upstream configuration file is not found, this module falls back to +*module mode* and invokes the HDF5 wrapper compiler typically installed +with the HDF5 library. Depending on the configuration, this wrapper +compiler is named either ``h5cc`` (serial) or ``h5pcc`` (parallel). If +found, the wrapper is queried with the ``-show`` argument to determine the +compiler and linker flags required for building an HDF5 client application. +Both serial and parallel versions of the HDF5 wrapper are considered. The +first directory containing either is used. If both versions are found in the +same directory, the serial version is preferred by default. To change this +behavior, set the variable ``HDF5_PREFER_PARALLEL`` to ``TRUE``. + +In addition to finding the include directories and libraries needed to compile +an HDF5 application, this module also attempts to find additional tools +provided by the HDF5 distribution, which can be useful for regression testing +or development workflows. + +Components +^^^^^^^^^^ + +This module supports optional components, which can be specified with the +:command:`find_package` command: + +.. code-block:: cmake + + find_package(HDF5 [COMPONENTS ...]) + +Supported components include: + +``C`` + Finds the ``HDF5`` C library (C bindings). + +``CXX`` + Finds the ``HDF5`` C++ library (C++ bindings). + +``Fortran`` + Finds the ``HDF5`` Fortran library (Fortran bindings). + +``HL`` + This component can be used in combination with other components to find the + high-level (HL) HDF5 library variants for C, CXX, and/or Fortran, which + provide high-level functions. + +If no components are specified, then this module will by default search for the +``C`` component. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following :ref:`Imported Targets`: + +``HDF5::HDF5`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for all found HDF5 binding + libraries (``HDF5_LIBRARIES``), available if HDF5 and all required components + are found. + +``hdf5::hdf5`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 C library, available + if HDF5 library and its ``C`` component are found. + +``hdf5::hdf5_cpp`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 C and C++ libraries, + available if HDF5 library, and its ``C`` and ``CXX`` components are found. + +``hdf5::hdf5_fortran`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 Fortran library, + available if HDF5 library and its ``Fortran`` component are found. + +``hdf5::hdf5_hl`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 high-level C library, + available if HDF5 library and its ``C``, and ``HL`` components are found. + +``hdf5::hdf5_hl_cpp`` + .. versionadded:: 3.19 + + High-level C++ library. + + Target encapsulating the usage requirements for the HDF5 high-level C and + high-level C++ libraries, available if HDF5 library and its ``C``, ``CXX``, + and ``HL`` components are found. + +``hdf5::hdf5_hl_fortran`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 high-level Fortran + library, available if HDF5 library and its ``Fortran``, and ``HL`` components + are found. + +``hdf5::h5diff`` + .. versionadded:: 3.19 + + Imported executable target encapsulating the usage requirements for the + ``h5diff`` executable, available if ``h5diff`` is found. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module defines the following variables: + +``HDF5_FOUND`` + Boolean indicating whether (the requested version of) HDF5 was found. + +``HDF5_VERSION`` + .. versionadded:: 3.3 + + The version of HDF5 library found. + +``HDF5_INCLUDE_DIRS`` + Include directories containing header files needed to use HDF5. + +``HDF5_DEFINITIONS`` + Required compiler definitions for using HDF5. + +``HDF5_LIBRARIES`` + Libraries of all requested bindings needed to link against to use HDF5. + +``HDF5_HL_LIBRARIES`` + Required libraries for the HDF5 high-level API for all bindings, + if the ``HL`` component is enabled. + +``HDF5_IS_PARALLEL`` + Boolean indicating whether the HDF5 library has parallel IO support. + +For each enabled language binding component, a corresponding +``HDF5__LIBRARIES`` variable, and potentially +``HDF5__DEFINITIONS``, will be defined. If the ``HL`` component is +enabled, then ``HDF5__HL_LIBRARIES`` variables will also be defined: + +``HDF5_C_DEFINITIONS`` + Required compiler definitions for HDF5 C bindings. + +``HDF5_CXX_DEFINITIONS`` + Required compiler definitions for HDF5 C++ bindings. + +``HDF5_Fortran_DEFINITIONS`` + Required compiler definitions for HDF5 Fortran bindings. + +``HDF5_C_INCLUDE_DIRS`` + Required include directories for HDF5 C bindings. + +``HDF5_CXX_INCLUDE_DIRS`` + Required include directories for HDF5 C++ bindings. + +``HDF5_Fortran_INCLUDE_DIRS`` + Required include directories for HDF5 Fortran bindings. + +``HDF5_C_LIBRARIES`` + Required libraries for the HDF5 C bindings. + +``HDF5_CXX_LIBRARIES`` + Required libraries for the HDF5 C++ bindings. + +``HDF5_Fortran_LIBRARIES`` + Required libraries for the HDF5 Fortran bindings. + +``HDF5_C_HL_LIBRARIES`` + Required libraries for the high-level C bindings, if the ``HL`` component + is enabled. + +``HDF5_CXX_HL_LIBRARIES`` + Required libraries for the high-level C++ bindings, if the ``HL`` + component is enabled. + +``HDF5_Fortran_HL_LIBRARIES`` + Required libraries for the high-level Fortran bindings, if the ``HL`` + component is enabled. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``HDF5_C_COMPILER_EXECUTABLE`` + The path to the HDF5 C wrapper compiler. + +``HDF5_CXX_COMPILER_EXECUTABLE`` + The path to the HDF5 C++ wrapper compiler. + +``HDF5_Fortran_COMPILER_EXECUTABLE`` + The path to the HDF5 Fortran wrapper compiler. + +``HDF5_C_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary C compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_CXX_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary C++ compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_Fortran_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary Fortran compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_DIFF_EXECUTABLE`` + The path to the HDF5 dataset comparison tool (``h5diff``). + +Hints +^^^^^ + +The following variables can be set before calling the ``find_package(HDF5)`` +to guide the search for HDF5 library: + +``HDF5_PREFER_PARALLEL`` + .. versionadded:: 3.4 + + Set this to boolean true to prefer parallel HDF5 (by default, serial is + preferred). This variable is used only in *module mode*. + +``HDF5_FIND_DEBUG`` + .. versionadded:: 3.9 + + Set this to boolean true to get extra debugging output by this module. + +``HDF5_NO_FIND_PACKAGE_CONFIG_FILE`` + .. versionadded:: 3.8 + + Set this to boolean true to skip finding and using CMake package configuration + file (``hdf5-config.cmake``). + +``HDF5_USE_STATIC_LIBRARIES`` + Set this to boolean value to determine whether or not to prefer a + static link to a dynamic link for ``HDF5`` and all of its dependencies. + + .. versionadded:: 3.10 + Support for ``HDF5_USE_STATIC_LIBRARIES`` on Windows. + +Examples +^^^^^^^^ + +Examples: Finding HDF5 +"""""""""""""""""""""" + +Finding HDF5: + +.. code-block:: cmake + + find_package(HDF5) + +Specifying a minimum required version of HDF5 to find: + +.. code-block:: cmake + + find_package(HDF5 1.8.15) + +Finding HDF5 and making it required (if HDF5 is not found, processing stops with +an error message): + +.. code-block:: cmake + + find_package(HDF5 1.8.15 REQUIRED) + +Searching for static HDF5 libraries: + +.. code-block:: cmake + + set(HDF5_USE_STATIC_LIBRARIES TRUE) + find_package(HDF5) + +Specifying components to find high-level C and C++ functions: + +.. code-block:: cmake + + find_package(HDF5 COMPONENTS C CXX HL) + +Examples: Using HDF5 +"""""""""""""""""""" + +Finding HDF5 and linking it to a project target: + +.. code-block:: cmake + + find_package(HDF5) + target_link_libraries(project_target PRIVATE HDF5::HDF5) + +Using Fortran HDF5 and HDF5-HL functions: + +.. code-block:: cmake + + find_package(HDF5 COMPONENTS Fortran HL) + target_link_libraries(project_target PRIVATE HDF5::HDF5) +#]=======================================================================] + +include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) +include(FindPackageHandleStandardArgs) + +cmake_policy(PUSH) +cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_ + +# We haven't found HDF5 yet. Clear its state in case it is set in the parent +# scope somewhere else. We can't rely on it because different components may +# have been requested for this call. +set(HDF5_FOUND OFF) +set(HDF5_LIBRARIES) +set(HDF5_HL_LIBRARIES) + +# List of the valid HDF5 components +set(HDF5_VALID_LANGUAGE_BINDINGS C CXX Fortran) + +# Validate the list of find components. +if(NOT HDF5_FIND_COMPONENTS) + set(HDF5_LANGUAGE_BINDINGS "C") +else() + set(HDF5_LANGUAGE_BINDINGS) + # add the extra specified components, ensuring that they are valid. + set(HDF5_FIND_HL OFF) + foreach(_component IN LISTS HDF5_FIND_COMPONENTS) + list(FIND HDF5_VALID_LANGUAGE_BINDINGS ${_component} _component_location) + if(NOT _component_location EQUAL -1) + list(APPEND HDF5_LANGUAGE_BINDINGS ${_component}) + elseif(_component STREQUAL "HL") + set(HDF5_FIND_HL ON) + elseif(_component STREQUAL "Fortran_HL") # only for compatibility + list(APPEND HDF5_LANGUAGE_BINDINGS Fortran) + set(HDF5_FIND_HL ON) + set(HDF5_FIND_REQUIRED_Fortran_HL FALSE) + set(HDF5_FIND_REQUIRED_Fortran TRUE) + set(HDF5_FIND_REQUIRED_HL TRUE) + else() + message(FATAL_ERROR "${_component} is not a valid HDF5 component.") + endif() + endforeach() + unset(_component) + unset(_component_location) + if(NOT HDF5_LANGUAGE_BINDINGS) + get_property(_langs GLOBAL PROPERTY ENABLED_LANGUAGES) + foreach(_lang IN LISTS _langs) + if(_lang MATCHES "^(C|CXX|Fortran)$") + list(APPEND HDF5_LANGUAGE_BINDINGS ${_lang}) + endif() + endforeach() + endif() + list(REMOVE_ITEM HDF5_FIND_COMPONENTS Fortran_HL) # replaced by Fortran and HL + list(REMOVE_DUPLICATES HDF5_LANGUAGE_BINDINGS) +endif() + +# Determine whether to search for serial or parallel executable first +if(HDF5_PREFER_PARALLEL) + set(HDF5_C_COMPILER_NAMES h5pcc h5cc) + set(HDF5_CXX_COMPILER_NAMES h5pc++ h5c++) + set(HDF5_Fortran_COMPILER_NAMES h5pfc h5fc) +else() + set(HDF5_C_COMPILER_NAMES h5cc h5pcc) + set(HDF5_CXX_COMPILER_NAMES h5c++ h5pc++) + set(HDF5_Fortran_COMPILER_NAMES h5fc h5pfc) +endif() + +# Prefer h5hl compilers if HDF5_FIND_HL is enabled +if(HDF5_FIND_HL) + list(PREPEND HDF5_C_COMPILER_NAMES h5hlcc) + list(PREPEND HDF5_CXX_COMPILER_NAMES h5hlc++) + list(PREPEND HDF5_Fortran_COMPILER_NAMES h5hlfc) +endif() + +# Test first if the current compilers automatically wrap HDF5 +function(_HDF5_test_regular_compiler_C success version is_parallel) + if(NOT ${success} OR + NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "#include \n" + "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" + "#ifdef H5_HAVE_PARALLEL\n" + "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" + "#endif\n" + "int main(int argc, char **argv) {\n" + " int require = 0;\n" + " require += info_ver[argc];\n" + "#ifdef H5_HAVE_PARALLEL\n" + " require += info_parallel[argc];\n" + "#endif\n" + " hid_t fid;\n" + " fid = H5Fcreate(\"foo.h5\",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);\n" + " return 0;\n" + "}") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_c + ) + endif() + if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c) + file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_c INFO_STRINGS + REGEX "^INFO:" + ) + string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" + INFO_VER "${INFO_STRINGS}" + ) + set(${version} ${CMAKE_MATCH_1}) + if(CMAKE_MATCH_3) + set(${version} ${HDF5_C_VERSION}.${CMAKE_MATCH_3}) + endif() + set(${version} ${${version}} PARENT_SCOPE) + + if(INFO_STRINGS MATCHES "INFO:PARALLEL") + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() +endfunction() + +function(_HDF5_test_regular_compiler_CXX success version is_parallel) + if(NOT ${success} OR + NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "#include \n" + "#ifndef H5_NO_NAMESPACE\n" + "using namespace H5;\n" + "#endif\n" + "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" + "#ifdef H5_HAVE_PARALLEL\n" + "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" + "#endif\n" + "int main(int argc, char **argv) {\n" + " int require = 0;\n" + " require += info_ver[argc];\n" + "#ifdef H5_HAVE_PARALLEL\n" + " require += info_parallel[argc];\n" + "#endif\n" + " H5File file(\"foo.h5\", H5F_ACC_TRUNC);\n" + " return 0;\n" + "}") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_cxx + ) + endif() + if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx) + file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx INFO_STRINGS + REGEX "^INFO:" + ) + string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" + INFO_VER "${INFO_STRINGS}" + ) + set(${version} ${CMAKE_MATCH_1}) + if(CMAKE_MATCH_3) + set(${version} ${HDF5_CXX_VERSION}.${CMAKE_MATCH_3}) + endif() + set(${version} ${${version}} PARENT_SCOPE) + + if(INFO_STRINGS MATCHES "INFO:PARALLEL") + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() +endfunction() + +function(_HDF5_test_regular_compiler_Fortran success is_parallel) + if(NOT ${success}) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "program hdf5_hello\n" + " use hdf5\n" + " integer error\n" + " call h5open_f(error)\n" + " call h5close_f(error)\n" + "end\n") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}") + if(${success}) + execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -showconfig + OUTPUT_VARIABLE config_output + ERROR_VARIABLE config_error + RESULT_VARIABLE config_result + ) + if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)") + # The value may be anything used when HDF5 was configured, + # so see if CMake interprets it as "true". + set(parallelHDF5 "${CMAKE_MATCH_1}") + if(parallelHDF5) + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() + endif() +endfunction() + +# Invoke the HDF5 wrapper compiler. The compiler return value is stored to the +# return_value argument, the text output is stored to the output variable. +function( _HDF5_invoke_compiler language output_var return_value_var version_var is_parallel_var) + set(is_parallel FALSE) + if(HDF5_USE_STATIC_LIBRARIES) + set(lib_type_args -noshlib) + else() + set(lib_type_args -shlib) + endif() + # Verify that the compiler wrapper can actually compile: sometimes the compiler + # wrapper exists, but not the compiler. E.g. Miniconda / Anaconda Python + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} "${_HDF5_TEST_SRC}" + WORKING_DIRECTORY ${_HDF5_TEST_DIR} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE return_value + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.") + endif() + else() + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -show ${lib_type_args} "${_HDF5_TEST_SRC}" + WORKING_DIRECTORY ${_HDF5_TEST_DIR} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE return_value + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "Unable to determine HDF5 ${language} flags from HDF5 wrapper.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "Unable to determine HDF5 ${language} flags from HDF5 wrapper.") + endif() + endif() + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -showconfig + OUTPUT_VARIABLE config_output + ERROR_VARIABLE config_output + RESULT_VARIABLE return_value + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.") + endif() + endif() + string(REGEX MATCH "HDF5 Version: ([a-zA-Z0-9\\.\\-]*)" version "${config_output}") + if(version) + string(REPLACE "HDF5 Version: " "" version "${version}") + string(REPLACE "-patch" "." version "${version}") + endif() + if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)") + # The value may be anything used when HDF5 was configured, + # so see if CMake interprets it as "true". + set(parallelHDF5 "${CMAKE_MATCH_1}") + if(parallelHDF5) + set(is_parallel TRUE) + endif() + endif() + endif() + foreach(var output return_value version is_parallel) + set(${${var}_var} ${${var}} PARENT_SCOPE) + endforeach() +endfunction() + +# Parse a compile line for definitions, includes, library paths, and libraries. +function(_HDF5_parse_compile_line compile_line_var include_paths definitions + library_paths libraries libraries_hl) + + separate_arguments(_compile_args NATIVE_COMMAND "${${compile_line_var}}") + + foreach(_arg IN LISTS _compile_args) + if("${_arg}" MATCHES "^-I(.*)$") + # include directory + list(APPEND include_paths "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-D(.*)$") + # compile definition + list(APPEND definitions "-D${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-L(.*)$") + # library search path + list(APPEND library_paths "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-l(hdf5.*hl.*)$") + # library name (hl) + list(APPEND libraries_hl "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-l(.*)$") + # library name + list(APPEND libraries "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^(.:)?[/\\].*\\.(a|so|dylib|sl|lib)$") + # library file + if(NOT EXISTS "${_arg}") + continue() + endif() + get_filename_component(_lpath "${_arg}" DIRECTORY) + get_filename_component(_lname "${_arg}" NAME_WE) + string(REGEX REPLACE "^lib" "" _lname "${_lname}") + list(APPEND library_paths "${_lpath}") + if(_lname MATCHES "hdf5.*hl") + list(APPEND libraries_hl "${_lname}") + else() + list(APPEND libraries "${_lname}") + endif() + endif() + endforeach() + foreach(var include_paths definitions library_paths libraries libraries_hl) + set(${${var}_var} ${${var}} PARENT_SCOPE) + endforeach() +endfunction() + +# Select a preferred imported configuration from a target +function(_HDF5_select_imported_config target imported_conf) + # We will first assign the value to a local variable _imported_conf, then assign + # it to the function argument at the end. + get_target_property(_imported_conf ${target} MAP_IMPORTED_CONFIG_${CMAKE_BUILD_TYPE}) + if (NOT _imported_conf) + # Get available imported configurations by examining target properties + get_target_property(_imported_conf ${target} IMPORTED_CONFIGURATIONS) + if(HDF5_FIND_DEBUG) + message(STATUS "Found imported configurations: ${_imported_conf}") + endif() + # Find the imported configuration that we prefer. + # We do this by making list of configurations in order of preference, + # starting with ${CMAKE_BUILD_TYPE} and ending with the first imported_conf + set(_preferred_confs ${CMAKE_BUILD_TYPE}) + list(GET _imported_conf 0 _fallback_conf) + list(APPEND _preferred_confs RELWITHDEBINFO RELEASE DEBUG ${_fallback_conf}) + if(HDF5_FIND_DEBUG) + message(STATUS "Start search through imported configurations in the following order: ${_preferred_confs}") + endif() + # Now find the first of these that is present in imported_conf + foreach (_conf IN LISTS _preferred_confs) + if (${_conf} IN_LIST _imported_conf) + set(_imported_conf ${_conf}) + break() + endif() + endforeach() + endif() + if(HDF5_FIND_DEBUG) + message(STATUS "Selected imported configuration: ${_imported_conf}") + endif() + # assign value to function argument + set(${imported_conf} ${_imported_conf} PARENT_SCOPE) +endfunction() + + +if(NOT HDF5_ROOT) + set(HDF5_ROOT $ENV{HDF5_ROOT}) +endif() +if(HDF5_ROOT) + set(_HDF5_SEARCH_OPTS NO_DEFAULT_PATH) +else() + set(_HDF5_SEARCH_OPTS) +endif() + +# Try to find HDF5 using an installed hdf5-config.cmake +if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE) + find_package(HDF5 QUIET NO_MODULE + HINTS ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS} + ) + if( HDF5_FOUND) + if(HDF5_FIND_DEBUG) + message(STATUS "Found HDF5 at ${HDF5_DIR} via NO_MODULE. Now trying to extract locations etc.") + endif() + # Extract information from imported targets + if (DEFINED HDF5_ENABLE_PARALLEL) + # Versions of <2.0.0 use `HDF5_ENABLE_PARALLEL` + set(HDF5_IS_PARALLEL ${HDF5_ENABLE_PARALLEL}) + elseif(DEFINED HDF5_PROVIDES_PARALLEL) + # Versions of >=2.0.0 use `HDF5_PROVIDES_PARALLEL` + set(HDF5_IS_PARALLEL ${HDF5_PROVIDES_PARALLEL}) + else() + set(HDF5_IS_PARALLEL NONE) + endif() + set(HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR}) + set(HDF5_LIBRARIES) + if (NOT TARGET hdf5 AND NOT TARGET hdf5-static AND NOT TARGET hdf5-shared) + # Some HDF5 versions (e.g. 1.8.18) used hdf5::hdf5 etc + set(_target_prefix "hdf5::") + endif() + set(HDF5_C_TARGET ${_target_prefix}hdf5) + set(HDF5_C_HL_TARGET ${_target_prefix}hdf5_hl) + set(HDF5_CXX_TARGET ${_target_prefix}hdf5_cpp) + set(HDF5_CXX_HL_TARGET ${_target_prefix}hdf5_hl_cpp) + set(HDF5_Fortran_TARGET ${_target_prefix}hdf5_fortran) + set(HDF5_Fortran_HL_TARGET ${_target_prefix}hdf5_hl_fortran) + set(HDF5_DEFINITIONS "") + if(HDF5_USE_STATIC_LIBRARIES) + set(_suffix "-static") + else() + set(_suffix "-shared") + endif() + foreach(_lang ${HDF5_LANGUAGE_BINDINGS}) + + #Older versions of hdf5 don't have a static/shared suffix so + #if we detect that occurrence clear the suffix + if(_suffix AND NOT TARGET ${HDF5_${_lang}_TARGET}${_suffix}) + if(NOT TARGET ${HDF5_${_lang}_TARGET}) + #can't find this component with or without the suffix + #so bail out, and let the following locate HDF5 + set(HDF5_FOUND FALSE) + break() + endif() + set(_suffix "") + endif() + + if(HDF5_FIND_DEBUG) + message(STATUS "Trying to get properties of target ${HDF5_${_lang}_TARGET}${_suffix}") + endif() + # Find library for this target. Complicated as on Windows with a DLL, we need to search for the import-lib. + _HDF5_select_imported_config(${HDF5_${_lang}_TARGET}${_suffix} _hdf5_imported_conf) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_location) + # no import lib, just try LOCATION + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_lang_location) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION) + endif() + endif() + if( _hdf5_lang_location ) + set(HDF5_${_lang}_LIBRARY ${_hdf5_lang_location}) + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) + set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) + set(HDF5_${_lang}_FOUND TRUE) + endif() + if(HDF5_FIND_HL) + get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_hl_location) + get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_hl_lang_location) + get_target_property(_hdf5_hl_lang_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION) + endif() + endif() + if( _hdf5_lang_hl_location ) + set(HDF5_${_lang}_HL_LIBRARY ${_hdf5_lang_hl_location}) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) + set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) + set(HDF5_HL_FOUND TRUE) + endif() + unset(_hdf5_lang_hl_location) + endif() + unset(_hdf5_imported_conf) + unset(_hdf5_lang_location) + endforeach() + endif() +endif() + +if(NOT HDF5_FOUND) + set(_HDF5_NEED_TO_SEARCH FALSE) + set(_HDF5_TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5) + set(HDF5_COMPILER_NO_INTERROGATE TRUE) + # Only search for languages we've enabled + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + # First check to see if our regular compiler is one of wrappers + if(_lang STREQUAL "C") + set(_HDF5_TEST_SRC cmake_hdf5_test.c) + if(CMAKE_CXX_COMPILER_LOADED AND NOT CMAKE_C_COMPILER_LOADED) + # CXX project without C enabled + set(_HDF5_TEST_SRC cmake_hdf5_test.cxx) + endif() + _HDF5_test_regular_compiler_C( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_VERSION + HDF5_${_lang}_IS_PARALLEL) + elseif(_lang STREQUAL "CXX") + set(_HDF5_TEST_SRC cmake_hdf5_test.cxx) + _HDF5_test_regular_compiler_CXX( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_VERSION + HDF5_${_lang}_IS_PARALLEL) + elseif(_lang STREQUAL "Fortran") + set(_HDF5_TEST_SRC cmake_hdf5_test.f90) + _HDF5_test_regular_compiler_Fortran( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_IS_PARALLEL) + else() + continue() + endif() + if(HDF5_${_lang}_COMPILER_NO_INTERROGATE) + if(HDF5_FIND_DEBUG) + message(STATUS "HDF5: Using hdf5 compiler wrapper for all ${_lang} compiling") + endif() + set(HDF5_${_lang}_FOUND TRUE) + set(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE + "${CMAKE_${_lang}_COMPILER}" + CACHE FILEPATH "HDF5 ${_lang} compiler wrapper") + set(HDF5_${_lang}_DEFINITIONS) + set(HDF5_${_lang}_INCLUDE_DIRS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + mark_as_advanced(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE) + + set(HDF5_${_lang}_FOUND TRUE) + set(HDF5_HL_FOUND TRUE) + else() + set(HDF5_COMPILER_NO_INTERROGATE FALSE) + # If this language isn't using the wrapper, then try to seed the + # search options with the wrapper + find_program(HDF5_${_lang}_COMPILER_EXECUTABLE + NAMES ${HDF5_${_lang}_COMPILER_NAMES} NAMES_PER_DIR + HINTS ${HDF5_ROOT} + PATH_SUFFIXES bin Bin + DOC "HDF5 ${_lang} Wrapper compiler. Used only to detect HDF5 compile flags." + ${_HDF5_SEARCH_OPTS} + ) + mark_as_advanced( HDF5_${_lang}_COMPILER_EXECUTABLE ) + unset(HDF5_${_lang}_COMPILER_NAMES) + + if(HDF5_${_lang}_COMPILER_EXECUTABLE) + _HDF5_invoke_compiler(${_lang} HDF5_${_lang}_COMPILE_LINE + HDF5_${_lang}_RETURN_VALUE HDF5_${_lang}_VERSION HDF5_${_lang}_IS_PARALLEL) + if(HDF5_${_lang}_RETURN_VALUE EQUAL 0) + if(HDF5_FIND_DEBUG) + message(STATUS "HDF5: Using hdf5 compiler wrapper to determine ${_lang} configuration") + endif() + _HDF5_parse_compile_line( HDF5_${_lang}_COMPILE_LINE + HDF5_${_lang}_INCLUDE_DIRS + HDF5_${_lang}_DEFINITIONS + HDF5_${_lang}_LIBRARY_DIRS + HDF5_${_lang}_LIBRARY_NAMES + HDF5_${_lang}_HL_LIBRARY_NAMES + ) + set(HDF5_${_lang}_LIBRARIES) + + foreach(_lib IN LISTS HDF5_${_lang}_LIBRARY_NAMES) + set(_HDF5_SEARCH_NAMES_LOCAL) + if("x${_lib}" MATCHES "hdf5") + # hdf5 library + set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) + if(HDF5_USE_STATIC_LIBRARIES) + if(WIN32) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) + else() + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) + endif() + endif() + else() + # external library + set(_HDF5_SEARCH_OPTS_LOCAL) + endif() + find_library(HDF5_${_lang}_LIBRARY_${_lib} + NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR + HINTS ${HDF5_${_lang}_LIBRARY_DIRS} + ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS_LOCAL} + ) + unset(_HDF5_SEARCH_OPTS_LOCAL) + unset(_HDF5_SEARCH_NAMES_LOCAL) + if(HDF5_${_lang}_LIBRARY_${_lib}) + list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) + else() + list(APPEND HDF5_${_lang}_LIBRARIES ${_lib}) + endif() + endforeach() + if(HDF5_FIND_HL) + set(HDF5_${_lang}_HL_LIBRARIES) + foreach(_lib IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) + set(_HDF5_SEARCH_NAMES_LOCAL) + if("x${_lib}" MATCHES "hdf5") + # hdf5 library + set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) + if(HDF5_USE_STATIC_LIBRARIES) + if(WIN32) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) + else() + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) + endif() + endif() + else() + # external library + set(_HDF5_SEARCH_OPTS_LOCAL) + endif() + find_library(HDF5_${_lang}_LIBRARY_${_lib} + NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR + HINTS ${HDF5_${_lang}_LIBRARY_DIRS} + ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS_LOCAL} + ) + unset(_HDF5_SEARCH_OPTS_LOCAL) + unset(_HDF5_SEARCH_NAMES_LOCAL) + if(HDF5_${_lang}_LIBRARY_${_lib}) + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) + else() + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${_lib}) + endif() + endforeach() + set(HDF5_HL_FOUND TRUE) + endif() + + set(HDF5_${_lang}_FOUND TRUE) + list(REMOVE_DUPLICATES HDF5_${_lang}_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_${_lang}_INCLUDE_DIRS) + else() + set(_HDF5_NEED_TO_SEARCH TRUE) + endif() + else() + set(_HDF5_NEED_TO_SEARCH TRUE) + endif() + endif() + if(HDF5_${_lang}_VERSION) + if(NOT HDF5_VERSION) + set(HDF5_VERSION ${HDF5_${_lang}_VERSION}) + elseif(NOT HDF5_VERSION VERSION_EQUAL HDF5_${_lang}_VERSION) + message(WARNING "HDF5 Version found for language ${_lang}, ${HDF5_${_lang}_VERSION} is different than previously found version ${HDF5_VERSION}") + endif() + endif() + if(DEFINED HDF5_${_lang}_IS_PARALLEL) + if(NOT DEFINED HDF5_IS_PARALLEL) + set(HDF5_IS_PARALLEL ${HDF5_${_lang}_IS_PARALLEL}) + elseif(NOT HDF5_IS_PARALLEL AND HDF5_${_lang}_IS_PARALLEL) + message(WARNING "HDF5 found for language ${_lang} is parallel but previously found language is not parallel.") + elseif(HDF5_IS_PARALLEL AND NOT HDF5_${_lang}_IS_PARALLEL) + message(WARNING "HDF5 found for language ${_lang} is not parallel but previously found language is parallel.") + endif() + endif() + endforeach() + unset(_HDF5_TEST_DIR) + unset(_HDF5_TEST_SRC) + unset(_lib) +else() + set(_HDF5_NEED_TO_SEARCH TRUE) +endif() + +if(NOT HDF5_FOUND AND HDF5_COMPILER_NO_INTERROGATE) + # No arguments necessary, all languages can use the compiler wrappers + set(HDF5_FOUND TRUE) + set(HDF5_METHOD "Included by compiler wrappers") + set(HDF5_REQUIRED_VARS HDF5_METHOD) +elseif(NOT HDF5_FOUND AND NOT _HDF5_NEED_TO_SEARCH) + # Compiler wrappers aren't being used by the build but were found and used + # to determine necessary include and library flags + set(HDF5_INCLUDE_DIRS) + set(HDF5_LIBRARIES) + set(HDF5_HL_LIBRARIES) + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + if(HDF5_${_lang}_FOUND) + if(NOT HDF5_${_lang}_COMPILER_NO_INTERROGATE) + list(APPEND HDF5_DEFINITIONS ${HDF5_${_lang}_DEFINITIONS}) + list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIRS}) + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) + if(HDF5_FIND_HL) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) + endif() + endif() + endif() + endforeach() + list(REMOVE_DUPLICATES HDF5_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) + set(HDF5_FOUND TRUE) + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES) + if(HDF5_FIND_HL) + list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) + endif() +endif() + +find_program( HDF5_DIFF_EXECUTABLE + NAMES h5diff + HINTS ${HDF5_ROOT} + PATH_SUFFIXES bin Bin + ${_HDF5_SEARCH_OPTS} + DOC "HDF5 file differencing tool." ) +mark_as_advanced( HDF5_DIFF_EXECUTABLE ) + +if( NOT HDF5_FOUND ) + # seed the initial lists of libraries to find with items we know we need + set(HDF5_C_LIBRARY_NAMES hdf5) + set(HDF5_C_HL_LIBRARY_NAMES hdf5_hl ${HDF5_C_LIBRARY_NAMES} ) + + set(HDF5_CXX_LIBRARY_NAMES hdf5_cpp ${HDF5_C_LIBRARY_NAMES}) + set(HDF5_CXX_HL_LIBRARY_NAMES hdf5_hl_cpp ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_CXX_LIBRARY_NAMES}) + + set(HDF5_Fortran_LIBRARY_NAMES hdf5_fortran ${HDF5_C_LIBRARY_NAMES}) + set(HDF5_Fortran_HL_LIBRARY_NAMES hdf5_hl_fortran hdf5hl_fortran ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_Fortran_LIBRARY_NAMES}) + + # suffixes as seen on Linux, MSYS2, ... + set(_lib_suffixes hdf5) + if(NOT HDF5_PREFER_PARALLEL) + list(APPEND _lib_suffixes hdf5/serial) + endif() + if(HDF5_USE_STATIC_LIBRARIES) + set(_inc_suffixes include/static) + else() + set(_inc_suffixes include/shared) + endif() + + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + # The "main" library. + set(_hdf5_main_library "") + + # find the HDF5 libraries + foreach(LIB IN LISTS HDF5_${_lang}_LIBRARY_NAMES) + if(HDF5_USE_STATIC_LIBRARIES) + # According to bug 1643 on the CMake bug tracker, this is the + # preferred method for searching for a static library. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search + # first for the full static library name, but fall back to a + # generic search on the name if the static search fails. + set( THIS_LIBRARY_SEARCH_DEBUG + lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug + lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_D-static ${LIB}_debug-static ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a ${LIB}-static) + else() + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) + set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) + if(WIN32) + list(APPEND HDF5_DEFINITIONS "-DH5_BUILT_AS_DYNAMIC_LIB") + endif() + endif() + find_library(HDF5_${LIB}_LIBRARY_DEBUG + NAMES ${THIS_LIBRARY_SEARCH_DEBUG} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + find_library(HDF5_${LIB}_LIBRARY_RELEASE + NAMES ${THIS_LIBRARY_SEARCH_RELEASE} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + + # Set the "main" library if not already set. + if (NOT _hdf5_main_library) + if (HDF5_${LIB}_LIBRARY_RELEASE) + set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_RELEASE}") + elseif (HDF5_${LIB}_LIBRARY_DEBUG) + set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_DEBUG}") + endif () + endif () + + select_library_configurations( HDF5_${LIB} ) + list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${LIB}_LIBRARY}) + endforeach() + if(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_FOUND TRUE) + endif() + + # Append the libraries for this language binding to the list of all + # required libraries. + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) + + # find the HDF5 include directories + set(_hdf5_inc_extra_paths) + set(_hdf5_inc_extra_suffixes) + if("${_lang}" STREQUAL "Fortran") + set(HDF5_INCLUDE_FILENAME hdf5.mod HDF5.mod) + + # Add library-based search paths for Fortran modules. + if (NOT _hdf5_main_library STREQUAL "") + # gfortran module directory + if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "LCC") + get_filename_component(_hdf5_library_dir "${_hdf5_main_library}" DIRECTORY) + list(APPEND _hdf5_inc_extra_paths "${_hdf5_library_dir}") + unset(_hdf5_library_dir) + list(APPEND _hdf5_inc_extra_suffixes gfortran/modules) + endif () + endif () + elseif("${_lang}" STREQUAL "CXX") + set(HDF5_INCLUDE_FILENAME H5Cpp.h) + else() + set(HDF5_INCLUDE_FILENAME hdf5.h) + endif() + + unset(_hdf5_main_library) + + find_path(HDF5_${_lang}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME} + HINTS ${HDF5_ROOT} + PATHS $ENV{HOME}/.local/include ${_hdf5_inc_extra_paths} + PATH_SUFFIXES include Include ${_inc_suffixes} ${_lib_suffixes} ${_hdf5_inc_extra_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + mark_as_advanced(HDF5_${_lang}_INCLUDE_DIR) + unset(_hdf5_inc_extra_paths) + unset(_hdf5_inc_extra_suffixes) + # set the _DIRS variable as this is what the user will normally use + set(HDF5_${_lang}_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) + list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) + + if(HDF5_FIND_HL) + foreach(LIB IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) + if(HDF5_USE_STATIC_LIBRARIES) + # According to bug 1643 on the CMake bug tracker, this is the + # preferred method for searching for a static library. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search + # first for the full static library name, but fall back to a + # generic search on the name if the static search fails. + set( THIS_LIBRARY_SEARCH_DEBUG + lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug + lib${LIB}d-static.a lib${LIB}_debug-static.a lib${LIB}d-static lib${LIB}_D-static lib${LIB}_debug-static ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a lib${LIB}-static) + else() + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) + set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) + endif() + find_library(HDF5_${LIB}_LIBRARY_DEBUG + NAMES ${THIS_LIBRARY_SEARCH_DEBUG} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + find_library(HDF5_${LIB}_LIBRARY_RELEASE + NAMES ${THIS_LIBRARY_SEARCH_RELEASE} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + + select_library_configurations( HDF5_${LIB} ) + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${LIB}_LIBRARY}) + endforeach() + + # Append the libraries for this language binding to the list of all + # required libraries. + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) + endif() + endforeach() + if(HDF5_FIND_HL AND HDF5_HL_LIBRARIES) + set(HDF5_HL_FOUND TRUE) + endif() + + list(REMOVE_DUPLICATES HDF5_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) + + # If the HDF5 include directory was found, open H5pubconf.h to determine if + # HDF5 was compiled with parallel IO support + set( HDF5_IS_PARALLEL FALSE ) + foreach( _dir IN LISTS HDF5_INCLUDE_DIRS ) + foreach(_hdr "${_dir}/H5pubconf.h" "${_dir}/H5pubconf-64.h" "${_dir}/H5pubconf-32.h") + if( EXISTS "${_hdr}" ) + file( STRINGS "${_hdr}" + HDF5_HAVE_PARALLEL_DEFINE + REGEX "HAVE_PARALLEL 1" ) + if( HDF5_HAVE_PARALLEL_DEFINE ) + set( HDF5_IS_PARALLEL TRUE ) + endif() + unset(HDF5_HAVE_PARALLEL_DEFINE) + + file( STRINGS "${_hdr}" + HDF5_VERSION_DEFINE + REGEX "^[ \t]*#[ \t]*define[ \t]+H5_VERSION[ \t]+" ) + if( "${HDF5_VERSION_DEFINE}" MATCHES + "H5_VERSION[ \t]+\"([0-9\\.]+)(-patch([0-9]+))?\"" ) + set( HDF5_VERSION "${CMAKE_MATCH_1}" ) + if( CMAKE_MATCH_3 ) + set( HDF5_VERSION ${HDF5_VERSION}.${CMAKE_MATCH_3}) + endif() + endif() + unset(HDF5_VERSION_DEFINE) + endif() + endforeach() + endforeach() + unset(_hdr) + unset(_dir) + set( HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL + "HDF5 library compiled with parallel IO support" ) + mark_as_advanced( HDF5_IS_PARALLEL ) + + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS) + if(HDF5_FIND_HL) + list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) + endif() +endif() + +# For backwards compatibility we set HDF5_INCLUDE_DIR to the value of +# HDF5_INCLUDE_DIRS +if( HDF5_INCLUDE_DIRS ) + set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" ) +endif() + +# If HDF5_REQUIRED_VARS is empty at this point, then it's likely that +# something external is trying to explicitly pass already found +# locations +if(NOT HDF5_REQUIRED_VARS) + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS) +endif() + +find_package_handle_standard_args(HDF5 + REQUIRED_VARS ${HDF5_REQUIRED_VARS} + VERSION_VAR HDF5_VERSION + HANDLE_COMPONENTS +) + +unset(_HDF5_SEARCH_OPTS) + +if( HDF5_FOUND AND NOT HDF5_DIR) + # hide HDF5_DIR for the non-advanced user to avoid confusion with + # HDF5_DIR-NOT_FOUND while HDF5 was found. + mark_as_advanced(HDF5_DIR) +endif() + +if (HDF5_FOUND) + if (NOT TARGET HDF5::HDF5) + add_library(HDF5::HDF5 INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_DEFINITIONS}") + set_target_properties(HDF5::HDF5 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + unset(_hdf5_definitions) + target_link_libraries(HDF5::HDF5 INTERFACE ${HDF5_LIBRARIES}) + endif () + + foreach (hdf5_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + if (hdf5_lang STREQUAL "C") + set(hdf5_target_name "hdf5") + elseif (hdf5_lang STREQUAL "CXX") + set(hdf5_target_name "hdf5_cpp") + elseif (hdf5_lang STREQUAL "Fortran") + set(hdf5_target_name "hdf5_fortran") + else () + continue () + endif () + + if (NOT TARGET "hdf5::${hdf5_target_name}") + if (HDF5_COMPILER_NO_INTERROGATE) + add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + else() + if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_lang}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_lang}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") + else () + # Error if we still don't have the location. + message(SEND_ERROR + "HDF5 was found, but a different variable was set which contains " + "the location of the `hdf5::${hdf5_target_name}` library.") + endif () + add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") + if (NOT HDF5_${hdf5_lang}_INCLUDE_DIRS) + set(HDF5_${hdf5_lang}_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS}) + endif () + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + if (_hdf5_location_release) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}") + endif() + if (_hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}") + endif() + if (NOT _hdf5_location_release AND NOT _hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION "${_hdf5_location}") + endif() + if (_hdf5_libtype STREQUAL "SHARED") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) + elseif (_hdf5_libtype STREQUAL "STATIC") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) + endif () + unset(_hdf5_definitions) + unset(_hdf5_libtype) + unset(_hdf5_location) + unset(_hdf5_location_release) + unset(_hdf5_location_debug) + endif () + endif () + + if (NOT HDF5_FIND_HL) + continue () + endif () + + set(hdf5_alt_target_name "") + if (hdf5_lang STREQUAL "C") + set(hdf5_target_name "hdf5_hl") + elseif (hdf5_lang STREQUAL "CXX") + set(hdf5_target_name "hdf5_hl_cpp") + elseif (hdf5_lang STREQUAL "Fortran") + set(hdf5_target_name "hdf5_hl_fortran") + set(hdf5_alt_target_name "hdf5hl_fortran") + else () + continue () + endif () + + if (NOT TARGET "hdf5::${hdf5_target_name}") + if (HDF5_COMPILER_NO_INTERROGATE) + add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + else() + if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_HL_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_lang}_HL_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_lang}_HL_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_lang}_HL_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") + elseif (hdf5_alt_target_name AND DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}}") + else () + # Error if we still don't have the location. + message(SEND_ERROR + "HDF5 was found, but a different variable was set which contains " + "the location of the `hdf5::${hdf5_target_name}` library.") + endif () + add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + if (_hdf5_location_release) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}") + endif() + if (_hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}") + endif() + if (NOT _hdf5_location_release AND NOT _hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION "${_hdf5_location}") + endif() + if (_hdf5_libtype STREQUAL "SHARED") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) + elseif (_hdf5_libtype STREQUAL "STATIC") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) + endif () + unset(_hdf5_definitions) + unset(_hdf5_libtype) + unset(_hdf5_location) + endif () + endif () + endforeach () + unset(hdf5_lang) + + if (HDF5_DIFF_EXECUTABLE AND NOT TARGET hdf5::h5diff) + add_executable(hdf5::h5diff IMPORTED) + set_target_properties(hdf5::h5diff PROPERTIES + IMPORTED_LOCATION "${HDF5_DIFF_EXECUTABLE}") + endif () +endif () + +if (HDF5_FIND_DEBUG) + message(STATUS "HDF5_DIR: ${HDF5_DIR}") + message(STATUS "HDF5_DEFINITIONS: ${HDF5_DEFINITIONS}") + message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}") + message(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}") + message(STATUS "HDF5_HL_LIBRARIES: ${HDF5_HL_LIBRARIES}") + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + message(STATUS "HDF5_${_lang}_DEFINITIONS: ${HDF5_${_lang}_DEFINITIONS}") + message(STATUS "HDF5_${_lang}_INCLUDE_DIR: ${HDF5_${_lang}_INCLUDE_DIR}") + message(STATUS "HDF5_${_lang}_INCLUDE_DIRS: ${HDF5_${_lang}_INCLUDE_DIRS}") + message(STATUS "HDF5_${_lang}_LIBRARY: ${HDF5_${_lang}_LIBRARY}") + message(STATUS "HDF5_${_lang}_LIBRARIES: ${HDF5_${_lang}_LIBRARIES}") + message(STATUS "HDF5_${_lang}_HL_LIBRARY: ${HDF5_${_lang}_HL_LIBRARY}") + message(STATUS "HDF5_${_lang}_HL_LIBRARIES: ${HDF5_${_lang}_HL_LIBRARIES}") + endforeach() + message(STATUS "Defined targets (if any):") + foreach(_lang IN ITEMS "" "_cpp" "_fortran") + foreach(_hl IN ITEMS "" "_hl") + foreach(_prefix IN ITEMS "hdf5::" "") + foreach(_suffix IN ITEMS "-static" "-shared" "") + set (_target ${_prefix}hdf5${_hl}${_lang}${_suffix}) + if (TARGET ${_target}) + message(STATUS "... ${_target}") + else() + #message(STATUS "... ${_target} does not exist") + endif() + endforeach() + endforeach() + endforeach() + endforeach() +endif() +unset(_lang) +unset(_HDF5_NEED_TO_SEARCH) + +cmake_policy(POP) diff --git a/plugins/decl_netcdf/cmake/4.3/SelectLibraryConfigurations.cmake b/plugins/decl_netcdf/cmake/4.3/SelectLibraryConfigurations.cmake new file mode 100644 index 000000000..5fde66e3e --- /dev/null +++ b/plugins/decl_netcdf/cmake/4.3/SelectLibraryConfigurations.cmake @@ -0,0 +1,187 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +SelectLibraryConfigurations +--------------------------- + +This module provides a command to automatically set library variables when +package is available with multiple :ref:`Build Configurations`. It is +intended for use in :ref:`Find Modules` implementing +:command:`find_package()` calls. + +Load this module in a CMake find module with: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + include(SelectLibraryConfigurations) + +Supported build configurations are ``Release`` and ``Debug`` as these are +the most common ones in such packages. + +.. note:: + + This module has been available since early versions of CMake, when the + ``_LIBRARIES`` result variable was used for linking found + packages. When writing standard find modules, :ref:`Imported Targets` should + be preferred. In addition to or as an alternative to this module, imported + targets provide finer control over linking through the + :prop_tgt:`IMPORTED_CONFIGURATIONS` property. + +Commands +^^^^^^^^ + +This module provides the following command: + +.. command:: select_library_configurations + + Sets and adjusts library variables based on debug and release build + configurations: + + .. code-block:: cmake + + select_library_configurations() + + This command is a helper for setting the ``_LIBRARY`` and + ``_LIBRARIES`` result variables when a library might be provided + with multiple build configurations. + + The argument is: + + ```` + The base name of the library, used as a prefix for variable names. This is + the name of the package as used in the ``Find.cmake`` module + filename, or the component name, when find module provides them. + + Prior to calling this command the following cache variables should be set + in the find module (for example, by the :command:`find_library` command): + + ``_LIBRARY_RELEASE`` + A cache variable storing the full path to the ``Release`` build of the + library. If not set or found, this command will set its value to + ``_LIBRARY_RELEASE-NOTFOUND``. + + ``_LIBRARY_DEBUG`` + A cache variable storing the full path to the ``Debug`` build of the + library. If not set or found, this command will set its value to + ``_LIBRARY_DEBUG-NOTFOUND``. + + This command then sets the following local result variables: + + ``_LIBRARY`` + A result variable that is set to the value of + ``_LIBRARY_RELEASE`` variable if found, otherwise it is set to the + value of ``_LIBRARY_DEBUG`` variable if found. If both are found, + the release library value takes precedence. If both are not found, it is set + to value ``_LIBRARY-NOTFOUND``. + + If the :manual:`CMake Generator ` in use supports + build configurations, then this variable will be a list of found libraries + each prepended with the ``optimized`` or ``debug`` keywords specifying which + library should be linked for the given configuration. These keywords are + used by the :command:`target_link_libraries` command. If a build + configuration has not been set or the generator in use does not support + build configurations, then this variable value will not contain these + keywords. + + ``_LIBRARIES`` + A result variable that is set to the same value as the + ``_LIBRARY`` variable. + + .. note:: + + The ``select_library_configurations()`` command should be called before + handling standard find module arguments with + :command:`find_package_handle_standard_args` to ensure that the + ``_FOUND`` result variable is correctly set based on + ``_LIBRARY`` or other related variables. + +Examples +^^^^^^^^ + +Setting library variables based on the build configuration inside a find module +file: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + # Find release and debug build of the library + find_library(Foo_LIBRARY_RELEASE ...) + find_library(Foo_LIBRARY_DEBUG ...) + + # Set Foo_LIBRARY and Foo_LIBRARIES result variables + include(SelectLibraryConfigurations) + select_library_configurations(Foo) + + # Set Foo_FOUND variable and print result message. + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( + Foo + REQUIRED_VARS Foo_LIBRARY ... + ) + +When find module provides components with multiple build configurations: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + include(SelectLibraryConfigurations) + foreach(component IN LISTS Foo_FIND_COMPONENTS) + # ... + select_library_configurations(Foo_${component}) + # ... + endforeach() + +A project can then use this find module as follows: + +.. code-block:: cmake + :caption: ``CMakeLists.txt`` + + find_package(Foo) + target_link_libraries(project_target PRIVATE ${Foo_LIBRARIES}) + # ... +#]=======================================================================] + +# This macro was adapted from the FindQt4 CMake module and is maintained by Will +# Dicharry . + +macro(select_library_configurations basename) + if(NOT ${basename}_LIBRARY_RELEASE) + set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + if(NOT ${basename}_LIBRARY_DEBUG) + set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND + NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND + ( _isMultiConfig OR CMAKE_BUILD_TYPE ) ) + # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for + # single-config generators, set optimized and debug libraries + set( ${basename}_LIBRARY "" ) + foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE ) + list( APPEND ${basename}_LIBRARY optimized "${_libname}" ) + endforeach() + foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG ) + list( APPEND ${basename}_LIBRARY debug "${_libname}" ) + endforeach() + elseif( ${basename}_LIBRARY_RELEASE ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} ) + elseif( ${basename}_LIBRARY_DEBUG ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} ) + else() + set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND") + endif() + + set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" ) + + if( ${basename}_LIBRARY ) + set( ${basename}_FOUND TRUE ) + endif() + + mark_as_advanced( ${basename}_LIBRARY_RELEASE + ${basename}_LIBRARY_DEBUG + ) +endmacro() diff --git a/plugins/decl_netcdf/cmake/FindNetCDF.cmake b/plugins/decl_netcdf/cmake/FindNetCDF.cmake index b1465e884..0cdd109d5 100644 --- a/plugins/decl_netcdf/cmake/FindNetCDF.cmake +++ b/plugins/decl_netcdf/cmake/FindNetCDF.cmake @@ -369,7 +369,7 @@ if("${NetCDF_FOUND}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT ("${HDF5_PROVIDES_PARALLEL}" OR "${HDF5_IS_PARALLEL}")) + if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT "${HDF5_IS_PARALLEL}") message(ERROR "Parallel HDF5 required by NetCDF, sequential HDF5 only found.") endif() list(APPEND NetCDF_LINK_LIBRARIES hdf5::hdf5) From 071dff92508ea0f223ba5dd69f2b96739e4d3b12 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 14:17:13 +0200 Subject: [PATCH 11/59] Add version checks for HDF5 in CMakeLists.txt --- plugins/decl_hdf5/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 3b3045c2d..970eba144 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -51,6 +51,7 @@ find_package(HDF5 REQUIRED COMPONENTS C) if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() + if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "Parallel HDF5 required, sequential HDF5 only found. Please set -DBUILD_HDF5_PARALLEL=OFF to disable parallel HDF5") endif() From 6c5ceaaee0db15e10f988a75093b5d4f8619bf30 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 14:29:17 +0200 Subject: [PATCH 12/59] Typo [skip ci] --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a8e12c33..b5f4d05d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,13 +109,13 @@ if("${BUILD_DECL_NETCDF_PLUGIN}") if(4.1 VERSION_GREATER "${CMAKE_VERSION}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake/4.1") elseif(4.3 VERSION_GREATER "${CMAKE_VERSION}") - # Workaround conpiling with HDF5-2.0.0+ + # Workaround compiling with HDF5-2.0.0+ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake/4.3") endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake") endif() if("${BUILD_DECL_HDF5_PLUGIN}") - # Workaround conpiling with HDF5-2.0.0+ + # Workaround compiling with HDF5-2.0.0+ if(4.3 VERSION_GREATER "${CMAKE_VERSION}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake/4.3") endif() From 2c2c58b6725e109bc2adcdc1d386878aec623841 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 20 Mar 2026 14:31:29 +0100 Subject: [PATCH 13/59] add fix for hdf5 2.0.0 --- CMakeLists.txt | 5 ++++- plugins/decl_hdf5/CMakeLists.txt | 6 ++++-- plugins/decl_netcdf/cmake/FindNetCDF.cmake | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index debe4c134..e72a6d844 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,7 +308,7 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") sbuild_add_dependency(HDF5 "${USE_DEFAULT}" EMBEDDED_PATH "vendor/hdf5-1.12.3" COMPONENTS ${HDF5_COMPONENTS} - MODULE_VARS HDF5_IS_PARALLEL HDF5_VERSION + MODULE_VARS HDF5_IS_PARALLEL HDF5_PROVIDES_PARALLEL HDF5_VERSION CMAKE_CACHE_ARGS -DBUILD_STATIC_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF @@ -326,6 +326,9 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() + if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) + set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") + endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "You requested a parallel HDF5 build (-DBUILD_HDF5_PARALLEL=ON) but a sequential SYSTEM version has been found\n" diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 970eba144..18214a720 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -51,14 +51,16 @@ find_package(HDF5 REQUIRED COMPONENTS C) if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - +if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) + set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") +endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "Parallel HDF5 required, sequential HDF5 only found. Please set -DBUILD_HDF5_PARALLEL=OFF to disable parallel HDF5") endif() set(HDF5_DEPS hdf5::hdf5) # MPI -if("${HDF5_IS_PARALLEL}") +if("${HDF5_IS_PARALLEL}" OR "${HDF5_PROVIDES_PARALLEL}") if("${BUILD_TESTING}" AND "${BUILD_FORTRAN}") set(MPI_COMPONENTS Fortran) endif() diff --git a/plugins/decl_netcdf/cmake/FindNetCDF.cmake b/plugins/decl_netcdf/cmake/FindNetCDF.cmake index 0cdd109d5..b1465e884 100644 --- a/plugins/decl_netcdf/cmake/FindNetCDF.cmake +++ b/plugins/decl_netcdf/cmake/FindNetCDF.cmake @@ -369,7 +369,7 @@ if("${NetCDF_FOUND}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT "${HDF5_IS_PARALLEL}") + if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT ("${HDF5_PROVIDES_PARALLEL}" OR "${HDF5_IS_PARALLEL}")) message(ERROR "Parallel HDF5 required by NetCDF, sequential HDF5 only found.") endif() list(APPEND NetCDF_LINK_LIBRARIES hdf5::hdf5) From ba0aed4f027fec355ae95c209f6b3992f29fc1e7 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Thu, 9 Apr 2026 09:33:35 +0200 Subject: [PATCH 14/59] Fix MPI condition for HDF5 parallel support --- plugins/decl_hdf5/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 18214a720..26d195ada 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -60,7 +60,7 @@ endif() set(HDF5_DEPS hdf5::hdf5) # MPI -if("${HDF5_IS_PARALLEL}" OR "${HDF5_PROVIDES_PARALLEL}") +if("${HDF5_IS_PARALLEL}") if("${BUILD_TESTING}" AND "${BUILD_FORTRAN}") set(MPI_COMPONENTS Fortran) endif() From 51508029efe51204d98ba9fb657140635f022688 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 14:16:24 +0200 Subject: [PATCH 15/59] add cmake fix for version less than 4.3 --- CMakeLists.txt | 15 +- plugins/decl_hdf5/CMakeLists.txt | 3 - plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake | 1423 +++++++++++++++++ .../4.3/SelectLibraryConfigurations.cmake | 187 +++ plugins/decl_netcdf/CMakeLists.txt | 3 + plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake | 1423 +++++++++++++++++ .../4.3/SelectLibraryConfigurations.cmake | 187 +++ plugins/decl_netcdf/cmake/FindNetCDF.cmake | 2 +- 8 files changed, 3235 insertions(+), 8 deletions(-) create mode 100644 plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake create mode 100644 plugins/decl_hdf5/cmake/4.3/SelectLibraryConfigurations.cmake create mode 100644 plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake create mode 100644 plugins/decl_netcdf/cmake/4.3/SelectLibraryConfigurations.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e72a6d844..c411f9b04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,9 +108,19 @@ if("${BUILD_DECL_NETCDF_PLUGIN}") # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 if(4.1 VERSION_GREATER "${CMAKE_VERSION}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake/4.1") + elseif(4.3 VERSION_GREATER "${CMAKE_VERSION}") + # Workaround conpiling with HDF5-2.0.0+ + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake/4.3") endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake") endif() +if("${BUILD_DECL_HDF5_PLUGIN}") + # Workaround conpiling with HDF5-2.0.0+ + if(4.3 VERSION_GREATER "${CMAKE_VERSION}") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake/4.3") + endif() + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake") +endif() set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" CACHE STRING "" FORCE) @@ -308,7 +318,7 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") sbuild_add_dependency(HDF5 "${USE_DEFAULT}" EMBEDDED_PATH "vendor/hdf5-1.12.3" COMPONENTS ${HDF5_COMPONENTS} - MODULE_VARS HDF5_IS_PARALLEL HDF5_PROVIDES_PARALLEL HDF5_VERSION + MODULE_VARS HDF5_IS_PARALLEL HDF5_VERSION CMAKE_CACHE_ARGS -DBUILD_STATIC_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF @@ -326,9 +336,6 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) - set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") - endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "You requested a parallel HDF5 build (-DBUILD_HDF5_PARALLEL=ON) but a sequential SYSTEM version has been found\n" diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 26d195ada..3b3045c2d 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -51,9 +51,6 @@ find_package(HDF5 REQUIRED COMPONENTS C) if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() -if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) - set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") -endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "Parallel HDF5 required, sequential HDF5 only found. Please set -DBUILD_HDF5_PARALLEL=OFF to disable parallel HDF5") endif() diff --git a/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake b/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake new file mode 100644 index 000000000..0a15557f0 --- /dev/null +++ b/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake @@ -0,0 +1,1423 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindHDF5 +-------- + +Finds Hierarchical Data Format (HDF5), a library for reading and writing +self-describing array data: + +.. code-block:: cmake + + find_package(HDF5 [] [COMPONENTS ...] [...]) + +If the HDF5 library is built using its CMake-based build system, it will as +of HDF5 version 1.8.15 provide its own CMake Package Configuration file +(``hdf5-config.cmake``) for use with the :command:`find_package` command in +*config mode*. By default, this module searches for this file and, if found, +returns the results based on the found configuration. + +If the upstream configuration file is not found, this module falls back to +*module mode* and invokes the HDF5 wrapper compiler typically installed +with the HDF5 library. Depending on the configuration, this wrapper +compiler is named either ``h5cc`` (serial) or ``h5pcc`` (parallel). If +found, the wrapper is queried with the ``-show`` argument to determine the +compiler and linker flags required for building an HDF5 client application. +Both serial and parallel versions of the HDF5 wrapper are considered. The +first directory containing either is used. If both versions are found in the +same directory, the serial version is preferred by default. To change this +behavior, set the variable ``HDF5_PREFER_PARALLEL`` to ``TRUE``. + +In addition to finding the include directories and libraries needed to compile +an HDF5 application, this module also attempts to find additional tools +provided by the HDF5 distribution, which can be useful for regression testing +or development workflows. + +Components +^^^^^^^^^^ + +This module supports optional components, which can be specified with the +:command:`find_package` command: + +.. code-block:: cmake + + find_package(HDF5 [COMPONENTS ...]) + +Supported components include: + +``C`` + Finds the ``HDF5`` C library (C bindings). + +``CXX`` + Finds the ``HDF5`` C++ library (C++ bindings). + +``Fortran`` + Finds the ``HDF5`` Fortran library (Fortran bindings). + +``HL`` + This component can be used in combination with other components to find the + high-level (HL) HDF5 library variants for C, CXX, and/or Fortran, which + provide high-level functions. + +If no components are specified, then this module will by default search for the +``C`` component. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following :ref:`Imported Targets`: + +``HDF5::HDF5`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for all found HDF5 binding + libraries (``HDF5_LIBRARIES``), available if HDF5 and all required components + are found. + +``hdf5::hdf5`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 C library, available + if HDF5 library and its ``C`` component are found. + +``hdf5::hdf5_cpp`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 C and C++ libraries, + available if HDF5 library, and its ``C`` and ``CXX`` components are found. + +``hdf5::hdf5_fortran`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 Fortran library, + available if HDF5 library and its ``Fortran`` component are found. + +``hdf5::hdf5_hl`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 high-level C library, + available if HDF5 library and its ``C``, and ``HL`` components are found. + +``hdf5::hdf5_hl_cpp`` + .. versionadded:: 3.19 + + High-level C++ library. + + Target encapsulating the usage requirements for the HDF5 high-level C and + high-level C++ libraries, available if HDF5 library and its ``C``, ``CXX``, + and ``HL`` components are found. + +``hdf5::hdf5_hl_fortran`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 high-level Fortran + library, available if HDF5 library and its ``Fortran``, and ``HL`` components + are found. + +``hdf5::h5diff`` + .. versionadded:: 3.19 + + Imported executable target encapsulating the usage requirements for the + ``h5diff`` executable, available if ``h5diff`` is found. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module defines the following variables: + +``HDF5_FOUND`` + Boolean indicating whether (the requested version of) HDF5 was found. + +``HDF5_VERSION`` + .. versionadded:: 3.3 + + The version of HDF5 library found. + +``HDF5_INCLUDE_DIRS`` + Include directories containing header files needed to use HDF5. + +``HDF5_DEFINITIONS`` + Required compiler definitions for using HDF5. + +``HDF5_LIBRARIES`` + Libraries of all requested bindings needed to link against to use HDF5. + +``HDF5_HL_LIBRARIES`` + Required libraries for the HDF5 high-level API for all bindings, + if the ``HL`` component is enabled. + +``HDF5_IS_PARALLEL`` + Boolean indicating whether the HDF5 library has parallel IO support. + +For each enabled language binding component, a corresponding +``HDF5__LIBRARIES`` variable, and potentially +``HDF5__DEFINITIONS``, will be defined. If the ``HL`` component is +enabled, then ``HDF5__HL_LIBRARIES`` variables will also be defined: + +``HDF5_C_DEFINITIONS`` + Required compiler definitions for HDF5 C bindings. + +``HDF5_CXX_DEFINITIONS`` + Required compiler definitions for HDF5 C++ bindings. + +``HDF5_Fortran_DEFINITIONS`` + Required compiler definitions for HDF5 Fortran bindings. + +``HDF5_C_INCLUDE_DIRS`` + Required include directories for HDF5 C bindings. + +``HDF5_CXX_INCLUDE_DIRS`` + Required include directories for HDF5 C++ bindings. + +``HDF5_Fortran_INCLUDE_DIRS`` + Required include directories for HDF5 Fortran bindings. + +``HDF5_C_LIBRARIES`` + Required libraries for the HDF5 C bindings. + +``HDF5_CXX_LIBRARIES`` + Required libraries for the HDF5 C++ bindings. + +``HDF5_Fortran_LIBRARIES`` + Required libraries for the HDF5 Fortran bindings. + +``HDF5_C_HL_LIBRARIES`` + Required libraries for the high-level C bindings, if the ``HL`` component + is enabled. + +``HDF5_CXX_HL_LIBRARIES`` + Required libraries for the high-level C++ bindings, if the ``HL`` + component is enabled. + +``HDF5_Fortran_HL_LIBRARIES`` + Required libraries for the high-level Fortran bindings, if the ``HL`` + component is enabled. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``HDF5_C_COMPILER_EXECUTABLE`` + The path to the HDF5 C wrapper compiler. + +``HDF5_CXX_COMPILER_EXECUTABLE`` + The path to the HDF5 C++ wrapper compiler. + +``HDF5_Fortran_COMPILER_EXECUTABLE`` + The path to the HDF5 Fortran wrapper compiler. + +``HDF5_C_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary C compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_CXX_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary C++ compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_Fortran_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary Fortran compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_DIFF_EXECUTABLE`` + The path to the HDF5 dataset comparison tool (``h5diff``). + +Hints +^^^^^ + +The following variables can be set before calling the ``find_package(HDF5)`` +to guide the search for HDF5 library: + +``HDF5_PREFER_PARALLEL`` + .. versionadded:: 3.4 + + Set this to boolean true to prefer parallel HDF5 (by default, serial is + preferred). This variable is used only in *module mode*. + +``HDF5_FIND_DEBUG`` + .. versionadded:: 3.9 + + Set this to boolean true to get extra debugging output by this module. + +``HDF5_NO_FIND_PACKAGE_CONFIG_FILE`` + .. versionadded:: 3.8 + + Set this to boolean true to skip finding and using CMake package configuration + file (``hdf5-config.cmake``). + +``HDF5_USE_STATIC_LIBRARIES`` + Set this to boolean value to determine whether or not to prefer a + static link to a dynamic link for ``HDF5`` and all of its dependencies. + + .. versionadded:: 3.10 + Support for ``HDF5_USE_STATIC_LIBRARIES`` on Windows. + +Examples +^^^^^^^^ + +Examples: Finding HDF5 +"""""""""""""""""""""" + +Finding HDF5: + +.. code-block:: cmake + + find_package(HDF5) + +Specifying a minimum required version of HDF5 to find: + +.. code-block:: cmake + + find_package(HDF5 1.8.15) + +Finding HDF5 and making it required (if HDF5 is not found, processing stops with +an error message): + +.. code-block:: cmake + + find_package(HDF5 1.8.15 REQUIRED) + +Searching for static HDF5 libraries: + +.. code-block:: cmake + + set(HDF5_USE_STATIC_LIBRARIES TRUE) + find_package(HDF5) + +Specifying components to find high-level C and C++ functions: + +.. code-block:: cmake + + find_package(HDF5 COMPONENTS C CXX HL) + +Examples: Using HDF5 +"""""""""""""""""""" + +Finding HDF5 and linking it to a project target: + +.. code-block:: cmake + + find_package(HDF5) + target_link_libraries(project_target PRIVATE HDF5::HDF5) + +Using Fortran HDF5 and HDF5-HL functions: + +.. code-block:: cmake + + find_package(HDF5 COMPONENTS Fortran HL) + target_link_libraries(project_target PRIVATE HDF5::HDF5) +#]=======================================================================] + +include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) +include(FindPackageHandleStandardArgs) + +cmake_policy(PUSH) +cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_ + +# We haven't found HDF5 yet. Clear its state in case it is set in the parent +# scope somewhere else. We can't rely on it because different components may +# have been requested for this call. +set(HDF5_FOUND OFF) +set(HDF5_LIBRARIES) +set(HDF5_HL_LIBRARIES) + +# List of the valid HDF5 components +set(HDF5_VALID_LANGUAGE_BINDINGS C CXX Fortran) + +# Validate the list of find components. +if(NOT HDF5_FIND_COMPONENTS) + set(HDF5_LANGUAGE_BINDINGS "C") +else() + set(HDF5_LANGUAGE_BINDINGS) + # add the extra specified components, ensuring that they are valid. + set(HDF5_FIND_HL OFF) + foreach(_component IN LISTS HDF5_FIND_COMPONENTS) + list(FIND HDF5_VALID_LANGUAGE_BINDINGS ${_component} _component_location) + if(NOT _component_location EQUAL -1) + list(APPEND HDF5_LANGUAGE_BINDINGS ${_component}) + elseif(_component STREQUAL "HL") + set(HDF5_FIND_HL ON) + elseif(_component STREQUAL "Fortran_HL") # only for compatibility + list(APPEND HDF5_LANGUAGE_BINDINGS Fortran) + set(HDF5_FIND_HL ON) + set(HDF5_FIND_REQUIRED_Fortran_HL FALSE) + set(HDF5_FIND_REQUIRED_Fortran TRUE) + set(HDF5_FIND_REQUIRED_HL TRUE) + else() + message(FATAL_ERROR "${_component} is not a valid HDF5 component.") + endif() + endforeach() + unset(_component) + unset(_component_location) + if(NOT HDF5_LANGUAGE_BINDINGS) + get_property(_langs GLOBAL PROPERTY ENABLED_LANGUAGES) + foreach(_lang IN LISTS _langs) + if(_lang MATCHES "^(C|CXX|Fortran)$") + list(APPEND HDF5_LANGUAGE_BINDINGS ${_lang}) + endif() + endforeach() + endif() + list(REMOVE_ITEM HDF5_FIND_COMPONENTS Fortran_HL) # replaced by Fortran and HL + list(REMOVE_DUPLICATES HDF5_LANGUAGE_BINDINGS) +endif() + +# Determine whether to search for serial or parallel executable first +if(HDF5_PREFER_PARALLEL) + set(HDF5_C_COMPILER_NAMES h5pcc h5cc) + set(HDF5_CXX_COMPILER_NAMES h5pc++ h5c++) + set(HDF5_Fortran_COMPILER_NAMES h5pfc h5fc) +else() + set(HDF5_C_COMPILER_NAMES h5cc h5pcc) + set(HDF5_CXX_COMPILER_NAMES h5c++ h5pc++) + set(HDF5_Fortran_COMPILER_NAMES h5fc h5pfc) +endif() + +# Prefer h5hl compilers if HDF5_FIND_HL is enabled +if(HDF5_FIND_HL) + list(PREPEND HDF5_C_COMPILER_NAMES h5hlcc) + list(PREPEND HDF5_CXX_COMPILER_NAMES h5hlc++) + list(PREPEND HDF5_Fortran_COMPILER_NAMES h5hlfc) +endif() + +# Test first if the current compilers automatically wrap HDF5 +function(_HDF5_test_regular_compiler_C success version is_parallel) + if(NOT ${success} OR + NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "#include \n" + "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" + "#ifdef H5_HAVE_PARALLEL\n" + "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" + "#endif\n" + "int main(int argc, char **argv) {\n" + " int require = 0;\n" + " require += info_ver[argc];\n" + "#ifdef H5_HAVE_PARALLEL\n" + " require += info_parallel[argc];\n" + "#endif\n" + " hid_t fid;\n" + " fid = H5Fcreate(\"foo.h5\",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);\n" + " return 0;\n" + "}") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_c + ) + endif() + if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c) + file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_c INFO_STRINGS + REGEX "^INFO:" + ) + string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" + INFO_VER "${INFO_STRINGS}" + ) + set(${version} ${CMAKE_MATCH_1}) + if(CMAKE_MATCH_3) + set(${version} ${HDF5_C_VERSION}.${CMAKE_MATCH_3}) + endif() + set(${version} ${${version}} PARENT_SCOPE) + + if(INFO_STRINGS MATCHES "INFO:PARALLEL") + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() +endfunction() + +function(_HDF5_test_regular_compiler_CXX success version is_parallel) + if(NOT ${success} OR + NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "#include \n" + "#ifndef H5_NO_NAMESPACE\n" + "using namespace H5;\n" + "#endif\n" + "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" + "#ifdef H5_HAVE_PARALLEL\n" + "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" + "#endif\n" + "int main(int argc, char **argv) {\n" + " int require = 0;\n" + " require += info_ver[argc];\n" + "#ifdef H5_HAVE_PARALLEL\n" + " require += info_parallel[argc];\n" + "#endif\n" + " H5File file(\"foo.h5\", H5F_ACC_TRUNC);\n" + " return 0;\n" + "}") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_cxx + ) + endif() + if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx) + file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx INFO_STRINGS + REGEX "^INFO:" + ) + string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" + INFO_VER "${INFO_STRINGS}" + ) + set(${version} ${CMAKE_MATCH_1}) + if(CMAKE_MATCH_3) + set(${version} ${HDF5_CXX_VERSION}.${CMAKE_MATCH_3}) + endif() + set(${version} ${${version}} PARENT_SCOPE) + + if(INFO_STRINGS MATCHES "INFO:PARALLEL") + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() +endfunction() + +function(_HDF5_test_regular_compiler_Fortran success is_parallel) + if(NOT ${success}) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "program hdf5_hello\n" + " use hdf5\n" + " integer error\n" + " call h5open_f(error)\n" + " call h5close_f(error)\n" + "end\n") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}") + if(${success}) + execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -showconfig + OUTPUT_VARIABLE config_output + ERROR_VARIABLE config_error + RESULT_VARIABLE config_result + ) + if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)") + # The value may be anything used when HDF5 was configured, + # so see if CMake interprets it as "true". + set(parallelHDF5 "${CMAKE_MATCH_1}") + if(parallelHDF5) + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() + endif() +endfunction() + +# Invoke the HDF5 wrapper compiler. The compiler return value is stored to the +# return_value argument, the text output is stored to the output variable. +function( _HDF5_invoke_compiler language output_var return_value_var version_var is_parallel_var) + set(is_parallel FALSE) + if(HDF5_USE_STATIC_LIBRARIES) + set(lib_type_args -noshlib) + else() + set(lib_type_args -shlib) + endif() + # Verify that the compiler wrapper can actually compile: sometimes the compiler + # wrapper exists, but not the compiler. E.g. Miniconda / Anaconda Python + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} "${_HDF5_TEST_SRC}" + WORKING_DIRECTORY ${_HDF5_TEST_DIR} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE return_value + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.") + endif() + else() + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -show ${lib_type_args} "${_HDF5_TEST_SRC}" + WORKING_DIRECTORY ${_HDF5_TEST_DIR} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE return_value + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "Unable to determine HDF5 ${language} flags from HDF5 wrapper.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "Unable to determine HDF5 ${language} flags from HDF5 wrapper.") + endif() + endif() + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -showconfig + OUTPUT_VARIABLE config_output + ERROR_VARIABLE config_output + RESULT_VARIABLE return_value + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.") + endif() + endif() + string(REGEX MATCH "HDF5 Version: ([a-zA-Z0-9\\.\\-]*)" version "${config_output}") + if(version) + string(REPLACE "HDF5 Version: " "" version "${version}") + string(REPLACE "-patch" "." version "${version}") + endif() + if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)") + # The value may be anything used when HDF5 was configured, + # so see if CMake interprets it as "true". + set(parallelHDF5 "${CMAKE_MATCH_1}") + if(parallelHDF5) + set(is_parallel TRUE) + endif() + endif() + endif() + foreach(var output return_value version is_parallel) + set(${${var}_var} ${${var}} PARENT_SCOPE) + endforeach() +endfunction() + +# Parse a compile line for definitions, includes, library paths, and libraries. +function(_HDF5_parse_compile_line compile_line_var include_paths definitions + library_paths libraries libraries_hl) + + separate_arguments(_compile_args NATIVE_COMMAND "${${compile_line_var}}") + + foreach(_arg IN LISTS _compile_args) + if("${_arg}" MATCHES "^-I(.*)$") + # include directory + list(APPEND include_paths "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-D(.*)$") + # compile definition + list(APPEND definitions "-D${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-L(.*)$") + # library search path + list(APPEND library_paths "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-l(hdf5.*hl.*)$") + # library name (hl) + list(APPEND libraries_hl "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-l(.*)$") + # library name + list(APPEND libraries "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^(.:)?[/\\].*\\.(a|so|dylib|sl|lib)$") + # library file + if(NOT EXISTS "${_arg}") + continue() + endif() + get_filename_component(_lpath "${_arg}" DIRECTORY) + get_filename_component(_lname "${_arg}" NAME_WE) + string(REGEX REPLACE "^lib" "" _lname "${_lname}") + list(APPEND library_paths "${_lpath}") + if(_lname MATCHES "hdf5.*hl") + list(APPEND libraries_hl "${_lname}") + else() + list(APPEND libraries "${_lname}") + endif() + endif() + endforeach() + foreach(var include_paths definitions library_paths libraries libraries_hl) + set(${${var}_var} ${${var}} PARENT_SCOPE) + endforeach() +endfunction() + +# Select a preferred imported configuration from a target +function(_HDF5_select_imported_config target imported_conf) + # We will first assign the value to a local variable _imported_conf, then assign + # it to the function argument at the end. + get_target_property(_imported_conf ${target} MAP_IMPORTED_CONFIG_${CMAKE_BUILD_TYPE}) + if (NOT _imported_conf) + # Get available imported configurations by examining target properties + get_target_property(_imported_conf ${target} IMPORTED_CONFIGURATIONS) + if(HDF5_FIND_DEBUG) + message(STATUS "Found imported configurations: ${_imported_conf}") + endif() + # Find the imported configuration that we prefer. + # We do this by making list of configurations in order of preference, + # starting with ${CMAKE_BUILD_TYPE} and ending with the first imported_conf + set(_preferred_confs ${CMAKE_BUILD_TYPE}) + list(GET _imported_conf 0 _fallback_conf) + list(APPEND _preferred_confs RELWITHDEBINFO RELEASE DEBUG ${_fallback_conf}) + if(HDF5_FIND_DEBUG) + message(STATUS "Start search through imported configurations in the following order: ${_preferred_confs}") + endif() + # Now find the first of these that is present in imported_conf + foreach (_conf IN LISTS _preferred_confs) + if (${_conf} IN_LIST _imported_conf) + set(_imported_conf ${_conf}) + break() + endif() + endforeach() + endif() + if(HDF5_FIND_DEBUG) + message(STATUS "Selected imported configuration: ${_imported_conf}") + endif() + # assign value to function argument + set(${imported_conf} ${_imported_conf} PARENT_SCOPE) +endfunction() + + +if(NOT HDF5_ROOT) + set(HDF5_ROOT $ENV{HDF5_ROOT}) +endif() +if(HDF5_ROOT) + set(_HDF5_SEARCH_OPTS NO_DEFAULT_PATH) +else() + set(_HDF5_SEARCH_OPTS) +endif() + +# Try to find HDF5 using an installed hdf5-config.cmake +if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE) + find_package(HDF5 QUIET NO_MODULE + HINTS ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS} + ) + if( HDF5_FOUND) + if(HDF5_FIND_DEBUG) + message(STATUS "Found HDF5 at ${HDF5_DIR} via NO_MODULE. Now trying to extract locations etc.") + endif() + # Extract information from imported targets + if (DEFINED HDF5_ENABLE_PARALLEL) + # Versions of <2.0.0 use `HDF5_ENABLE_PARALLEL` + set(HDF5_IS_PARALLEL ${HDF5_ENABLE_PARALLEL}) + elseif(DEFINED HDF5_PROVIDES_PARALLEL) + # Versions of >=2.0.0 use `HDF5_PROVIDES_PARALLEL` + set(HDF5_IS_PARALLEL ${HDF5_PROVIDES_PARALLEL}) + else() + set(HDF5_IS_PARALLEL NONE) + endif() + set(HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR}) + set(HDF5_LIBRARIES) + if (NOT TARGET hdf5 AND NOT TARGET hdf5-static AND NOT TARGET hdf5-shared) + # Some HDF5 versions (e.g. 1.8.18) used hdf5::hdf5 etc + set(_target_prefix "hdf5::") + endif() + set(HDF5_C_TARGET ${_target_prefix}hdf5) + set(HDF5_C_HL_TARGET ${_target_prefix}hdf5_hl) + set(HDF5_CXX_TARGET ${_target_prefix}hdf5_cpp) + set(HDF5_CXX_HL_TARGET ${_target_prefix}hdf5_hl_cpp) + set(HDF5_Fortran_TARGET ${_target_prefix}hdf5_fortran) + set(HDF5_Fortran_HL_TARGET ${_target_prefix}hdf5_hl_fortran) + set(HDF5_DEFINITIONS "") + if(HDF5_USE_STATIC_LIBRARIES) + set(_suffix "-static") + else() + set(_suffix "-shared") + endif() + foreach(_lang ${HDF5_LANGUAGE_BINDINGS}) + + #Older versions of hdf5 don't have a static/shared suffix so + #if we detect that occurrence clear the suffix + if(_suffix AND NOT TARGET ${HDF5_${_lang}_TARGET}${_suffix}) + if(NOT TARGET ${HDF5_${_lang}_TARGET}) + #can't find this component with or without the suffix + #so bail out, and let the following locate HDF5 + set(HDF5_FOUND FALSE) + break() + endif() + set(_suffix "") + endif() + + if(HDF5_FIND_DEBUG) + message(STATUS "Trying to get properties of target ${HDF5_${_lang}_TARGET}${_suffix}") + endif() + # Find library for this target. Complicated as on Windows with a DLL, we need to search for the import-lib. + _HDF5_select_imported_config(${HDF5_${_lang}_TARGET}${_suffix} _hdf5_imported_conf) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_location) + # no import lib, just try LOCATION + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_lang_location) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION) + endif() + endif() + if( _hdf5_lang_location ) + set(HDF5_${_lang}_LIBRARY ${_hdf5_lang_location}) + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) + set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) + set(HDF5_${_lang}_FOUND TRUE) + endif() + if(HDF5_FIND_HL) + get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_hl_location) + get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_hl_lang_location) + get_target_property(_hdf5_hl_lang_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION) + endif() + endif() + if( _hdf5_lang_hl_location ) + set(HDF5_${_lang}_HL_LIBRARY ${_hdf5_lang_hl_location}) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) + set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) + set(HDF5_HL_FOUND TRUE) + endif() + unset(_hdf5_lang_hl_location) + endif() + unset(_hdf5_imported_conf) + unset(_hdf5_lang_location) + endforeach() + endif() +endif() + +if(NOT HDF5_FOUND) + set(_HDF5_NEED_TO_SEARCH FALSE) + set(_HDF5_TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5) + set(HDF5_COMPILER_NO_INTERROGATE TRUE) + # Only search for languages we've enabled + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + # First check to see if our regular compiler is one of wrappers + if(_lang STREQUAL "C") + set(_HDF5_TEST_SRC cmake_hdf5_test.c) + if(CMAKE_CXX_COMPILER_LOADED AND NOT CMAKE_C_COMPILER_LOADED) + # CXX project without C enabled + set(_HDF5_TEST_SRC cmake_hdf5_test.cxx) + endif() + _HDF5_test_regular_compiler_C( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_VERSION + HDF5_${_lang}_IS_PARALLEL) + elseif(_lang STREQUAL "CXX") + set(_HDF5_TEST_SRC cmake_hdf5_test.cxx) + _HDF5_test_regular_compiler_CXX( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_VERSION + HDF5_${_lang}_IS_PARALLEL) + elseif(_lang STREQUAL "Fortran") + set(_HDF5_TEST_SRC cmake_hdf5_test.f90) + _HDF5_test_regular_compiler_Fortran( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_IS_PARALLEL) + else() + continue() + endif() + if(HDF5_${_lang}_COMPILER_NO_INTERROGATE) + if(HDF5_FIND_DEBUG) + message(STATUS "HDF5: Using hdf5 compiler wrapper for all ${_lang} compiling") + endif() + set(HDF5_${_lang}_FOUND TRUE) + set(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE + "${CMAKE_${_lang}_COMPILER}" + CACHE FILEPATH "HDF5 ${_lang} compiler wrapper") + set(HDF5_${_lang}_DEFINITIONS) + set(HDF5_${_lang}_INCLUDE_DIRS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + mark_as_advanced(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE) + + set(HDF5_${_lang}_FOUND TRUE) + set(HDF5_HL_FOUND TRUE) + else() + set(HDF5_COMPILER_NO_INTERROGATE FALSE) + # If this language isn't using the wrapper, then try to seed the + # search options with the wrapper + find_program(HDF5_${_lang}_COMPILER_EXECUTABLE + NAMES ${HDF5_${_lang}_COMPILER_NAMES} NAMES_PER_DIR + HINTS ${HDF5_ROOT} + PATH_SUFFIXES bin Bin + DOC "HDF5 ${_lang} Wrapper compiler. Used only to detect HDF5 compile flags." + ${_HDF5_SEARCH_OPTS} + ) + mark_as_advanced( HDF5_${_lang}_COMPILER_EXECUTABLE ) + unset(HDF5_${_lang}_COMPILER_NAMES) + + if(HDF5_${_lang}_COMPILER_EXECUTABLE) + _HDF5_invoke_compiler(${_lang} HDF5_${_lang}_COMPILE_LINE + HDF5_${_lang}_RETURN_VALUE HDF5_${_lang}_VERSION HDF5_${_lang}_IS_PARALLEL) + if(HDF5_${_lang}_RETURN_VALUE EQUAL 0) + if(HDF5_FIND_DEBUG) + message(STATUS "HDF5: Using hdf5 compiler wrapper to determine ${_lang} configuration") + endif() + _HDF5_parse_compile_line( HDF5_${_lang}_COMPILE_LINE + HDF5_${_lang}_INCLUDE_DIRS + HDF5_${_lang}_DEFINITIONS + HDF5_${_lang}_LIBRARY_DIRS + HDF5_${_lang}_LIBRARY_NAMES + HDF5_${_lang}_HL_LIBRARY_NAMES + ) + set(HDF5_${_lang}_LIBRARIES) + + foreach(_lib IN LISTS HDF5_${_lang}_LIBRARY_NAMES) + set(_HDF5_SEARCH_NAMES_LOCAL) + if("x${_lib}" MATCHES "hdf5") + # hdf5 library + set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) + if(HDF5_USE_STATIC_LIBRARIES) + if(WIN32) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) + else() + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) + endif() + endif() + else() + # external library + set(_HDF5_SEARCH_OPTS_LOCAL) + endif() + find_library(HDF5_${_lang}_LIBRARY_${_lib} + NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR + HINTS ${HDF5_${_lang}_LIBRARY_DIRS} + ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS_LOCAL} + ) + unset(_HDF5_SEARCH_OPTS_LOCAL) + unset(_HDF5_SEARCH_NAMES_LOCAL) + if(HDF5_${_lang}_LIBRARY_${_lib}) + list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) + else() + list(APPEND HDF5_${_lang}_LIBRARIES ${_lib}) + endif() + endforeach() + if(HDF5_FIND_HL) + set(HDF5_${_lang}_HL_LIBRARIES) + foreach(_lib IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) + set(_HDF5_SEARCH_NAMES_LOCAL) + if("x${_lib}" MATCHES "hdf5") + # hdf5 library + set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) + if(HDF5_USE_STATIC_LIBRARIES) + if(WIN32) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) + else() + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) + endif() + endif() + else() + # external library + set(_HDF5_SEARCH_OPTS_LOCAL) + endif() + find_library(HDF5_${_lang}_LIBRARY_${_lib} + NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR + HINTS ${HDF5_${_lang}_LIBRARY_DIRS} + ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS_LOCAL} + ) + unset(_HDF5_SEARCH_OPTS_LOCAL) + unset(_HDF5_SEARCH_NAMES_LOCAL) + if(HDF5_${_lang}_LIBRARY_${_lib}) + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) + else() + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${_lib}) + endif() + endforeach() + set(HDF5_HL_FOUND TRUE) + endif() + + set(HDF5_${_lang}_FOUND TRUE) + list(REMOVE_DUPLICATES HDF5_${_lang}_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_${_lang}_INCLUDE_DIRS) + else() + set(_HDF5_NEED_TO_SEARCH TRUE) + endif() + else() + set(_HDF5_NEED_TO_SEARCH TRUE) + endif() + endif() + if(HDF5_${_lang}_VERSION) + if(NOT HDF5_VERSION) + set(HDF5_VERSION ${HDF5_${_lang}_VERSION}) + elseif(NOT HDF5_VERSION VERSION_EQUAL HDF5_${_lang}_VERSION) + message(WARNING "HDF5 Version found for language ${_lang}, ${HDF5_${_lang}_VERSION} is different than previously found version ${HDF5_VERSION}") + endif() + endif() + if(DEFINED HDF5_${_lang}_IS_PARALLEL) + if(NOT DEFINED HDF5_IS_PARALLEL) + set(HDF5_IS_PARALLEL ${HDF5_${_lang}_IS_PARALLEL}) + elseif(NOT HDF5_IS_PARALLEL AND HDF5_${_lang}_IS_PARALLEL) + message(WARNING "HDF5 found for language ${_lang} is parallel but previously found language is not parallel.") + elseif(HDF5_IS_PARALLEL AND NOT HDF5_${_lang}_IS_PARALLEL) + message(WARNING "HDF5 found for language ${_lang} is not parallel but previously found language is parallel.") + endif() + endif() + endforeach() + unset(_HDF5_TEST_DIR) + unset(_HDF5_TEST_SRC) + unset(_lib) +else() + set(_HDF5_NEED_TO_SEARCH TRUE) +endif() + +if(NOT HDF5_FOUND AND HDF5_COMPILER_NO_INTERROGATE) + # No arguments necessary, all languages can use the compiler wrappers + set(HDF5_FOUND TRUE) + set(HDF5_METHOD "Included by compiler wrappers") + set(HDF5_REQUIRED_VARS HDF5_METHOD) +elseif(NOT HDF5_FOUND AND NOT _HDF5_NEED_TO_SEARCH) + # Compiler wrappers aren't being used by the build but were found and used + # to determine necessary include and library flags + set(HDF5_INCLUDE_DIRS) + set(HDF5_LIBRARIES) + set(HDF5_HL_LIBRARIES) + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + if(HDF5_${_lang}_FOUND) + if(NOT HDF5_${_lang}_COMPILER_NO_INTERROGATE) + list(APPEND HDF5_DEFINITIONS ${HDF5_${_lang}_DEFINITIONS}) + list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIRS}) + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) + if(HDF5_FIND_HL) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) + endif() + endif() + endif() + endforeach() + list(REMOVE_DUPLICATES HDF5_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) + set(HDF5_FOUND TRUE) + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES) + if(HDF5_FIND_HL) + list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) + endif() +endif() + +find_program( HDF5_DIFF_EXECUTABLE + NAMES h5diff + HINTS ${HDF5_ROOT} + PATH_SUFFIXES bin Bin + ${_HDF5_SEARCH_OPTS} + DOC "HDF5 file differencing tool." ) +mark_as_advanced( HDF5_DIFF_EXECUTABLE ) + +if( NOT HDF5_FOUND ) + # seed the initial lists of libraries to find with items we know we need + set(HDF5_C_LIBRARY_NAMES hdf5) + set(HDF5_C_HL_LIBRARY_NAMES hdf5_hl ${HDF5_C_LIBRARY_NAMES} ) + + set(HDF5_CXX_LIBRARY_NAMES hdf5_cpp ${HDF5_C_LIBRARY_NAMES}) + set(HDF5_CXX_HL_LIBRARY_NAMES hdf5_hl_cpp ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_CXX_LIBRARY_NAMES}) + + set(HDF5_Fortran_LIBRARY_NAMES hdf5_fortran ${HDF5_C_LIBRARY_NAMES}) + set(HDF5_Fortran_HL_LIBRARY_NAMES hdf5_hl_fortran hdf5hl_fortran ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_Fortran_LIBRARY_NAMES}) + + # suffixes as seen on Linux, MSYS2, ... + set(_lib_suffixes hdf5) + if(NOT HDF5_PREFER_PARALLEL) + list(APPEND _lib_suffixes hdf5/serial) + endif() + if(HDF5_USE_STATIC_LIBRARIES) + set(_inc_suffixes include/static) + else() + set(_inc_suffixes include/shared) + endif() + + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + # The "main" library. + set(_hdf5_main_library "") + + # find the HDF5 libraries + foreach(LIB IN LISTS HDF5_${_lang}_LIBRARY_NAMES) + if(HDF5_USE_STATIC_LIBRARIES) + # According to bug 1643 on the CMake bug tracker, this is the + # preferred method for searching for a static library. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search + # first for the full static library name, but fall back to a + # generic search on the name if the static search fails. + set( THIS_LIBRARY_SEARCH_DEBUG + lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug + lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_D-static ${LIB}_debug-static ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a ${LIB}-static) + else() + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) + set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) + if(WIN32) + list(APPEND HDF5_DEFINITIONS "-DH5_BUILT_AS_DYNAMIC_LIB") + endif() + endif() + find_library(HDF5_${LIB}_LIBRARY_DEBUG + NAMES ${THIS_LIBRARY_SEARCH_DEBUG} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + find_library(HDF5_${LIB}_LIBRARY_RELEASE + NAMES ${THIS_LIBRARY_SEARCH_RELEASE} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + + # Set the "main" library if not already set. + if (NOT _hdf5_main_library) + if (HDF5_${LIB}_LIBRARY_RELEASE) + set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_RELEASE}") + elseif (HDF5_${LIB}_LIBRARY_DEBUG) + set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_DEBUG}") + endif () + endif () + + select_library_configurations( HDF5_${LIB} ) + list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${LIB}_LIBRARY}) + endforeach() + if(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_FOUND TRUE) + endif() + + # Append the libraries for this language binding to the list of all + # required libraries. + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) + + # find the HDF5 include directories + set(_hdf5_inc_extra_paths) + set(_hdf5_inc_extra_suffixes) + if("${_lang}" STREQUAL "Fortran") + set(HDF5_INCLUDE_FILENAME hdf5.mod HDF5.mod) + + # Add library-based search paths for Fortran modules. + if (NOT _hdf5_main_library STREQUAL "") + # gfortran module directory + if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "LCC") + get_filename_component(_hdf5_library_dir "${_hdf5_main_library}" DIRECTORY) + list(APPEND _hdf5_inc_extra_paths "${_hdf5_library_dir}") + unset(_hdf5_library_dir) + list(APPEND _hdf5_inc_extra_suffixes gfortran/modules) + endif () + endif () + elseif("${_lang}" STREQUAL "CXX") + set(HDF5_INCLUDE_FILENAME H5Cpp.h) + else() + set(HDF5_INCLUDE_FILENAME hdf5.h) + endif() + + unset(_hdf5_main_library) + + find_path(HDF5_${_lang}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME} + HINTS ${HDF5_ROOT} + PATHS $ENV{HOME}/.local/include ${_hdf5_inc_extra_paths} + PATH_SUFFIXES include Include ${_inc_suffixes} ${_lib_suffixes} ${_hdf5_inc_extra_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + mark_as_advanced(HDF5_${_lang}_INCLUDE_DIR) + unset(_hdf5_inc_extra_paths) + unset(_hdf5_inc_extra_suffixes) + # set the _DIRS variable as this is what the user will normally use + set(HDF5_${_lang}_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) + list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) + + if(HDF5_FIND_HL) + foreach(LIB IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) + if(HDF5_USE_STATIC_LIBRARIES) + # According to bug 1643 on the CMake bug tracker, this is the + # preferred method for searching for a static library. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search + # first for the full static library name, but fall back to a + # generic search on the name if the static search fails. + set( THIS_LIBRARY_SEARCH_DEBUG + lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug + lib${LIB}d-static.a lib${LIB}_debug-static.a lib${LIB}d-static lib${LIB}_D-static lib${LIB}_debug-static ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a lib${LIB}-static) + else() + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) + set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) + endif() + find_library(HDF5_${LIB}_LIBRARY_DEBUG + NAMES ${THIS_LIBRARY_SEARCH_DEBUG} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + find_library(HDF5_${LIB}_LIBRARY_RELEASE + NAMES ${THIS_LIBRARY_SEARCH_RELEASE} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + + select_library_configurations( HDF5_${LIB} ) + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${LIB}_LIBRARY}) + endforeach() + + # Append the libraries for this language binding to the list of all + # required libraries. + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) + endif() + endforeach() + if(HDF5_FIND_HL AND HDF5_HL_LIBRARIES) + set(HDF5_HL_FOUND TRUE) + endif() + + list(REMOVE_DUPLICATES HDF5_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) + + # If the HDF5 include directory was found, open H5pubconf.h to determine if + # HDF5 was compiled with parallel IO support + set( HDF5_IS_PARALLEL FALSE ) + foreach( _dir IN LISTS HDF5_INCLUDE_DIRS ) + foreach(_hdr "${_dir}/H5pubconf.h" "${_dir}/H5pubconf-64.h" "${_dir}/H5pubconf-32.h") + if( EXISTS "${_hdr}" ) + file( STRINGS "${_hdr}" + HDF5_HAVE_PARALLEL_DEFINE + REGEX "HAVE_PARALLEL 1" ) + if( HDF5_HAVE_PARALLEL_DEFINE ) + set( HDF5_IS_PARALLEL TRUE ) + endif() + unset(HDF5_HAVE_PARALLEL_DEFINE) + + file( STRINGS "${_hdr}" + HDF5_VERSION_DEFINE + REGEX "^[ \t]*#[ \t]*define[ \t]+H5_VERSION[ \t]+" ) + if( "${HDF5_VERSION_DEFINE}" MATCHES + "H5_VERSION[ \t]+\"([0-9\\.]+)(-patch([0-9]+))?\"" ) + set( HDF5_VERSION "${CMAKE_MATCH_1}" ) + if( CMAKE_MATCH_3 ) + set( HDF5_VERSION ${HDF5_VERSION}.${CMAKE_MATCH_3}) + endif() + endif() + unset(HDF5_VERSION_DEFINE) + endif() + endforeach() + endforeach() + unset(_hdr) + unset(_dir) + set( HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL + "HDF5 library compiled with parallel IO support" ) + mark_as_advanced( HDF5_IS_PARALLEL ) + + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS) + if(HDF5_FIND_HL) + list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) + endif() +endif() + +# For backwards compatibility we set HDF5_INCLUDE_DIR to the value of +# HDF5_INCLUDE_DIRS +if( HDF5_INCLUDE_DIRS ) + set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" ) +endif() + +# If HDF5_REQUIRED_VARS is empty at this point, then it's likely that +# something external is trying to explicitly pass already found +# locations +if(NOT HDF5_REQUIRED_VARS) + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS) +endif() + +find_package_handle_standard_args(HDF5 + REQUIRED_VARS ${HDF5_REQUIRED_VARS} + VERSION_VAR HDF5_VERSION + HANDLE_COMPONENTS +) + +unset(_HDF5_SEARCH_OPTS) + +if( HDF5_FOUND AND NOT HDF5_DIR) + # hide HDF5_DIR for the non-advanced user to avoid confusion with + # HDF5_DIR-NOT_FOUND while HDF5 was found. + mark_as_advanced(HDF5_DIR) +endif() + +if (HDF5_FOUND) + if (NOT TARGET HDF5::HDF5) + add_library(HDF5::HDF5 INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_DEFINITIONS}") + set_target_properties(HDF5::HDF5 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + unset(_hdf5_definitions) + target_link_libraries(HDF5::HDF5 INTERFACE ${HDF5_LIBRARIES}) + endif () + + foreach (hdf5_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + if (hdf5_lang STREQUAL "C") + set(hdf5_target_name "hdf5") + elseif (hdf5_lang STREQUAL "CXX") + set(hdf5_target_name "hdf5_cpp") + elseif (hdf5_lang STREQUAL "Fortran") + set(hdf5_target_name "hdf5_fortran") + else () + continue () + endif () + + if (NOT TARGET "hdf5::${hdf5_target_name}") + if (HDF5_COMPILER_NO_INTERROGATE) + add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + else() + if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_lang}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_lang}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") + else () + # Error if we still don't have the location. + message(SEND_ERROR + "HDF5 was found, but a different variable was set which contains " + "the location of the `hdf5::${hdf5_target_name}` library.") + endif () + add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") + if (NOT HDF5_${hdf5_lang}_INCLUDE_DIRS) + set(HDF5_${hdf5_lang}_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS}) + endif () + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + if (_hdf5_location_release) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}") + endif() + if (_hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}") + endif() + if (NOT _hdf5_location_release AND NOT _hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION "${_hdf5_location}") + endif() + if (_hdf5_libtype STREQUAL "SHARED") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) + elseif (_hdf5_libtype STREQUAL "STATIC") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) + endif () + unset(_hdf5_definitions) + unset(_hdf5_libtype) + unset(_hdf5_location) + unset(_hdf5_location_release) + unset(_hdf5_location_debug) + endif () + endif () + + if (NOT HDF5_FIND_HL) + continue () + endif () + + set(hdf5_alt_target_name "") + if (hdf5_lang STREQUAL "C") + set(hdf5_target_name "hdf5_hl") + elseif (hdf5_lang STREQUAL "CXX") + set(hdf5_target_name "hdf5_hl_cpp") + elseif (hdf5_lang STREQUAL "Fortran") + set(hdf5_target_name "hdf5_hl_fortran") + set(hdf5_alt_target_name "hdf5hl_fortran") + else () + continue () + endif () + + if (NOT TARGET "hdf5::${hdf5_target_name}") + if (HDF5_COMPILER_NO_INTERROGATE) + add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + else() + if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_HL_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_lang}_HL_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_lang}_HL_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_lang}_HL_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") + elseif (hdf5_alt_target_name AND DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}}") + else () + # Error if we still don't have the location. + message(SEND_ERROR + "HDF5 was found, but a different variable was set which contains " + "the location of the `hdf5::${hdf5_target_name}` library.") + endif () + add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + if (_hdf5_location_release) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}") + endif() + if (_hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}") + endif() + if (NOT _hdf5_location_release AND NOT _hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION "${_hdf5_location}") + endif() + if (_hdf5_libtype STREQUAL "SHARED") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) + elseif (_hdf5_libtype STREQUAL "STATIC") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) + endif () + unset(_hdf5_definitions) + unset(_hdf5_libtype) + unset(_hdf5_location) + endif () + endif () + endforeach () + unset(hdf5_lang) + + if (HDF5_DIFF_EXECUTABLE AND NOT TARGET hdf5::h5diff) + add_executable(hdf5::h5diff IMPORTED) + set_target_properties(hdf5::h5diff PROPERTIES + IMPORTED_LOCATION "${HDF5_DIFF_EXECUTABLE}") + endif () +endif () + +if (HDF5_FIND_DEBUG) + message(STATUS "HDF5_DIR: ${HDF5_DIR}") + message(STATUS "HDF5_DEFINITIONS: ${HDF5_DEFINITIONS}") + message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}") + message(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}") + message(STATUS "HDF5_HL_LIBRARIES: ${HDF5_HL_LIBRARIES}") + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + message(STATUS "HDF5_${_lang}_DEFINITIONS: ${HDF5_${_lang}_DEFINITIONS}") + message(STATUS "HDF5_${_lang}_INCLUDE_DIR: ${HDF5_${_lang}_INCLUDE_DIR}") + message(STATUS "HDF5_${_lang}_INCLUDE_DIRS: ${HDF5_${_lang}_INCLUDE_DIRS}") + message(STATUS "HDF5_${_lang}_LIBRARY: ${HDF5_${_lang}_LIBRARY}") + message(STATUS "HDF5_${_lang}_LIBRARIES: ${HDF5_${_lang}_LIBRARIES}") + message(STATUS "HDF5_${_lang}_HL_LIBRARY: ${HDF5_${_lang}_HL_LIBRARY}") + message(STATUS "HDF5_${_lang}_HL_LIBRARIES: ${HDF5_${_lang}_HL_LIBRARIES}") + endforeach() + message(STATUS "Defined targets (if any):") + foreach(_lang IN ITEMS "" "_cpp" "_fortran") + foreach(_hl IN ITEMS "" "_hl") + foreach(_prefix IN ITEMS "hdf5::" "") + foreach(_suffix IN ITEMS "-static" "-shared" "") + set (_target ${_prefix}hdf5${_hl}${_lang}${_suffix}) + if (TARGET ${_target}) + message(STATUS "... ${_target}") + else() + #message(STATUS "... ${_target} does not exist") + endif() + endforeach() + endforeach() + endforeach() + endforeach() +endif() +unset(_lang) +unset(_HDF5_NEED_TO_SEARCH) + +cmake_policy(POP) diff --git a/plugins/decl_hdf5/cmake/4.3/SelectLibraryConfigurations.cmake b/plugins/decl_hdf5/cmake/4.3/SelectLibraryConfigurations.cmake new file mode 100644 index 000000000..5fde66e3e --- /dev/null +++ b/plugins/decl_hdf5/cmake/4.3/SelectLibraryConfigurations.cmake @@ -0,0 +1,187 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +SelectLibraryConfigurations +--------------------------- + +This module provides a command to automatically set library variables when +package is available with multiple :ref:`Build Configurations`. It is +intended for use in :ref:`Find Modules` implementing +:command:`find_package()` calls. + +Load this module in a CMake find module with: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + include(SelectLibraryConfigurations) + +Supported build configurations are ``Release`` and ``Debug`` as these are +the most common ones in such packages. + +.. note:: + + This module has been available since early versions of CMake, when the + ``_LIBRARIES`` result variable was used for linking found + packages. When writing standard find modules, :ref:`Imported Targets` should + be preferred. In addition to or as an alternative to this module, imported + targets provide finer control over linking through the + :prop_tgt:`IMPORTED_CONFIGURATIONS` property. + +Commands +^^^^^^^^ + +This module provides the following command: + +.. command:: select_library_configurations + + Sets and adjusts library variables based on debug and release build + configurations: + + .. code-block:: cmake + + select_library_configurations() + + This command is a helper for setting the ``_LIBRARY`` and + ``_LIBRARIES`` result variables when a library might be provided + with multiple build configurations. + + The argument is: + + ```` + The base name of the library, used as a prefix for variable names. This is + the name of the package as used in the ``Find.cmake`` module + filename, or the component name, when find module provides them. + + Prior to calling this command the following cache variables should be set + in the find module (for example, by the :command:`find_library` command): + + ``_LIBRARY_RELEASE`` + A cache variable storing the full path to the ``Release`` build of the + library. If not set or found, this command will set its value to + ``_LIBRARY_RELEASE-NOTFOUND``. + + ``_LIBRARY_DEBUG`` + A cache variable storing the full path to the ``Debug`` build of the + library. If not set or found, this command will set its value to + ``_LIBRARY_DEBUG-NOTFOUND``. + + This command then sets the following local result variables: + + ``_LIBRARY`` + A result variable that is set to the value of + ``_LIBRARY_RELEASE`` variable if found, otherwise it is set to the + value of ``_LIBRARY_DEBUG`` variable if found. If both are found, + the release library value takes precedence. If both are not found, it is set + to value ``_LIBRARY-NOTFOUND``. + + If the :manual:`CMake Generator ` in use supports + build configurations, then this variable will be a list of found libraries + each prepended with the ``optimized`` or ``debug`` keywords specifying which + library should be linked for the given configuration. These keywords are + used by the :command:`target_link_libraries` command. If a build + configuration has not been set or the generator in use does not support + build configurations, then this variable value will not contain these + keywords. + + ``_LIBRARIES`` + A result variable that is set to the same value as the + ``_LIBRARY`` variable. + + .. note:: + + The ``select_library_configurations()`` command should be called before + handling standard find module arguments with + :command:`find_package_handle_standard_args` to ensure that the + ``_FOUND`` result variable is correctly set based on + ``_LIBRARY`` or other related variables. + +Examples +^^^^^^^^ + +Setting library variables based on the build configuration inside a find module +file: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + # Find release and debug build of the library + find_library(Foo_LIBRARY_RELEASE ...) + find_library(Foo_LIBRARY_DEBUG ...) + + # Set Foo_LIBRARY and Foo_LIBRARIES result variables + include(SelectLibraryConfigurations) + select_library_configurations(Foo) + + # Set Foo_FOUND variable and print result message. + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( + Foo + REQUIRED_VARS Foo_LIBRARY ... + ) + +When find module provides components with multiple build configurations: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + include(SelectLibraryConfigurations) + foreach(component IN LISTS Foo_FIND_COMPONENTS) + # ... + select_library_configurations(Foo_${component}) + # ... + endforeach() + +A project can then use this find module as follows: + +.. code-block:: cmake + :caption: ``CMakeLists.txt`` + + find_package(Foo) + target_link_libraries(project_target PRIVATE ${Foo_LIBRARIES}) + # ... +#]=======================================================================] + +# This macro was adapted from the FindQt4 CMake module and is maintained by Will +# Dicharry . + +macro(select_library_configurations basename) + if(NOT ${basename}_LIBRARY_RELEASE) + set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + if(NOT ${basename}_LIBRARY_DEBUG) + set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND + NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND + ( _isMultiConfig OR CMAKE_BUILD_TYPE ) ) + # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for + # single-config generators, set optimized and debug libraries + set( ${basename}_LIBRARY "" ) + foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE ) + list( APPEND ${basename}_LIBRARY optimized "${_libname}" ) + endforeach() + foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG ) + list( APPEND ${basename}_LIBRARY debug "${_libname}" ) + endforeach() + elseif( ${basename}_LIBRARY_RELEASE ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} ) + elseif( ${basename}_LIBRARY_DEBUG ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} ) + else() + set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND") + endif() + + set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" ) + + if( ${basename}_LIBRARY ) + set( ${basename}_FOUND TRUE ) + endif() + + mark_as_advanced( ${basename}_LIBRARY_RELEASE + ${basename}_LIBRARY_DEBUG + ) +endmacro() diff --git a/plugins/decl_netcdf/CMakeLists.txt b/plugins/decl_netcdf/CMakeLists.txt index 96e14ed4d..b3c973139 100644 --- a/plugins/decl_netcdf/CMakeLists.txt +++ b/plugins/decl_netcdf/CMakeLists.txt @@ -34,6 +34,9 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") if("${CMAKE_VERSION}" VERSION_LESS 4.1) # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/4.1") +elseif("${CMAKE_VERSION}" VERSION_LESS 4.3) + # Workaround for compiling with HDF5-2.0.0+ + list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/4.3") endif() option(BUILD_NETCDF_PARALLEL "Build Decl'NetCDF in parallel mode" ON) diff --git a/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake b/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake new file mode 100644 index 000000000..0a15557f0 --- /dev/null +++ b/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake @@ -0,0 +1,1423 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindHDF5 +-------- + +Finds Hierarchical Data Format (HDF5), a library for reading and writing +self-describing array data: + +.. code-block:: cmake + + find_package(HDF5 [] [COMPONENTS ...] [...]) + +If the HDF5 library is built using its CMake-based build system, it will as +of HDF5 version 1.8.15 provide its own CMake Package Configuration file +(``hdf5-config.cmake``) for use with the :command:`find_package` command in +*config mode*. By default, this module searches for this file and, if found, +returns the results based on the found configuration. + +If the upstream configuration file is not found, this module falls back to +*module mode* and invokes the HDF5 wrapper compiler typically installed +with the HDF5 library. Depending on the configuration, this wrapper +compiler is named either ``h5cc`` (serial) or ``h5pcc`` (parallel). If +found, the wrapper is queried with the ``-show`` argument to determine the +compiler and linker flags required for building an HDF5 client application. +Both serial and parallel versions of the HDF5 wrapper are considered. The +first directory containing either is used. If both versions are found in the +same directory, the serial version is preferred by default. To change this +behavior, set the variable ``HDF5_PREFER_PARALLEL`` to ``TRUE``. + +In addition to finding the include directories and libraries needed to compile +an HDF5 application, this module also attempts to find additional tools +provided by the HDF5 distribution, which can be useful for regression testing +or development workflows. + +Components +^^^^^^^^^^ + +This module supports optional components, which can be specified with the +:command:`find_package` command: + +.. code-block:: cmake + + find_package(HDF5 [COMPONENTS ...]) + +Supported components include: + +``C`` + Finds the ``HDF5`` C library (C bindings). + +``CXX`` + Finds the ``HDF5`` C++ library (C++ bindings). + +``Fortran`` + Finds the ``HDF5`` Fortran library (Fortran bindings). + +``HL`` + This component can be used in combination with other components to find the + high-level (HL) HDF5 library variants for C, CXX, and/or Fortran, which + provide high-level functions. + +If no components are specified, then this module will by default search for the +``C`` component. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following :ref:`Imported Targets`: + +``HDF5::HDF5`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for all found HDF5 binding + libraries (``HDF5_LIBRARIES``), available if HDF5 and all required components + are found. + +``hdf5::hdf5`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 C library, available + if HDF5 library and its ``C`` component are found. + +``hdf5::hdf5_cpp`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 C and C++ libraries, + available if HDF5 library, and its ``C`` and ``CXX`` components are found. + +``hdf5::hdf5_fortran`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 Fortran library, + available if HDF5 library and its ``Fortran`` component are found. + +``hdf5::hdf5_hl`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 high-level C library, + available if HDF5 library and its ``C``, and ``HL`` components are found. + +``hdf5::hdf5_hl_cpp`` + .. versionadded:: 3.19 + + High-level C++ library. + + Target encapsulating the usage requirements for the HDF5 high-level C and + high-level C++ libraries, available if HDF5 library and its ``C``, ``CXX``, + and ``HL`` components are found. + +``hdf5::hdf5_hl_fortran`` + .. versionadded:: 3.19 + + Target encapsulating the usage requirements for the HDF5 high-level Fortran + library, available if HDF5 library and its ``Fortran``, and ``HL`` components + are found. + +``hdf5::h5diff`` + .. versionadded:: 3.19 + + Imported executable target encapsulating the usage requirements for the + ``h5diff`` executable, available if ``h5diff`` is found. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module defines the following variables: + +``HDF5_FOUND`` + Boolean indicating whether (the requested version of) HDF5 was found. + +``HDF5_VERSION`` + .. versionadded:: 3.3 + + The version of HDF5 library found. + +``HDF5_INCLUDE_DIRS`` + Include directories containing header files needed to use HDF5. + +``HDF5_DEFINITIONS`` + Required compiler definitions for using HDF5. + +``HDF5_LIBRARIES`` + Libraries of all requested bindings needed to link against to use HDF5. + +``HDF5_HL_LIBRARIES`` + Required libraries for the HDF5 high-level API for all bindings, + if the ``HL`` component is enabled. + +``HDF5_IS_PARALLEL`` + Boolean indicating whether the HDF5 library has parallel IO support. + +For each enabled language binding component, a corresponding +``HDF5__LIBRARIES`` variable, and potentially +``HDF5__DEFINITIONS``, will be defined. If the ``HL`` component is +enabled, then ``HDF5__HL_LIBRARIES`` variables will also be defined: + +``HDF5_C_DEFINITIONS`` + Required compiler definitions for HDF5 C bindings. + +``HDF5_CXX_DEFINITIONS`` + Required compiler definitions for HDF5 C++ bindings. + +``HDF5_Fortran_DEFINITIONS`` + Required compiler definitions for HDF5 Fortran bindings. + +``HDF5_C_INCLUDE_DIRS`` + Required include directories for HDF5 C bindings. + +``HDF5_CXX_INCLUDE_DIRS`` + Required include directories for HDF5 C++ bindings. + +``HDF5_Fortran_INCLUDE_DIRS`` + Required include directories for HDF5 Fortran bindings. + +``HDF5_C_LIBRARIES`` + Required libraries for the HDF5 C bindings. + +``HDF5_CXX_LIBRARIES`` + Required libraries for the HDF5 C++ bindings. + +``HDF5_Fortran_LIBRARIES`` + Required libraries for the HDF5 Fortran bindings. + +``HDF5_C_HL_LIBRARIES`` + Required libraries for the high-level C bindings, if the ``HL`` component + is enabled. + +``HDF5_CXX_HL_LIBRARIES`` + Required libraries for the high-level C++ bindings, if the ``HL`` + component is enabled. + +``HDF5_Fortran_HL_LIBRARIES`` + Required libraries for the high-level Fortran bindings, if the ``HL`` + component is enabled. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``HDF5_C_COMPILER_EXECUTABLE`` + The path to the HDF5 C wrapper compiler. + +``HDF5_CXX_COMPILER_EXECUTABLE`` + The path to the HDF5 C++ wrapper compiler. + +``HDF5_Fortran_COMPILER_EXECUTABLE`` + The path to the HDF5 Fortran wrapper compiler. + +``HDF5_C_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary C compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_CXX_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary C++ compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_Fortran_COMPILER_EXECUTABLE_NO_INTERROGATE`` + .. versionadded:: 3.6 + + The path to the primary Fortran compiler which is also the HDF5 wrapper. + This variable is used only in *module mode*. + +``HDF5_DIFF_EXECUTABLE`` + The path to the HDF5 dataset comparison tool (``h5diff``). + +Hints +^^^^^ + +The following variables can be set before calling the ``find_package(HDF5)`` +to guide the search for HDF5 library: + +``HDF5_PREFER_PARALLEL`` + .. versionadded:: 3.4 + + Set this to boolean true to prefer parallel HDF5 (by default, serial is + preferred). This variable is used only in *module mode*. + +``HDF5_FIND_DEBUG`` + .. versionadded:: 3.9 + + Set this to boolean true to get extra debugging output by this module. + +``HDF5_NO_FIND_PACKAGE_CONFIG_FILE`` + .. versionadded:: 3.8 + + Set this to boolean true to skip finding and using CMake package configuration + file (``hdf5-config.cmake``). + +``HDF5_USE_STATIC_LIBRARIES`` + Set this to boolean value to determine whether or not to prefer a + static link to a dynamic link for ``HDF5`` and all of its dependencies. + + .. versionadded:: 3.10 + Support for ``HDF5_USE_STATIC_LIBRARIES`` on Windows. + +Examples +^^^^^^^^ + +Examples: Finding HDF5 +"""""""""""""""""""""" + +Finding HDF5: + +.. code-block:: cmake + + find_package(HDF5) + +Specifying a minimum required version of HDF5 to find: + +.. code-block:: cmake + + find_package(HDF5 1.8.15) + +Finding HDF5 and making it required (if HDF5 is not found, processing stops with +an error message): + +.. code-block:: cmake + + find_package(HDF5 1.8.15 REQUIRED) + +Searching for static HDF5 libraries: + +.. code-block:: cmake + + set(HDF5_USE_STATIC_LIBRARIES TRUE) + find_package(HDF5) + +Specifying components to find high-level C and C++ functions: + +.. code-block:: cmake + + find_package(HDF5 COMPONENTS C CXX HL) + +Examples: Using HDF5 +"""""""""""""""""""" + +Finding HDF5 and linking it to a project target: + +.. code-block:: cmake + + find_package(HDF5) + target_link_libraries(project_target PRIVATE HDF5::HDF5) + +Using Fortran HDF5 and HDF5-HL functions: + +.. code-block:: cmake + + find_package(HDF5 COMPONENTS Fortran HL) + target_link_libraries(project_target PRIVATE HDF5::HDF5) +#]=======================================================================] + +include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) +include(FindPackageHandleStandardArgs) + +cmake_policy(PUSH) +cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_ + +# We haven't found HDF5 yet. Clear its state in case it is set in the parent +# scope somewhere else. We can't rely on it because different components may +# have been requested for this call. +set(HDF5_FOUND OFF) +set(HDF5_LIBRARIES) +set(HDF5_HL_LIBRARIES) + +# List of the valid HDF5 components +set(HDF5_VALID_LANGUAGE_BINDINGS C CXX Fortran) + +# Validate the list of find components. +if(NOT HDF5_FIND_COMPONENTS) + set(HDF5_LANGUAGE_BINDINGS "C") +else() + set(HDF5_LANGUAGE_BINDINGS) + # add the extra specified components, ensuring that they are valid. + set(HDF5_FIND_HL OFF) + foreach(_component IN LISTS HDF5_FIND_COMPONENTS) + list(FIND HDF5_VALID_LANGUAGE_BINDINGS ${_component} _component_location) + if(NOT _component_location EQUAL -1) + list(APPEND HDF5_LANGUAGE_BINDINGS ${_component}) + elseif(_component STREQUAL "HL") + set(HDF5_FIND_HL ON) + elseif(_component STREQUAL "Fortran_HL") # only for compatibility + list(APPEND HDF5_LANGUAGE_BINDINGS Fortran) + set(HDF5_FIND_HL ON) + set(HDF5_FIND_REQUIRED_Fortran_HL FALSE) + set(HDF5_FIND_REQUIRED_Fortran TRUE) + set(HDF5_FIND_REQUIRED_HL TRUE) + else() + message(FATAL_ERROR "${_component} is not a valid HDF5 component.") + endif() + endforeach() + unset(_component) + unset(_component_location) + if(NOT HDF5_LANGUAGE_BINDINGS) + get_property(_langs GLOBAL PROPERTY ENABLED_LANGUAGES) + foreach(_lang IN LISTS _langs) + if(_lang MATCHES "^(C|CXX|Fortran)$") + list(APPEND HDF5_LANGUAGE_BINDINGS ${_lang}) + endif() + endforeach() + endif() + list(REMOVE_ITEM HDF5_FIND_COMPONENTS Fortran_HL) # replaced by Fortran and HL + list(REMOVE_DUPLICATES HDF5_LANGUAGE_BINDINGS) +endif() + +# Determine whether to search for serial or parallel executable first +if(HDF5_PREFER_PARALLEL) + set(HDF5_C_COMPILER_NAMES h5pcc h5cc) + set(HDF5_CXX_COMPILER_NAMES h5pc++ h5c++) + set(HDF5_Fortran_COMPILER_NAMES h5pfc h5fc) +else() + set(HDF5_C_COMPILER_NAMES h5cc h5pcc) + set(HDF5_CXX_COMPILER_NAMES h5c++ h5pc++) + set(HDF5_Fortran_COMPILER_NAMES h5fc h5pfc) +endif() + +# Prefer h5hl compilers if HDF5_FIND_HL is enabled +if(HDF5_FIND_HL) + list(PREPEND HDF5_C_COMPILER_NAMES h5hlcc) + list(PREPEND HDF5_CXX_COMPILER_NAMES h5hlc++) + list(PREPEND HDF5_Fortran_COMPILER_NAMES h5hlfc) +endif() + +# Test first if the current compilers automatically wrap HDF5 +function(_HDF5_test_regular_compiler_C success version is_parallel) + if(NOT ${success} OR + NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "#include \n" + "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" + "#ifdef H5_HAVE_PARALLEL\n" + "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" + "#endif\n" + "int main(int argc, char **argv) {\n" + " int require = 0;\n" + " require += info_ver[argc];\n" + "#ifdef H5_HAVE_PARALLEL\n" + " require += info_parallel[argc];\n" + "#endif\n" + " hid_t fid;\n" + " fid = H5Fcreate(\"foo.h5\",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);\n" + " return 0;\n" + "}") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_c + ) + endif() + if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c) + file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_c INFO_STRINGS + REGEX "^INFO:" + ) + string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" + INFO_VER "${INFO_STRINGS}" + ) + set(${version} ${CMAKE_MATCH_1}) + if(CMAKE_MATCH_3) + set(${version} ${HDF5_C_VERSION}.${CMAKE_MATCH_3}) + endif() + set(${version} ${${version}} PARENT_SCOPE) + + if(INFO_STRINGS MATCHES "INFO:PARALLEL") + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() +endfunction() + +function(_HDF5_test_regular_compiler_CXX success version is_parallel) + if(NOT ${success} OR + NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "#include \n" + "#ifndef H5_NO_NAMESPACE\n" + "using namespace H5;\n" + "#endif\n" + "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" + "#ifdef H5_HAVE_PARALLEL\n" + "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" + "#endif\n" + "int main(int argc, char **argv) {\n" + " int require = 0;\n" + " require += info_ver[argc];\n" + "#ifdef H5_HAVE_PARALLEL\n" + " require += info_parallel[argc];\n" + "#endif\n" + " H5File file(\"foo.h5\", H5F_ACC_TRUNC);\n" + " return 0;\n" + "}") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_cxx + ) + endif() + if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx) + file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx INFO_STRINGS + REGEX "^INFO:" + ) + string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" + INFO_VER "${INFO_STRINGS}" + ) + set(${version} ${CMAKE_MATCH_1}) + if(CMAKE_MATCH_3) + set(${version} ${HDF5_CXX_VERSION}.${CMAKE_MATCH_3}) + endif() + set(${version} ${${version}} PARENT_SCOPE) + + if(INFO_STRINGS MATCHES "INFO:PARALLEL") + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() +endfunction() + +function(_HDF5_test_regular_compiler_Fortran success is_parallel) + if(NOT ${success}) + file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + "program hdf5_hello\n" + " use hdf5\n" + " integer error\n" + " call h5open_f(error)\n" + " call h5close_f(error)\n" + "end\n") + try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}") + if(${success}) + execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -showconfig + OUTPUT_VARIABLE config_output + ERROR_VARIABLE config_error + RESULT_VARIABLE config_result + ) + if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)") + # The value may be anything used when HDF5 was configured, + # so see if CMake interprets it as "true". + set(parallelHDF5 "${CMAKE_MATCH_1}") + if(parallelHDF5) + set(${is_parallel} TRUE PARENT_SCOPE) + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + else() + set(${is_parallel} FALSE PARENT_SCOPE) + endif() + endif() + endif() +endfunction() + +# Invoke the HDF5 wrapper compiler. The compiler return value is stored to the +# return_value argument, the text output is stored to the output variable. +function( _HDF5_invoke_compiler language output_var return_value_var version_var is_parallel_var) + set(is_parallel FALSE) + if(HDF5_USE_STATIC_LIBRARIES) + set(lib_type_args -noshlib) + else() + set(lib_type_args -shlib) + endif() + # Verify that the compiler wrapper can actually compile: sometimes the compiler + # wrapper exists, but not the compiler. E.g. Miniconda / Anaconda Python + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} "${_HDF5_TEST_SRC}" + WORKING_DIRECTORY ${_HDF5_TEST_DIR} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE return_value + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.") + endif() + else() + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -show ${lib_type_args} "${_HDF5_TEST_SRC}" + WORKING_DIRECTORY ${_HDF5_TEST_DIR} + OUTPUT_VARIABLE output + ERROR_VARIABLE output + RESULT_VARIABLE return_value + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "Unable to determine HDF5 ${language} flags from HDF5 wrapper.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "Unable to determine HDF5 ${language} flags from HDF5 wrapper.") + endif() + endif() + execute_process( + COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -showconfig + OUTPUT_VARIABLE config_output + ERROR_VARIABLE config_output + RESULT_VARIABLE return_value + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT return_value EQUAL 0) + message(CONFIGURE_LOG + "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.\n\n${output}") + if(NOT HDF5_FIND_QUIETLY) + message(STATUS + "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.") + endif() + endif() + string(REGEX MATCH "HDF5 Version: ([a-zA-Z0-9\\.\\-]*)" version "${config_output}") + if(version) + string(REPLACE "HDF5 Version: " "" version "${version}") + string(REPLACE "-patch" "." version "${version}") + endif() + if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)") + # The value may be anything used when HDF5 was configured, + # so see if CMake interprets it as "true". + set(parallelHDF5 "${CMAKE_MATCH_1}") + if(parallelHDF5) + set(is_parallel TRUE) + endif() + endif() + endif() + foreach(var output return_value version is_parallel) + set(${${var}_var} ${${var}} PARENT_SCOPE) + endforeach() +endfunction() + +# Parse a compile line for definitions, includes, library paths, and libraries. +function(_HDF5_parse_compile_line compile_line_var include_paths definitions + library_paths libraries libraries_hl) + + separate_arguments(_compile_args NATIVE_COMMAND "${${compile_line_var}}") + + foreach(_arg IN LISTS _compile_args) + if("${_arg}" MATCHES "^-I(.*)$") + # include directory + list(APPEND include_paths "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-D(.*)$") + # compile definition + list(APPEND definitions "-D${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-L(.*)$") + # library search path + list(APPEND library_paths "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-l(hdf5.*hl.*)$") + # library name (hl) + list(APPEND libraries_hl "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^-l(.*)$") + # library name + list(APPEND libraries "${CMAKE_MATCH_1}") + elseif("${_arg}" MATCHES "^(.:)?[/\\].*\\.(a|so|dylib|sl|lib)$") + # library file + if(NOT EXISTS "${_arg}") + continue() + endif() + get_filename_component(_lpath "${_arg}" DIRECTORY) + get_filename_component(_lname "${_arg}" NAME_WE) + string(REGEX REPLACE "^lib" "" _lname "${_lname}") + list(APPEND library_paths "${_lpath}") + if(_lname MATCHES "hdf5.*hl") + list(APPEND libraries_hl "${_lname}") + else() + list(APPEND libraries "${_lname}") + endif() + endif() + endforeach() + foreach(var include_paths definitions library_paths libraries libraries_hl) + set(${${var}_var} ${${var}} PARENT_SCOPE) + endforeach() +endfunction() + +# Select a preferred imported configuration from a target +function(_HDF5_select_imported_config target imported_conf) + # We will first assign the value to a local variable _imported_conf, then assign + # it to the function argument at the end. + get_target_property(_imported_conf ${target} MAP_IMPORTED_CONFIG_${CMAKE_BUILD_TYPE}) + if (NOT _imported_conf) + # Get available imported configurations by examining target properties + get_target_property(_imported_conf ${target} IMPORTED_CONFIGURATIONS) + if(HDF5_FIND_DEBUG) + message(STATUS "Found imported configurations: ${_imported_conf}") + endif() + # Find the imported configuration that we prefer. + # We do this by making list of configurations in order of preference, + # starting with ${CMAKE_BUILD_TYPE} and ending with the first imported_conf + set(_preferred_confs ${CMAKE_BUILD_TYPE}) + list(GET _imported_conf 0 _fallback_conf) + list(APPEND _preferred_confs RELWITHDEBINFO RELEASE DEBUG ${_fallback_conf}) + if(HDF5_FIND_DEBUG) + message(STATUS "Start search through imported configurations in the following order: ${_preferred_confs}") + endif() + # Now find the first of these that is present in imported_conf + foreach (_conf IN LISTS _preferred_confs) + if (${_conf} IN_LIST _imported_conf) + set(_imported_conf ${_conf}) + break() + endif() + endforeach() + endif() + if(HDF5_FIND_DEBUG) + message(STATUS "Selected imported configuration: ${_imported_conf}") + endif() + # assign value to function argument + set(${imported_conf} ${_imported_conf} PARENT_SCOPE) +endfunction() + + +if(NOT HDF5_ROOT) + set(HDF5_ROOT $ENV{HDF5_ROOT}) +endif() +if(HDF5_ROOT) + set(_HDF5_SEARCH_OPTS NO_DEFAULT_PATH) +else() + set(_HDF5_SEARCH_OPTS) +endif() + +# Try to find HDF5 using an installed hdf5-config.cmake +if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE) + find_package(HDF5 QUIET NO_MODULE + HINTS ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS} + ) + if( HDF5_FOUND) + if(HDF5_FIND_DEBUG) + message(STATUS "Found HDF5 at ${HDF5_DIR} via NO_MODULE. Now trying to extract locations etc.") + endif() + # Extract information from imported targets + if (DEFINED HDF5_ENABLE_PARALLEL) + # Versions of <2.0.0 use `HDF5_ENABLE_PARALLEL` + set(HDF5_IS_PARALLEL ${HDF5_ENABLE_PARALLEL}) + elseif(DEFINED HDF5_PROVIDES_PARALLEL) + # Versions of >=2.0.0 use `HDF5_PROVIDES_PARALLEL` + set(HDF5_IS_PARALLEL ${HDF5_PROVIDES_PARALLEL}) + else() + set(HDF5_IS_PARALLEL NONE) + endif() + set(HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR}) + set(HDF5_LIBRARIES) + if (NOT TARGET hdf5 AND NOT TARGET hdf5-static AND NOT TARGET hdf5-shared) + # Some HDF5 versions (e.g. 1.8.18) used hdf5::hdf5 etc + set(_target_prefix "hdf5::") + endif() + set(HDF5_C_TARGET ${_target_prefix}hdf5) + set(HDF5_C_HL_TARGET ${_target_prefix}hdf5_hl) + set(HDF5_CXX_TARGET ${_target_prefix}hdf5_cpp) + set(HDF5_CXX_HL_TARGET ${_target_prefix}hdf5_hl_cpp) + set(HDF5_Fortran_TARGET ${_target_prefix}hdf5_fortran) + set(HDF5_Fortran_HL_TARGET ${_target_prefix}hdf5_hl_fortran) + set(HDF5_DEFINITIONS "") + if(HDF5_USE_STATIC_LIBRARIES) + set(_suffix "-static") + else() + set(_suffix "-shared") + endif() + foreach(_lang ${HDF5_LANGUAGE_BINDINGS}) + + #Older versions of hdf5 don't have a static/shared suffix so + #if we detect that occurrence clear the suffix + if(_suffix AND NOT TARGET ${HDF5_${_lang}_TARGET}${_suffix}) + if(NOT TARGET ${HDF5_${_lang}_TARGET}) + #can't find this component with or without the suffix + #so bail out, and let the following locate HDF5 + set(HDF5_FOUND FALSE) + break() + endif() + set(_suffix "") + endif() + + if(HDF5_FIND_DEBUG) + message(STATUS "Trying to get properties of target ${HDF5_${_lang}_TARGET}${_suffix}") + endif() + # Find library for this target. Complicated as on Windows with a DLL, we need to search for the import-lib. + _HDF5_select_imported_config(${HDF5_${_lang}_TARGET}${_suffix} _hdf5_imported_conf) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_location) + # no import lib, just try LOCATION + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_lang_location) + get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION) + endif() + endif() + if( _hdf5_lang_location ) + set(HDF5_${_lang}_LIBRARY ${_hdf5_lang_location}) + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) + set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) + set(HDF5_${_lang}_FOUND TRUE) + endif() + if(HDF5_FIND_HL) + get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) + if (NOT _hdf5_lang_hl_location) + get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) + if (NOT _hdf5_hl_lang_location) + get_target_property(_hdf5_hl_lang_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION) + endif() + endif() + if( _hdf5_lang_hl_location ) + set(HDF5_${_lang}_HL_LIBRARY ${_hdf5_lang_hl_location}) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) + set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) + set(HDF5_HL_FOUND TRUE) + endif() + unset(_hdf5_lang_hl_location) + endif() + unset(_hdf5_imported_conf) + unset(_hdf5_lang_location) + endforeach() + endif() +endif() + +if(NOT HDF5_FOUND) + set(_HDF5_NEED_TO_SEARCH FALSE) + set(_HDF5_TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5) + set(HDF5_COMPILER_NO_INTERROGATE TRUE) + # Only search for languages we've enabled + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + # First check to see if our regular compiler is one of wrappers + if(_lang STREQUAL "C") + set(_HDF5_TEST_SRC cmake_hdf5_test.c) + if(CMAKE_CXX_COMPILER_LOADED AND NOT CMAKE_C_COMPILER_LOADED) + # CXX project without C enabled + set(_HDF5_TEST_SRC cmake_hdf5_test.cxx) + endif() + _HDF5_test_regular_compiler_C( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_VERSION + HDF5_${_lang}_IS_PARALLEL) + elseif(_lang STREQUAL "CXX") + set(_HDF5_TEST_SRC cmake_hdf5_test.cxx) + _HDF5_test_regular_compiler_CXX( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_VERSION + HDF5_${_lang}_IS_PARALLEL) + elseif(_lang STREQUAL "Fortran") + set(_HDF5_TEST_SRC cmake_hdf5_test.f90) + _HDF5_test_regular_compiler_Fortran( + HDF5_${_lang}_COMPILER_NO_INTERROGATE + HDF5_${_lang}_IS_PARALLEL) + else() + continue() + endif() + if(HDF5_${_lang}_COMPILER_NO_INTERROGATE) + if(HDF5_FIND_DEBUG) + message(STATUS "HDF5: Using hdf5 compiler wrapper for all ${_lang} compiling") + endif() + set(HDF5_${_lang}_FOUND TRUE) + set(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE + "${CMAKE_${_lang}_COMPILER}" + CACHE FILEPATH "HDF5 ${_lang} compiler wrapper") + set(HDF5_${_lang}_DEFINITIONS) + set(HDF5_${_lang}_INCLUDE_DIRS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + mark_as_advanced(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE) + + set(HDF5_${_lang}_FOUND TRUE) + set(HDF5_HL_FOUND TRUE) + else() + set(HDF5_COMPILER_NO_INTERROGATE FALSE) + # If this language isn't using the wrapper, then try to seed the + # search options with the wrapper + find_program(HDF5_${_lang}_COMPILER_EXECUTABLE + NAMES ${HDF5_${_lang}_COMPILER_NAMES} NAMES_PER_DIR + HINTS ${HDF5_ROOT} + PATH_SUFFIXES bin Bin + DOC "HDF5 ${_lang} Wrapper compiler. Used only to detect HDF5 compile flags." + ${_HDF5_SEARCH_OPTS} + ) + mark_as_advanced( HDF5_${_lang}_COMPILER_EXECUTABLE ) + unset(HDF5_${_lang}_COMPILER_NAMES) + + if(HDF5_${_lang}_COMPILER_EXECUTABLE) + _HDF5_invoke_compiler(${_lang} HDF5_${_lang}_COMPILE_LINE + HDF5_${_lang}_RETURN_VALUE HDF5_${_lang}_VERSION HDF5_${_lang}_IS_PARALLEL) + if(HDF5_${_lang}_RETURN_VALUE EQUAL 0) + if(HDF5_FIND_DEBUG) + message(STATUS "HDF5: Using hdf5 compiler wrapper to determine ${_lang} configuration") + endif() + _HDF5_parse_compile_line( HDF5_${_lang}_COMPILE_LINE + HDF5_${_lang}_INCLUDE_DIRS + HDF5_${_lang}_DEFINITIONS + HDF5_${_lang}_LIBRARY_DIRS + HDF5_${_lang}_LIBRARY_NAMES + HDF5_${_lang}_HL_LIBRARY_NAMES + ) + set(HDF5_${_lang}_LIBRARIES) + + foreach(_lib IN LISTS HDF5_${_lang}_LIBRARY_NAMES) + set(_HDF5_SEARCH_NAMES_LOCAL) + if("x${_lib}" MATCHES "hdf5") + # hdf5 library + set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) + if(HDF5_USE_STATIC_LIBRARIES) + if(WIN32) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) + else() + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) + endif() + endif() + else() + # external library + set(_HDF5_SEARCH_OPTS_LOCAL) + endif() + find_library(HDF5_${_lang}_LIBRARY_${_lib} + NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR + HINTS ${HDF5_${_lang}_LIBRARY_DIRS} + ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS_LOCAL} + ) + unset(_HDF5_SEARCH_OPTS_LOCAL) + unset(_HDF5_SEARCH_NAMES_LOCAL) + if(HDF5_${_lang}_LIBRARY_${_lib}) + list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) + else() + list(APPEND HDF5_${_lang}_LIBRARIES ${_lib}) + endif() + endforeach() + if(HDF5_FIND_HL) + set(HDF5_${_lang}_HL_LIBRARIES) + foreach(_lib IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) + set(_HDF5_SEARCH_NAMES_LOCAL) + if("x${_lib}" MATCHES "hdf5") + # hdf5 library + set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) + if(HDF5_USE_STATIC_LIBRARIES) + if(WIN32) + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) + else() + set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) + endif() + endif() + else() + # external library + set(_HDF5_SEARCH_OPTS_LOCAL) + endif() + find_library(HDF5_${_lang}_LIBRARY_${_lib} + NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR + HINTS ${HDF5_${_lang}_LIBRARY_DIRS} + ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS_LOCAL} + ) + unset(_HDF5_SEARCH_OPTS_LOCAL) + unset(_HDF5_SEARCH_NAMES_LOCAL) + if(HDF5_${_lang}_LIBRARY_${_lib}) + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) + else() + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${_lib}) + endif() + endforeach() + set(HDF5_HL_FOUND TRUE) + endif() + + set(HDF5_${_lang}_FOUND TRUE) + list(REMOVE_DUPLICATES HDF5_${_lang}_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_${_lang}_INCLUDE_DIRS) + else() + set(_HDF5_NEED_TO_SEARCH TRUE) + endif() + else() + set(_HDF5_NEED_TO_SEARCH TRUE) + endif() + endif() + if(HDF5_${_lang}_VERSION) + if(NOT HDF5_VERSION) + set(HDF5_VERSION ${HDF5_${_lang}_VERSION}) + elseif(NOT HDF5_VERSION VERSION_EQUAL HDF5_${_lang}_VERSION) + message(WARNING "HDF5 Version found for language ${_lang}, ${HDF5_${_lang}_VERSION} is different than previously found version ${HDF5_VERSION}") + endif() + endif() + if(DEFINED HDF5_${_lang}_IS_PARALLEL) + if(NOT DEFINED HDF5_IS_PARALLEL) + set(HDF5_IS_PARALLEL ${HDF5_${_lang}_IS_PARALLEL}) + elseif(NOT HDF5_IS_PARALLEL AND HDF5_${_lang}_IS_PARALLEL) + message(WARNING "HDF5 found for language ${_lang} is parallel but previously found language is not parallel.") + elseif(HDF5_IS_PARALLEL AND NOT HDF5_${_lang}_IS_PARALLEL) + message(WARNING "HDF5 found for language ${_lang} is not parallel but previously found language is parallel.") + endif() + endif() + endforeach() + unset(_HDF5_TEST_DIR) + unset(_HDF5_TEST_SRC) + unset(_lib) +else() + set(_HDF5_NEED_TO_SEARCH TRUE) +endif() + +if(NOT HDF5_FOUND AND HDF5_COMPILER_NO_INTERROGATE) + # No arguments necessary, all languages can use the compiler wrappers + set(HDF5_FOUND TRUE) + set(HDF5_METHOD "Included by compiler wrappers") + set(HDF5_REQUIRED_VARS HDF5_METHOD) +elseif(NOT HDF5_FOUND AND NOT _HDF5_NEED_TO_SEARCH) + # Compiler wrappers aren't being used by the build but were found and used + # to determine necessary include and library flags + set(HDF5_INCLUDE_DIRS) + set(HDF5_LIBRARIES) + set(HDF5_HL_LIBRARIES) + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + if(HDF5_${_lang}_FOUND) + if(NOT HDF5_${_lang}_COMPILER_NO_INTERROGATE) + list(APPEND HDF5_DEFINITIONS ${HDF5_${_lang}_DEFINITIONS}) + list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIRS}) + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) + if(HDF5_FIND_HL) + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) + endif() + endif() + endif() + endforeach() + list(REMOVE_DUPLICATES HDF5_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) + set(HDF5_FOUND TRUE) + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES) + if(HDF5_FIND_HL) + list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) + endif() +endif() + +find_program( HDF5_DIFF_EXECUTABLE + NAMES h5diff + HINTS ${HDF5_ROOT} + PATH_SUFFIXES bin Bin + ${_HDF5_SEARCH_OPTS} + DOC "HDF5 file differencing tool." ) +mark_as_advanced( HDF5_DIFF_EXECUTABLE ) + +if( NOT HDF5_FOUND ) + # seed the initial lists of libraries to find with items we know we need + set(HDF5_C_LIBRARY_NAMES hdf5) + set(HDF5_C_HL_LIBRARY_NAMES hdf5_hl ${HDF5_C_LIBRARY_NAMES} ) + + set(HDF5_CXX_LIBRARY_NAMES hdf5_cpp ${HDF5_C_LIBRARY_NAMES}) + set(HDF5_CXX_HL_LIBRARY_NAMES hdf5_hl_cpp ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_CXX_LIBRARY_NAMES}) + + set(HDF5_Fortran_LIBRARY_NAMES hdf5_fortran ${HDF5_C_LIBRARY_NAMES}) + set(HDF5_Fortran_HL_LIBRARY_NAMES hdf5_hl_fortran hdf5hl_fortran ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_Fortran_LIBRARY_NAMES}) + + # suffixes as seen on Linux, MSYS2, ... + set(_lib_suffixes hdf5) + if(NOT HDF5_PREFER_PARALLEL) + list(APPEND _lib_suffixes hdf5/serial) + endif() + if(HDF5_USE_STATIC_LIBRARIES) + set(_inc_suffixes include/static) + else() + set(_inc_suffixes include/shared) + endif() + + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + set(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_HL_LIBRARIES) + + # The "main" library. + set(_hdf5_main_library "") + + # find the HDF5 libraries + foreach(LIB IN LISTS HDF5_${_lang}_LIBRARY_NAMES) + if(HDF5_USE_STATIC_LIBRARIES) + # According to bug 1643 on the CMake bug tracker, this is the + # preferred method for searching for a static library. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search + # first for the full static library name, but fall back to a + # generic search on the name if the static search fails. + set( THIS_LIBRARY_SEARCH_DEBUG + lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug + lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_D-static ${LIB}_debug-static ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a ${LIB}-static) + else() + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) + set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) + if(WIN32) + list(APPEND HDF5_DEFINITIONS "-DH5_BUILT_AS_DYNAMIC_LIB") + endif() + endif() + find_library(HDF5_${LIB}_LIBRARY_DEBUG + NAMES ${THIS_LIBRARY_SEARCH_DEBUG} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + find_library(HDF5_${LIB}_LIBRARY_RELEASE + NAMES ${THIS_LIBRARY_SEARCH_RELEASE} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + + # Set the "main" library if not already set. + if (NOT _hdf5_main_library) + if (HDF5_${LIB}_LIBRARY_RELEASE) + set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_RELEASE}") + elseif (HDF5_${LIB}_LIBRARY_DEBUG) + set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_DEBUG}") + endif () + endif () + + select_library_configurations( HDF5_${LIB} ) + list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${LIB}_LIBRARY}) + endforeach() + if(HDF5_${_lang}_LIBRARIES) + set(HDF5_${_lang}_FOUND TRUE) + endif() + + # Append the libraries for this language binding to the list of all + # required libraries. + list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) + + # find the HDF5 include directories + set(_hdf5_inc_extra_paths) + set(_hdf5_inc_extra_suffixes) + if("${_lang}" STREQUAL "Fortran") + set(HDF5_INCLUDE_FILENAME hdf5.mod HDF5.mod) + + # Add library-based search paths for Fortran modules. + if (NOT _hdf5_main_library STREQUAL "") + # gfortran module directory + if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "LCC") + get_filename_component(_hdf5_library_dir "${_hdf5_main_library}" DIRECTORY) + list(APPEND _hdf5_inc_extra_paths "${_hdf5_library_dir}") + unset(_hdf5_library_dir) + list(APPEND _hdf5_inc_extra_suffixes gfortran/modules) + endif () + endif () + elseif("${_lang}" STREQUAL "CXX") + set(HDF5_INCLUDE_FILENAME H5Cpp.h) + else() + set(HDF5_INCLUDE_FILENAME hdf5.h) + endif() + + unset(_hdf5_main_library) + + find_path(HDF5_${_lang}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME} + HINTS ${HDF5_ROOT} + PATHS $ENV{HOME}/.local/include ${_hdf5_inc_extra_paths} + PATH_SUFFIXES include Include ${_inc_suffixes} ${_lib_suffixes} ${_hdf5_inc_extra_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + mark_as_advanced(HDF5_${_lang}_INCLUDE_DIR) + unset(_hdf5_inc_extra_paths) + unset(_hdf5_inc_extra_suffixes) + # set the _DIRS variable as this is what the user will normally use + set(HDF5_${_lang}_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) + list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) + + if(HDF5_FIND_HL) + foreach(LIB IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) + if(HDF5_USE_STATIC_LIBRARIES) + # According to bug 1643 on the CMake bug tracker, this is the + # preferred method for searching for a static library. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search + # first for the full static library name, but fall back to a + # generic search on the name if the static search fails. + set( THIS_LIBRARY_SEARCH_DEBUG + lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug + lib${LIB}d-static.a lib${LIB}_debug-static.a lib${LIB}d-static lib${LIB}_D-static lib${LIB}_debug-static ) + set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a lib${LIB}-static) + else() + set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) + set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) + endif() + find_library(HDF5_${LIB}_LIBRARY_DEBUG + NAMES ${THIS_LIBRARY_SEARCH_DEBUG} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + find_library(HDF5_${LIB}_LIBRARY_RELEASE + NAMES ${THIS_LIBRARY_SEARCH_RELEASE} + HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} + ${_HDF5_SEARCH_OPTS} + ) + + select_library_configurations( HDF5_${LIB} ) + list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${LIB}_LIBRARY}) + endforeach() + + # Append the libraries for this language binding to the list of all + # required libraries. + list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) + endif() + endforeach() + if(HDF5_FIND_HL AND HDF5_HL_LIBRARIES) + set(HDF5_HL_FOUND TRUE) + endif() + + list(REMOVE_DUPLICATES HDF5_DEFINITIONS) + list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) + + # If the HDF5 include directory was found, open H5pubconf.h to determine if + # HDF5 was compiled with parallel IO support + set( HDF5_IS_PARALLEL FALSE ) + foreach( _dir IN LISTS HDF5_INCLUDE_DIRS ) + foreach(_hdr "${_dir}/H5pubconf.h" "${_dir}/H5pubconf-64.h" "${_dir}/H5pubconf-32.h") + if( EXISTS "${_hdr}" ) + file( STRINGS "${_hdr}" + HDF5_HAVE_PARALLEL_DEFINE + REGEX "HAVE_PARALLEL 1" ) + if( HDF5_HAVE_PARALLEL_DEFINE ) + set( HDF5_IS_PARALLEL TRUE ) + endif() + unset(HDF5_HAVE_PARALLEL_DEFINE) + + file( STRINGS "${_hdr}" + HDF5_VERSION_DEFINE + REGEX "^[ \t]*#[ \t]*define[ \t]+H5_VERSION[ \t]+" ) + if( "${HDF5_VERSION_DEFINE}" MATCHES + "H5_VERSION[ \t]+\"([0-9\\.]+)(-patch([0-9]+))?\"" ) + set( HDF5_VERSION "${CMAKE_MATCH_1}" ) + if( CMAKE_MATCH_3 ) + set( HDF5_VERSION ${HDF5_VERSION}.${CMAKE_MATCH_3}) + endif() + endif() + unset(HDF5_VERSION_DEFINE) + endif() + endforeach() + endforeach() + unset(_hdr) + unset(_dir) + set( HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL + "HDF5 library compiled with parallel IO support" ) + mark_as_advanced( HDF5_IS_PARALLEL ) + + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS) + if(HDF5_FIND_HL) + list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) + endif() +endif() + +# For backwards compatibility we set HDF5_INCLUDE_DIR to the value of +# HDF5_INCLUDE_DIRS +if( HDF5_INCLUDE_DIRS ) + set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" ) +endif() + +# If HDF5_REQUIRED_VARS is empty at this point, then it's likely that +# something external is trying to explicitly pass already found +# locations +if(NOT HDF5_REQUIRED_VARS) + set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS) +endif() + +find_package_handle_standard_args(HDF5 + REQUIRED_VARS ${HDF5_REQUIRED_VARS} + VERSION_VAR HDF5_VERSION + HANDLE_COMPONENTS +) + +unset(_HDF5_SEARCH_OPTS) + +if( HDF5_FOUND AND NOT HDF5_DIR) + # hide HDF5_DIR for the non-advanced user to avoid confusion with + # HDF5_DIR-NOT_FOUND while HDF5 was found. + mark_as_advanced(HDF5_DIR) +endif() + +if (HDF5_FOUND) + if (NOT TARGET HDF5::HDF5) + add_library(HDF5::HDF5 INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_DEFINITIONS}") + set_target_properties(HDF5::HDF5 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + unset(_hdf5_definitions) + target_link_libraries(HDF5::HDF5 INTERFACE ${HDF5_LIBRARIES}) + endif () + + foreach (hdf5_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + if (hdf5_lang STREQUAL "C") + set(hdf5_target_name "hdf5") + elseif (hdf5_lang STREQUAL "CXX") + set(hdf5_target_name "hdf5_cpp") + elseif (hdf5_lang STREQUAL "Fortran") + set(hdf5_target_name "hdf5_fortran") + else () + continue () + endif () + + if (NOT TARGET "hdf5::${hdf5_target_name}") + if (HDF5_COMPILER_NO_INTERROGATE) + add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + else() + if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_lang}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_lang}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") + else () + # Error if we still don't have the location. + message(SEND_ERROR + "HDF5 was found, but a different variable was set which contains " + "the location of the `hdf5::${hdf5_target_name}` library.") + endif () + add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") + if (NOT HDF5_${hdf5_lang}_INCLUDE_DIRS) + set(HDF5_${hdf5_lang}_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS}) + endif () + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + if (_hdf5_location_release) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}") + endif() + if (_hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}") + endif() + if (NOT _hdf5_location_release AND NOT _hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION "${_hdf5_location}") + endif() + if (_hdf5_libtype STREQUAL "SHARED") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) + elseif (_hdf5_libtype STREQUAL "STATIC") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) + endif () + unset(_hdf5_definitions) + unset(_hdf5_libtype) + unset(_hdf5_location) + unset(_hdf5_location_release) + unset(_hdf5_location_debug) + endif () + endif () + + if (NOT HDF5_FIND_HL) + continue () + endif () + + set(hdf5_alt_target_name "") + if (hdf5_lang STREQUAL "C") + set(hdf5_target_name "hdf5_hl") + elseif (hdf5_lang STREQUAL "CXX") + set(hdf5_target_name "hdf5_hl_cpp") + elseif (hdf5_lang STREQUAL "Fortran") + set(hdf5_target_name "hdf5_hl_fortran") + set(hdf5_alt_target_name "hdf5hl_fortran") + else () + continue () + endif () + + if (NOT TARGET "hdf5::${hdf5_target_name}") + if (HDF5_COMPILER_NO_INTERROGATE) + add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + else() + if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_HL_LIBRARY") + set(_hdf5_location "${HDF5_${hdf5_lang}_HL_LIBRARY}") + set(_hdf5_location_release "${HDF5_${hdf5_lang}_HL_LIBRARY_RELEASE}") + set(_hdf5_location_debug "${HDF5_${hdf5_lang}_HL_LIBRARY_DEBUG}") + elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") + elseif (hdf5_alt_target_name AND DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}") + set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}}") + else () + # Error if we still don't have the location. + message(SEND_ERROR + "HDF5 was found, but a different variable was set which contains " + "the location of the `hdf5::${hdf5_target_name}` library.") + endif () + add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) + string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") + set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") + if (_hdf5_location_release) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}") + endif() + if (_hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}") + endif() + if (NOT _hdf5_location_release AND NOT _hdf5_location_debug) + set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY + IMPORTED_LOCATION "${_hdf5_location}") + endif() + if (_hdf5_libtype STREQUAL "SHARED") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) + elseif (_hdf5_libtype STREQUAL "STATIC") + set_property(TARGET "hdf5::${hdf5_target_name}" APPEND + PROPERTY + INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) + endif () + unset(_hdf5_definitions) + unset(_hdf5_libtype) + unset(_hdf5_location) + endif () + endif () + endforeach () + unset(hdf5_lang) + + if (HDF5_DIFF_EXECUTABLE AND NOT TARGET hdf5::h5diff) + add_executable(hdf5::h5diff IMPORTED) + set_target_properties(hdf5::h5diff PROPERTIES + IMPORTED_LOCATION "${HDF5_DIFF_EXECUTABLE}") + endif () +endif () + +if (HDF5_FIND_DEBUG) + message(STATUS "HDF5_DIR: ${HDF5_DIR}") + message(STATUS "HDF5_DEFINITIONS: ${HDF5_DEFINITIONS}") + message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}") + message(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}") + message(STATUS "HDF5_HL_LIBRARIES: ${HDF5_HL_LIBRARIES}") + foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) + message(STATUS "HDF5_${_lang}_DEFINITIONS: ${HDF5_${_lang}_DEFINITIONS}") + message(STATUS "HDF5_${_lang}_INCLUDE_DIR: ${HDF5_${_lang}_INCLUDE_DIR}") + message(STATUS "HDF5_${_lang}_INCLUDE_DIRS: ${HDF5_${_lang}_INCLUDE_DIRS}") + message(STATUS "HDF5_${_lang}_LIBRARY: ${HDF5_${_lang}_LIBRARY}") + message(STATUS "HDF5_${_lang}_LIBRARIES: ${HDF5_${_lang}_LIBRARIES}") + message(STATUS "HDF5_${_lang}_HL_LIBRARY: ${HDF5_${_lang}_HL_LIBRARY}") + message(STATUS "HDF5_${_lang}_HL_LIBRARIES: ${HDF5_${_lang}_HL_LIBRARIES}") + endforeach() + message(STATUS "Defined targets (if any):") + foreach(_lang IN ITEMS "" "_cpp" "_fortran") + foreach(_hl IN ITEMS "" "_hl") + foreach(_prefix IN ITEMS "hdf5::" "") + foreach(_suffix IN ITEMS "-static" "-shared" "") + set (_target ${_prefix}hdf5${_hl}${_lang}${_suffix}) + if (TARGET ${_target}) + message(STATUS "... ${_target}") + else() + #message(STATUS "... ${_target} does not exist") + endif() + endforeach() + endforeach() + endforeach() + endforeach() +endif() +unset(_lang) +unset(_HDF5_NEED_TO_SEARCH) + +cmake_policy(POP) diff --git a/plugins/decl_netcdf/cmake/4.3/SelectLibraryConfigurations.cmake b/plugins/decl_netcdf/cmake/4.3/SelectLibraryConfigurations.cmake new file mode 100644 index 000000000..5fde66e3e --- /dev/null +++ b/plugins/decl_netcdf/cmake/4.3/SelectLibraryConfigurations.cmake @@ -0,0 +1,187 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file LICENSE.rst or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +SelectLibraryConfigurations +--------------------------- + +This module provides a command to automatically set library variables when +package is available with multiple :ref:`Build Configurations`. It is +intended for use in :ref:`Find Modules` implementing +:command:`find_package()` calls. + +Load this module in a CMake find module with: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + include(SelectLibraryConfigurations) + +Supported build configurations are ``Release`` and ``Debug`` as these are +the most common ones in such packages. + +.. note:: + + This module has been available since early versions of CMake, when the + ``_LIBRARIES`` result variable was used for linking found + packages. When writing standard find modules, :ref:`Imported Targets` should + be preferred. In addition to or as an alternative to this module, imported + targets provide finer control over linking through the + :prop_tgt:`IMPORTED_CONFIGURATIONS` property. + +Commands +^^^^^^^^ + +This module provides the following command: + +.. command:: select_library_configurations + + Sets and adjusts library variables based on debug and release build + configurations: + + .. code-block:: cmake + + select_library_configurations() + + This command is a helper for setting the ``_LIBRARY`` and + ``_LIBRARIES`` result variables when a library might be provided + with multiple build configurations. + + The argument is: + + ```` + The base name of the library, used as a prefix for variable names. This is + the name of the package as used in the ``Find.cmake`` module + filename, or the component name, when find module provides them. + + Prior to calling this command the following cache variables should be set + in the find module (for example, by the :command:`find_library` command): + + ``_LIBRARY_RELEASE`` + A cache variable storing the full path to the ``Release`` build of the + library. If not set or found, this command will set its value to + ``_LIBRARY_RELEASE-NOTFOUND``. + + ``_LIBRARY_DEBUG`` + A cache variable storing the full path to the ``Debug`` build of the + library. If not set or found, this command will set its value to + ``_LIBRARY_DEBUG-NOTFOUND``. + + This command then sets the following local result variables: + + ``_LIBRARY`` + A result variable that is set to the value of + ``_LIBRARY_RELEASE`` variable if found, otherwise it is set to the + value of ``_LIBRARY_DEBUG`` variable if found. If both are found, + the release library value takes precedence. If both are not found, it is set + to value ``_LIBRARY-NOTFOUND``. + + If the :manual:`CMake Generator ` in use supports + build configurations, then this variable will be a list of found libraries + each prepended with the ``optimized`` or ``debug`` keywords specifying which + library should be linked for the given configuration. These keywords are + used by the :command:`target_link_libraries` command. If a build + configuration has not been set or the generator in use does not support + build configurations, then this variable value will not contain these + keywords. + + ``_LIBRARIES`` + A result variable that is set to the same value as the + ``_LIBRARY`` variable. + + .. note:: + + The ``select_library_configurations()`` command should be called before + handling standard find module arguments with + :command:`find_package_handle_standard_args` to ensure that the + ``_FOUND`` result variable is correctly set based on + ``_LIBRARY`` or other related variables. + +Examples +^^^^^^^^ + +Setting library variables based on the build configuration inside a find module +file: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + # Find release and debug build of the library + find_library(Foo_LIBRARY_RELEASE ...) + find_library(Foo_LIBRARY_DEBUG ...) + + # Set Foo_LIBRARY and Foo_LIBRARIES result variables + include(SelectLibraryConfigurations) + select_library_configurations(Foo) + + # Set Foo_FOUND variable and print result message. + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( + Foo + REQUIRED_VARS Foo_LIBRARY ... + ) + +When find module provides components with multiple build configurations: + +.. code-block:: cmake + :caption: ``FindFoo.cmake`` + + include(SelectLibraryConfigurations) + foreach(component IN LISTS Foo_FIND_COMPONENTS) + # ... + select_library_configurations(Foo_${component}) + # ... + endforeach() + +A project can then use this find module as follows: + +.. code-block:: cmake + :caption: ``CMakeLists.txt`` + + find_package(Foo) + target_link_libraries(project_target PRIVATE ${Foo_LIBRARIES}) + # ... +#]=======================================================================] + +# This macro was adapted from the FindQt4 CMake module and is maintained by Will +# Dicharry . + +macro(select_library_configurations basename) + if(NOT ${basename}_LIBRARY_RELEASE) + set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + if(NOT ${basename}_LIBRARY_DEBUG) + set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.") + endif() + + get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND + NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND + ( _isMultiConfig OR CMAKE_BUILD_TYPE ) ) + # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for + # single-config generators, set optimized and debug libraries + set( ${basename}_LIBRARY "" ) + foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE ) + list( APPEND ${basename}_LIBRARY optimized "${_libname}" ) + endforeach() + foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG ) + list( APPEND ${basename}_LIBRARY debug "${_libname}" ) + endforeach() + elseif( ${basename}_LIBRARY_RELEASE ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} ) + elseif( ${basename}_LIBRARY_DEBUG ) + set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} ) + else() + set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND") + endif() + + set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" ) + + if( ${basename}_LIBRARY ) + set( ${basename}_FOUND TRUE ) + endif() + + mark_as_advanced( ${basename}_LIBRARY_RELEASE + ${basename}_LIBRARY_DEBUG + ) +endmacro() diff --git a/plugins/decl_netcdf/cmake/FindNetCDF.cmake b/plugins/decl_netcdf/cmake/FindNetCDF.cmake index b1465e884..0cdd109d5 100644 --- a/plugins/decl_netcdf/cmake/FindNetCDF.cmake +++ b/plugins/decl_netcdf/cmake/FindNetCDF.cmake @@ -369,7 +369,7 @@ if("${NetCDF_FOUND}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT ("${HDF5_PROVIDES_PARALLEL}" OR "${HDF5_IS_PARALLEL}")) + if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT "${HDF5_IS_PARALLEL}") message(ERROR "Parallel HDF5 required by NetCDF, sequential HDF5 only found.") endif() list(APPEND NetCDF_LINK_LIBRARIES hdf5::hdf5) From 1dcb3c27a123d1c8b438ee160fdcd643344b16fa Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 14:29:17 +0200 Subject: [PATCH 16/59] Typo [skip ci] --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c411f9b04..325750102 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,13 +109,13 @@ if("${BUILD_DECL_NETCDF_PLUGIN}") if(4.1 VERSION_GREATER "${CMAKE_VERSION}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake/4.1") elseif(4.3 VERSION_GREATER "${CMAKE_VERSION}") - # Workaround conpiling with HDF5-2.0.0+ + # Workaround compiling with HDF5-2.0.0+ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake/4.3") endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake") endif() if("${BUILD_DECL_HDF5_PLUGIN}") - # Workaround conpiling with HDF5-2.0.0+ + # Workaround compiling with HDF5-2.0.0+ if(4.3 VERSION_GREATER "${CMAKE_VERSION}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake/4.3") endif() From b01bb1bb3b778a98f2c48847a7451ddbccbb7126 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 14:17:13 +0200 Subject: [PATCH 17/59] Add version checks for HDF5 in CMakeLists.txt --- plugins/decl_hdf5/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 3b3045c2d..970eba144 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -51,6 +51,7 @@ find_package(HDF5 REQUIRED COMPONENTS C) if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() + if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "Parallel HDF5 required, sequential HDF5 only found. Please set -DBUILD_HDF5_PARALLEL=OFF to disable parallel HDF5") endif() From bd034c887ee5fd1ed08f3b185c2b92a1bd67f6de Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 14:36:56 +0200 Subject: [PATCH 18/59] Remove redundant CMAKE_MODULE_PATH entry --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 325750102..dce86827e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,6 @@ if("${BUILD_DECL_HDF5_PLUGIN}") if(4.3 VERSION_GREATER "${CMAKE_VERSION}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake/4.3") endif() - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake") endif() set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" CACHE STRING "" FORCE) From 106bfbfe92a9646d9588f9a5a88f5731422a7c8a Mon Sep 17 00:00:00 2001 From: yushan wang Date: Wed, 15 Apr 2026 11:52:36 +0200 Subject: [PATCH 19/59] remove 4.1 cmake patch --- plugins/decl_hdf5/CMakeLists.txt | 4 + plugins/decl_netcdf/CMakeLists.txt | 5 +- plugins/decl_netcdf/cmake/4.1/FindHDF5.cmake | 1415 ----------------- .../4.1/SelectLibraryConfigurations.cmake | 185 --- 4 files changed, 5 insertions(+), 1604 deletions(-) delete mode 100644 plugins/decl_netcdf/cmake/4.1/FindHDF5.cmake delete mode 100644 plugins/decl_netcdf/cmake/4.1/SelectLibraryConfigurations.cmake diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 970eba144..75fdeb09d 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -31,6 +31,10 @@ cmake_minimum_required(VERSION 3.22...4.2) project(pdi_decl_hdf5_plugin LANGUAGES C CXX) +if(4.3 VERSION_GREATER "${CMAKE_VERSION}") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake/4.3") +endif() + option(BUILD_BENCHMARKING "Build PDI benchmarks" ON) option(BUILD_FORTRAN "Enable Fortran support" ON) option(BUILD_HDF5_PARALLEL "Enable HDF5 parallel build" ON) diff --git a/plugins/decl_netcdf/CMakeLists.txt b/plugins/decl_netcdf/CMakeLists.txt index b3c973139..89aad2a47 100644 --- a/plugins/decl_netcdf/CMakeLists.txt +++ b/plugins/decl_netcdf/CMakeLists.txt @@ -31,10 +31,7 @@ cmake_minimum_required(VERSION 3.22...4.2) project(pdi_decl_netcdf_plugin LANGUAGES C CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") -if("${CMAKE_VERSION}" VERSION_LESS 4.1) - # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 - list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/4.1") -elseif("${CMAKE_VERSION}" VERSION_LESS 4.3) +if("${CMAKE_VERSION}" VERSION_LESS 4.3) # Workaround for compiling with HDF5-2.0.0+ list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/4.3") endif() diff --git a/plugins/decl_netcdf/cmake/4.1/FindHDF5.cmake b/plugins/decl_netcdf/cmake/4.1/FindHDF5.cmake deleted file mode 100644 index 958b29496..000000000 --- a/plugins/decl_netcdf/cmake/4.1/FindHDF5.cmake +++ /dev/null @@ -1,1415 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file LICENSE.rst or https://cmake.org/licensing for details. - -#[=======================================================================[.rst: -FindHDF5 --------- - -Finds Hierarchical Data Format (HDF5), a library for reading and writing -self-describing array data: - -.. code-block:: cmake - - find_package(HDF5 [] ... [COMPONENTS ...] ...) - -If the HDF5 library is built using its CMake-based build system, it will as -of HDF5 version 1.8.15 provide its own CMake Package Configuration file -(``hdf5-config.cmake``) for use with the :command:`find_package` command in -*config mode*. By default, this module searches for this file and, if found, -returns the results based on the found configuration. - -If the upstream configuration file is not found, this module falls back to -*module mode* and invokes the HDF5 wrapper compiler typically installed -with the HDF5 library. Depending on the configuration, this wrapper -compiler is named either ``h5cc`` (serial) or ``h5pcc`` (parallel). If -found, the wrapper is queried with the ``-show`` argument to determine the -compiler and linker flags required for building an HDF5 client application. -Both serial and parallel versions of the HDF5 wrapper are considered. The -first directory containing either is used. If both versions are found in the -same directory, the serial version is preferred by default. To change this -behavior, set the variable ``HDF5_PREFER_PARALLEL`` to ``TRUE``. - -In addition to finding the include directories and libraries needed to compile -an HDF5 application, this module also attempts to find additional tools -provided by the HDF5 distribution, which can be useful for regression testing -or development workflows. - -Components -^^^^^^^^^^ - -This module supports optional components, which can be specified with the -:command:`find_package` command: - -.. code-block:: cmake - - find_package(HDF5 [COMPONENTS ...]) - -Supported components include: - -``C`` - Finds the ``HDF5`` C library (C bindings). - -``CXX`` - Finds the ``HDF5`` C++ library (C++ bindings). - -``Fortran`` - Finds the ``HDF5`` Fortran library (Fortran bindings). - -``HL`` - This component can be used in combination with other components to find the - high-level (HL) HDF5 library variants for C, CXX, and/or Fortran, which - provide high-level functions. - -If no components are specified, then this module will by default search for the -``C`` component. - -Imported Targets -^^^^^^^^^^^^^^^^ - -This module provides the following :ref:`Imported Targets`: - -``HDF5::HDF5`` - .. versionadded:: 3.19 - - Target encapsulating the usage requirements for all found HDF5 libraries - (``HDF5_LIBRARIES``), available if HDF5 and all required components are found. - -``hdf5::hdf5`` - .. versionadded:: 3.19 - - Target encapsulating the usage requirements for the HDF5 C library, available - if HDF5 library and its ``C`` component are found. - -``hdf5::hdf5_cpp`` - .. versionadded:: 3.19 - - Target encapsulating the usage requirements for the HDF5 C and C++ libraries, - available if HDF5 library, and its ``C`` and ``CXX`` components are found. - -``hdf5::hdf5_fortran`` - .. versionadded:: 3.19 - - Target encapsulating the usage requirements for the HDF5 Fortran library, - available if HDF5 library and its ``Fortran`` component are found. - -``hdf5::hdf5_hl`` - .. versionadded:: 3.19 - - Target encapsulating the usage requirements for the HDF5 high-level C library, - available if HDF5 library and its ``C``, and ``HL`` components are found. - -``hdf5::hdf5_hl_cpp`` - .. versionadded:: 3.19 - - High-level C++ library. - - Target encapsulating the usage requirements for the HDF5 high-level C and - high-level C++ libraries, available if HDF5 library and its ``C``, ``CXX``, - and ``HL`` components are found. - -``hdf5::hdf5_hl_fortran`` - .. versionadded:: 3.19 - - Target encapsulating the usage requirements for the HDF5 high-level Fortran - library, available if HDF5 library and its ``Fortran``, and ``HL`` components - are found. - -``hdf5::h5diff`` - .. versionadded:: 3.19 - - Imported executable target encapsulating the usage requirements for the - ``h5diff`` executable, available if ``h5diff`` is found. - -Result Variables -^^^^^^^^^^^^^^^^ - -This module defines the following variables: - -``HDF5_FOUND`` - Boolean indicating whether (the requested version of) HDF5 is found. - -``HDF5_VERSION`` - .. versionadded:: 3.3 - - The version of HDF5 library found. - -``HDF5_INCLUDE_DIRS`` - Include directories containing header files needed to use HDF5. - -``HDF5_DEFINITIONS`` - Required compiler definitions for using HDF5. - -``HDF5_LIBRARIES`` - Libraries of all requested bindings needed to link against to use HDF5. - -``HDF5_HL_LIBRARIES`` - Required libraries for the HDF5 high-level API for all bindings, - if the ``HL`` component is enabled. - -``HDF5_IS_PARALLEL`` - Boolean indicating whether the HDF5 library has parallel IO support. - -For each enabled language binding component, a corresponding -``HDF5__LIBRARIES`` variable, and potentially -``HDF5__DEFINITIONS``, will be defined. If the ``HL`` component is -enabled, then ``HDF5__HL_LIBRARIES`` variables will also be defined: - -``HDF5_C_DEFINITIONS`` - Required compiler definitions for HDF5 C bindings. - -``HDF5_CXX_DEFINITIONS`` - Required compiler definitions for HDF5 C++ bindings. - -``HDF5_Fortran_DEFINITIONS`` - Required compiler definitions for HDF5 Fortran bindings. - -``HDF5_C_INCLUDE_DIRS`` - Required include directories for HDF5 C bindings. - -``HDF5_CXX_INCLUDE_DIRS`` - Required include directories for HDF5 C++ bindings. - -``HDF5_Fortran_INCLUDE_DIRS`` - Required include directories for HDF5 Fortran bindings. - -``HDF5_C_LIBRARIES`` - Required libraries for the HDF5 C bindings. - -``HDF5_CXX_LIBRARIES`` - Required libraries for the HDF5 C++ bindings. - -``HDF5_Fortran_LIBRARIES`` - Required libraries for the HDF5 Fortran bindings. - -``HDF5_C_HL_LIBRARIES`` - Required libraries for the high-level C bindings, if the ``HL`` component - is enabled. - -``HDF5_CXX_HL_LIBRARIES`` - Required libraries for the high-level C++ bindings, if the ``HL`` - component is enabled. - -``HDF5_Fortran_HL_LIBRARIES`` - Required libraries for the high-level Fortran bindings, if the ``HL`` - component is enabled. - -Cache Variables -^^^^^^^^^^^^^^^ - -The following cache variables may also be set: - -``HDF5_C_COMPILER_EXECUTABLE`` - The path to the HDF5 C wrapper compiler. - -``HDF5_CXX_COMPILER_EXECUTABLE`` - The path to the HDF5 C++ wrapper compiler. - -``HDF5_Fortran_COMPILER_EXECUTABLE`` - The path to the HDF5 Fortran wrapper compiler. - -``HDF5_C_COMPILER_EXECUTABLE_NO_INTERROGATE`` - .. versionadded:: 3.6 - - The path to the primary C compiler which is also the HDF5 wrapper. - This variable is used only in *module mode*. - -``HDF5_CXX_COMPILER_EXECUTABLE_NO_INTERROGATE`` - .. versionadded:: 3.6 - - The path to the primary C++ compiler which is also the HDF5 wrapper. - This variable is used only in *module mode*. - -``HDF5_Fortran_COMPILER_EXECUTABLE_NO_INTERROGATE`` - .. versionadded:: 3.6 - - The path to the primary Fortran compiler which is also the HDF5 wrapper. - This variable is used only in *module mode*. - -``HDF5_DIFF_EXECUTABLE`` - The path to the HDF5 dataset comparison tool (``h5diff``). - -Hints -^^^^^ - -The following variables can be set before calling the ``find_package(HDF5)`` -to guide the search for HDF5 library: - -``HDF5_PREFER_PARALLEL`` - .. versionadded:: 3.4 - - Set this to boolean true to prefer parallel HDF5 (by default, serial is - preferred). This variable is used only in *module mode*. - -``HDF5_FIND_DEBUG`` - .. versionadded:: 3.9 - - Set this to boolean true to get extra debugging output by this module. - -``HDF5_NO_FIND_PACKAGE_CONFIG_FILE`` - .. versionadded:: 3.8 - - Set this to boolean true to skip finding and using CMake package configuration - file (``hdf5-config.cmake``). - -``HDF5_USE_STATIC_LIBRARIES`` - Set this to boolean value to determine whether or not to prefer a - static link to a dynamic link for ``HDF5`` and all of its dependencies. - - .. versionadded:: 3.10 - Support for ``HDF5_USE_STATIC_LIBRARIES`` on Windows. - -Examples -^^^^^^^^ - -Examples: Finding HDF5 -"""""""""""""""""""""" - -Finding HDF5: - -.. code-block:: cmake - - find_package(HDF5) - -Specifying a minimum required version of HDF5 to find: - -.. code-block:: cmake - - find_package(HDF5 1.8.15) - -Finding HDF5 and making it required (if HDF5 is not found, processing stops with -an error message): - -.. code-block:: cmake - - find_package(HDF5 1.8.15 REQUIRED) - -Searching for static HDF5 libraries: - -.. code-block:: cmake - - set(HDF5_USE_STATIC_LIBRARIES TRUE) - find_package(HDF5) - -Specifying components to find high-level C and C++ functions: - -.. code-block:: cmake - - find_package(HDF5 COMPONENTS C CXX HL) - -Examples: Using HDF5 -"""""""""""""""""""" - -Finding HDF5 and linking it to a project target: - -.. code-block:: cmake - - find_package(HDF5) - target_link_libraries(project_target PRIVATE HDF5::HDF5) - -Using Fortran HDF5 and HDF5-HL functions: - -.. code-block:: cmake - - find_package(HDF5 COMPONENTS Fortran HL) - target_link_libraries(project_target PRIVATE HDF5::HDF5) -#]=======================================================================] - -include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) -include(FindPackageHandleStandardArgs) - -cmake_policy(PUSH) -if(POLICY CMP0159) - cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_ -endif() - -# We haven't found HDF5 yet. Clear its state in case it is set in the parent -# scope somewhere else. We can't rely on it because different components may -# have been requested for this call. -set(HDF5_FOUND OFF) -set(HDF5_LIBRARIES) -set(HDF5_HL_LIBRARIES) - -# List of the valid HDF5 components -set(HDF5_VALID_LANGUAGE_BINDINGS C CXX Fortran) - -# Validate the list of find components. -if(NOT HDF5_FIND_COMPONENTS) - set(HDF5_LANGUAGE_BINDINGS "C") -else() - set(HDF5_LANGUAGE_BINDINGS) - # add the extra specified components, ensuring that they are valid. - set(HDF5_FIND_HL OFF) - foreach(_component IN LISTS HDF5_FIND_COMPONENTS) - list(FIND HDF5_VALID_LANGUAGE_BINDINGS ${_component} _component_location) - if(NOT _component_location EQUAL -1) - list(APPEND HDF5_LANGUAGE_BINDINGS ${_component}) - elseif(_component STREQUAL "HL") - set(HDF5_FIND_HL ON) - elseif(_component STREQUAL "Fortran_HL") # only for compatibility - list(APPEND HDF5_LANGUAGE_BINDINGS Fortran) - set(HDF5_FIND_HL ON) - set(HDF5_FIND_REQUIRED_Fortran_HL FALSE) - set(HDF5_FIND_REQUIRED_Fortran TRUE) - set(HDF5_FIND_REQUIRED_HL TRUE) - else() - message(FATAL_ERROR "${_component} is not a valid HDF5 component.") - endif() - endforeach() - unset(_component) - unset(_component_location) - if(NOT HDF5_LANGUAGE_BINDINGS) - get_property(_langs GLOBAL PROPERTY ENABLED_LANGUAGES) - foreach(_lang IN LISTS _langs) - if(_lang MATCHES "^(C|CXX|Fortran)$") - list(APPEND HDF5_LANGUAGE_BINDINGS ${_lang}) - endif() - endforeach() - endif() - list(REMOVE_ITEM HDF5_FIND_COMPONENTS Fortran_HL) # replaced by Fortran and HL - list(REMOVE_DUPLICATES HDF5_LANGUAGE_BINDINGS) -endif() - -# Determine whether to search for serial or parallel executable first -if(HDF5_PREFER_PARALLEL) - set(HDF5_C_COMPILER_NAMES h5pcc h5cc) - set(HDF5_CXX_COMPILER_NAMES h5pc++ h5c++) - set(HDF5_Fortran_COMPILER_NAMES h5pfc h5fc) -else() - set(HDF5_C_COMPILER_NAMES h5cc h5pcc) - set(HDF5_CXX_COMPILER_NAMES h5c++ h5pc++) - set(HDF5_Fortran_COMPILER_NAMES h5fc h5pfc) -endif() - -# Prefer h5hl compilers if HDF5_FIND_HL is enabled -if(HDF5_FIND_HL) - list(PREPEND HDF5_C_COMPILER_NAMES h5hlcc) - list(PREPEND HDF5_CXX_COMPILER_NAMES h5hlc++) - list(PREPEND HDF5_Fortran_COMPILER_NAMES h5hlfc) -endif() - -# Test first if the current compilers automatically wrap HDF5 -function(_HDF5_test_regular_compiler_C success version is_parallel) - if(NOT ${success} OR - NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c) - file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" - "#include \n" - "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" - "#ifdef H5_HAVE_PARALLEL\n" - "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" - "#endif\n" - "int main(int argc, char **argv) {\n" - " int require = 0;\n" - " require += info_ver[argc];\n" - "#ifdef H5_HAVE_PARALLEL\n" - " require += info_parallel[argc];\n" - "#endif\n" - " hid_t fid;\n" - " fid = H5Fcreate(\"foo.h5\",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);\n" - " return 0;\n" - "}") - try_compile(${success} "${_HDF5_TEST_DIR}" "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" - COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_c - ) - endif() - if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c) - file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_c INFO_STRINGS - REGEX "^INFO:" - ) - string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" - INFO_VER "${INFO_STRINGS}" - ) - set(${version} ${CMAKE_MATCH_1}) - if(CMAKE_MATCH_3) - set(${version} ${HDF5_C_VERSION}.${CMAKE_MATCH_3}) - endif() - set(${version} ${${version}} PARENT_SCOPE) - - if(INFO_STRINGS MATCHES "INFO:PARALLEL") - set(${is_parallel} TRUE PARENT_SCOPE) - else() - set(${is_parallel} FALSE PARENT_SCOPE) - endif() - endif() -endfunction() - -function(_HDF5_test_regular_compiler_CXX success version is_parallel) - if(NOT ${success} OR - NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx) - file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" - "#include \n" - "#ifndef H5_NO_NAMESPACE\n" - "using namespace H5;\n" - "#endif\n" - "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n" - "#ifdef H5_HAVE_PARALLEL\n" - "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n" - "#endif\n" - "int main(int argc, char **argv) {\n" - " int require = 0;\n" - " require += info_ver[argc];\n" - "#ifdef H5_HAVE_PARALLEL\n" - " require += info_parallel[argc];\n" - "#endif\n" - " H5File file(\"foo.h5\", H5F_ACC_TRUNC);\n" - " return 0;\n" - "}") - try_compile(${success} "${_HDF5_TEST_DIR}" "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" - COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_cxx - ) - endif() - if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx) - file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx INFO_STRINGS - REGEX "^INFO:" - ) - string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?" - INFO_VER "${INFO_STRINGS}" - ) - set(${version} ${CMAKE_MATCH_1}) - if(CMAKE_MATCH_3) - set(${version} ${HDF5_CXX_VERSION}.${CMAKE_MATCH_3}) - endif() - set(${version} ${${version}} PARENT_SCOPE) - - if(INFO_STRINGS MATCHES "INFO:PARALLEL") - set(${is_parallel} TRUE PARENT_SCOPE) - else() - set(${is_parallel} FALSE PARENT_SCOPE) - endif() - endif() -endfunction() - -function(_HDF5_test_regular_compiler_Fortran success is_parallel) - if(NOT ${success}) - file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" - "program hdf5_hello\n" - " use hdf5\n" - " integer error\n" - " call h5open_f(error)\n" - " call h5close_f(error)\n" - "end\n") - try_compile(${success} "${_HDF5_TEST_DIR}" "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}") - if(${success}) - execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -showconfig - OUTPUT_VARIABLE config_output - ERROR_VARIABLE config_error - RESULT_VARIABLE config_result - ) - if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)") - # The value may be anything used when HDF5 was configured, - # so see if CMake interprets it as "true". - set(parallelHDF5 "${CMAKE_MATCH_1}") - if(parallelHDF5) - set(${is_parallel} TRUE PARENT_SCOPE) - else() - set(${is_parallel} FALSE PARENT_SCOPE) - endif() - else() - set(${is_parallel} FALSE PARENT_SCOPE) - endif() - endif() - endif() -endfunction() - -# Invoke the HDF5 wrapper compiler. The compiler return value is stored to the -# return_value argument, the text output is stored to the output variable. -function( _HDF5_invoke_compiler language output_var return_value_var version_var is_parallel_var) - set(is_parallel FALSE) - if(HDF5_USE_STATIC_LIBRARIES) - set(lib_type_args -noshlib) - else() - set(lib_type_args -shlib) - endif() - # Verify that the compiler wrapper can actually compile: sometimes the compiler - # wrapper exists, but not the compiler. E.g. Miniconda / Anaconda Python - execute_process( - COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} "${_HDF5_TEST_SRC}" - WORKING_DIRECTORY ${_HDF5_TEST_DIR} - OUTPUT_VARIABLE output - ERROR_VARIABLE output - RESULT_VARIABLE return_value - ) - if(NOT return_value EQUAL 0) - message(CONFIGURE_LOG - "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.\n\n${output}") - if(NOT HDF5_FIND_QUIETLY) - message(STATUS - "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.") - endif() - else() - execute_process( - COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -show ${lib_type_args} "${_HDF5_TEST_SRC}" - WORKING_DIRECTORY ${_HDF5_TEST_DIR} - OUTPUT_VARIABLE output - ERROR_VARIABLE output - RESULT_VARIABLE return_value - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(NOT return_value EQUAL 0) - message(CONFIGURE_LOG - "Unable to determine HDF5 ${language} flags from HDF5 wrapper.\n\n${output}") - if(NOT HDF5_FIND_QUIETLY) - message(STATUS - "Unable to determine HDF5 ${language} flags from HDF5 wrapper.") - endif() - endif() - execute_process( - COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -showconfig - OUTPUT_VARIABLE config_output - ERROR_VARIABLE config_output - RESULT_VARIABLE return_value - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(NOT return_value EQUAL 0) - message(CONFIGURE_LOG - "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.\n\n${output}") - if(NOT HDF5_FIND_QUIETLY) - message(STATUS - "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.") - endif() - endif() - string(REGEX MATCH "HDF5 Version: ([a-zA-Z0-9\\.\\-]*)" version "${config_output}") - if(version) - string(REPLACE "HDF5 Version: " "" version "${version}") - string(REPLACE "-patch" "." version "${version}") - endif() - if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)") - # The value may be anything used when HDF5 was configured, - # so see if CMake interprets it as "true". - set(parallelHDF5 "${CMAKE_MATCH_1}") - if(parallelHDF5) - set(is_parallel TRUE) - endif() - endif() - endif() - foreach(var output return_value version is_parallel) - set(${${var}_var} ${${var}} PARENT_SCOPE) - endforeach() -endfunction() - -# Parse a compile line for definitions, includes, library paths, and libraries. -function(_HDF5_parse_compile_line compile_line_var include_paths definitions - library_paths libraries libraries_hl) - - separate_arguments(_compile_args NATIVE_COMMAND "${${compile_line_var}}") - - foreach(_arg IN LISTS _compile_args) - if("${_arg}" MATCHES "^-I(.*)$") - # include directory - list(APPEND include_paths "${CMAKE_MATCH_1}") - elseif("${_arg}" MATCHES "^-D(.*)$") - # compile definition - list(APPEND definitions "-D${CMAKE_MATCH_1}") - elseif("${_arg}" MATCHES "^-L(.*)$") - # library search path - list(APPEND library_paths "${CMAKE_MATCH_1}") - elseif("${_arg}" MATCHES "^-l(hdf5.*hl.*)$") - # library name (hl) - list(APPEND libraries_hl "${CMAKE_MATCH_1}") - elseif("${_arg}" MATCHES "^-l(.*)$") - # library name - list(APPEND libraries "${CMAKE_MATCH_1}") - elseif("${_arg}" MATCHES "^(.:)?[/\\].*\\.(a|so|dylib|sl|lib)$") - # library file - if(NOT EXISTS "${_arg}") - continue() - endif() - get_filename_component(_lpath "${_arg}" DIRECTORY) - get_filename_component(_lname "${_arg}" NAME_WE) - string(REGEX REPLACE "^lib" "" _lname "${_lname}") - list(APPEND library_paths "${_lpath}") - if(_lname MATCHES "hdf5.*hl") - list(APPEND libraries_hl "${_lname}") - else() - list(APPEND libraries "${_lname}") - endif() - endif() - endforeach() - foreach(var include_paths definitions library_paths libraries libraries_hl) - set(${${var}_var} ${${var}} PARENT_SCOPE) - endforeach() -endfunction() - -# Select a preferred imported configuration from a target -function(_HDF5_select_imported_config target imported_conf) - # We will first assign the value to a local variable _imported_conf, then assign - # it to the function argument at the end. - get_target_property(_imported_conf ${target} MAP_IMPORTED_CONFIG_${CMAKE_BUILD_TYPE}) - if (NOT _imported_conf) - # Get available imported configurations by examining target properties - get_target_property(_imported_conf ${target} IMPORTED_CONFIGURATIONS) - if(HDF5_FIND_DEBUG) - message(STATUS "Found imported configurations: ${_imported_conf}") - endif() - # Find the imported configuration that we prefer. - # We do this by making list of configurations in order of preference, - # starting with ${CMAKE_BUILD_TYPE} and ending with the first imported_conf - set(_preferred_confs ${CMAKE_BUILD_TYPE}) - list(GET _imported_conf 0 _fallback_conf) - list(APPEND _preferred_confs RELWITHDEBINFO RELEASE DEBUG ${_fallback_conf}) - if(HDF5_FIND_DEBUG) - message(STATUS "Start search through imported configurations in the following order: ${_preferred_confs}") - endif() - # Now find the first of these that is present in imported_conf - foreach (_conf IN LISTS _preferred_confs) - if (${_conf} IN_LIST _imported_conf) - set(_imported_conf ${_conf}) - break() - endif() - endforeach() - endif() - if(HDF5_FIND_DEBUG) - message(STATUS "Selected imported configuration: ${_imported_conf}") - endif() - # assign value to function argument - set(${imported_conf} ${_imported_conf} PARENT_SCOPE) -endfunction() - - -if(NOT HDF5_ROOT) - set(HDF5_ROOT $ENV{HDF5_ROOT}) -endif() -if(HDF5_ROOT) - set(_HDF5_SEARCH_OPTS NO_DEFAULT_PATH) -else() - set(_HDF5_SEARCH_OPTS) -endif() - -# Try to find HDF5 using an installed hdf5-config.cmake -if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE) - find_package(HDF5 QUIET NO_MODULE - HINTS ${HDF5_ROOT} - ${_HDF5_SEARCH_OPTS} - ) - if( HDF5_FOUND) - if(HDF5_FIND_DEBUG) - message(STATUS "Found HDF5 at ${HDF5_DIR} via NO_MODULE. Now trying to extract locations etc.") - endif() - set(HDF5_IS_PARALLEL ${HDF5_ENABLE_PARALLEL}) - set(HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR}) - set(HDF5_LIBRARIES) - if (NOT TARGET hdf5 AND NOT TARGET hdf5-static AND NOT TARGET hdf5-shared) - # Some HDF5 versions (e.g. 1.8.18) used hdf5::hdf5 etc - set(_target_prefix "hdf5::") - endif() - set(HDF5_C_TARGET ${_target_prefix}hdf5) - set(HDF5_C_HL_TARGET ${_target_prefix}hdf5_hl) - set(HDF5_CXX_TARGET ${_target_prefix}hdf5_cpp) - set(HDF5_CXX_HL_TARGET ${_target_prefix}hdf5_hl_cpp) - set(HDF5_Fortran_TARGET ${_target_prefix}hdf5_fortran) - set(HDF5_Fortran_HL_TARGET ${_target_prefix}hdf5_hl_fortran) - set(HDF5_DEFINITIONS "") - if(HDF5_USE_STATIC_LIBRARIES) - set(_suffix "-static") - else() - set(_suffix "-shared") - endif() - foreach(_lang ${HDF5_LANGUAGE_BINDINGS}) - - #Older versions of hdf5 don't have a static/shared suffix so - #if we detect that occurrence clear the suffix - if(_suffix AND NOT TARGET ${HDF5_${_lang}_TARGET}${_suffix}) - if(NOT TARGET ${HDF5_${_lang}_TARGET}) - #can't find this component with or without the suffix - #so bail out, and let the following locate HDF5 - set(HDF5_FOUND FALSE) - break() - endif() - set(_suffix "") - endif() - - if(HDF5_FIND_DEBUG) - message(STATUS "Trying to get properties of target ${HDF5_${_lang}_TARGET}${_suffix}") - endif() - # Find library for this target. Complicated as on Windows with a DLL, we need to search for the import-lib. - _HDF5_select_imported_config(${HDF5_${_lang}_TARGET}${_suffix} _hdf5_imported_conf) - get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) - if (NOT _hdf5_lang_location) - # no import lib, just try LOCATION - get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) - if (NOT _hdf5_lang_location) - get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION) - endif() - endif() - if( _hdf5_lang_location ) - set(HDF5_${_lang}_LIBRARY ${_hdf5_lang_location}) - list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) - set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix}) - set(HDF5_${_lang}_FOUND TRUE) - endif() - if(HDF5_FIND_HL) - get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} ) - if (NOT _hdf5_lang_hl_location) - get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf}) - if (NOT _hdf5_hl_lang_location) - get_target_property(_hdf5_hl_lang_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION) - endif() - endif() - if( _hdf5_lang_hl_location ) - set(HDF5_${_lang}_HL_LIBRARY ${_hdf5_lang_hl_location}) - list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) - set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix}) - set(HDF5_HL_FOUND TRUE) - endif() - unset(_hdf5_lang_hl_location) - endif() - unset(_hdf5_imported_conf) - unset(_hdf5_lang_location) - endforeach() - endif() -endif() - -if(NOT HDF5_FOUND) - set(_HDF5_NEED_TO_SEARCH FALSE) - set(_HDF5_TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5) - set(HDF5_COMPILER_NO_INTERROGATE TRUE) - # Only search for languages we've enabled - foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) - set(HDF5_${_lang}_LIBRARIES) - set(HDF5_${_lang}_HL_LIBRARIES) - - # First check to see if our regular compiler is one of wrappers - if(_lang STREQUAL "C") - set(_HDF5_TEST_SRC cmake_hdf5_test.c) - if(CMAKE_CXX_COMPILER_LOADED AND NOT CMAKE_C_COMPILER_LOADED) - # CXX project without C enabled - set(_HDF5_TEST_SRC cmake_hdf5_test.cxx) - endif() - _HDF5_test_regular_compiler_C( - HDF5_${_lang}_COMPILER_NO_INTERROGATE - HDF5_${_lang}_VERSION - HDF5_${_lang}_IS_PARALLEL) - elseif(_lang STREQUAL "CXX") - set(_HDF5_TEST_SRC cmake_hdf5_test.cxx) - _HDF5_test_regular_compiler_CXX( - HDF5_${_lang}_COMPILER_NO_INTERROGATE - HDF5_${_lang}_VERSION - HDF5_${_lang}_IS_PARALLEL) - elseif(_lang STREQUAL "Fortran") - set(_HDF5_TEST_SRC cmake_hdf5_test.f90) - _HDF5_test_regular_compiler_Fortran( - HDF5_${_lang}_COMPILER_NO_INTERROGATE - HDF5_${_lang}_IS_PARALLEL) - else() - continue() - endif() - if(HDF5_${_lang}_COMPILER_NO_INTERROGATE) - if(HDF5_FIND_DEBUG) - message(STATUS "HDF5: Using hdf5 compiler wrapper for all ${_lang} compiling") - endif() - set(HDF5_${_lang}_FOUND TRUE) - set(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE - "${CMAKE_${_lang}_COMPILER}" - CACHE FILEPATH "HDF5 ${_lang} compiler wrapper") - set(HDF5_${_lang}_DEFINITIONS) - set(HDF5_${_lang}_INCLUDE_DIRS) - set(HDF5_${_lang}_LIBRARIES) - set(HDF5_${_lang}_HL_LIBRARIES) - - mark_as_advanced(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE) - - set(HDF5_${_lang}_FOUND TRUE) - set(HDF5_HL_FOUND TRUE) - else() - set(HDF5_COMPILER_NO_INTERROGATE FALSE) - # If this language isn't using the wrapper, then try to seed the - # search options with the wrapper - find_program(HDF5_${_lang}_COMPILER_EXECUTABLE - NAMES ${HDF5_${_lang}_COMPILER_NAMES} NAMES_PER_DIR - HINTS ${HDF5_ROOT} - PATH_SUFFIXES bin Bin - DOC "HDF5 ${_lang} Wrapper compiler. Used only to detect HDF5 compile flags." - ${_HDF5_SEARCH_OPTS} - ) - mark_as_advanced( HDF5_${_lang}_COMPILER_EXECUTABLE ) - unset(HDF5_${_lang}_COMPILER_NAMES) - - if(HDF5_${_lang}_COMPILER_EXECUTABLE) - _HDF5_invoke_compiler(${_lang} HDF5_${_lang}_COMPILE_LINE - HDF5_${_lang}_RETURN_VALUE HDF5_${_lang}_VERSION HDF5_${_lang}_IS_PARALLEL) - if(HDF5_${_lang}_RETURN_VALUE EQUAL 0) - if(HDF5_FIND_DEBUG) - message(STATUS "HDF5: Using hdf5 compiler wrapper to determine ${_lang} configuration") - endif() - _HDF5_parse_compile_line( HDF5_${_lang}_COMPILE_LINE - HDF5_${_lang}_INCLUDE_DIRS - HDF5_${_lang}_DEFINITIONS - HDF5_${_lang}_LIBRARY_DIRS - HDF5_${_lang}_LIBRARY_NAMES - HDF5_${_lang}_HL_LIBRARY_NAMES - ) - set(HDF5_${_lang}_LIBRARIES) - - foreach(_lib IN LISTS HDF5_${_lang}_LIBRARY_NAMES) - set(_HDF5_SEARCH_NAMES_LOCAL) - if("x${_lib}" MATCHES "hdf5") - # hdf5 library - set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) - if(HDF5_USE_STATIC_LIBRARIES) - if(WIN32) - set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) - else() - set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) - endif() - endif() - else() - # external library - set(_HDF5_SEARCH_OPTS_LOCAL) - endif() - find_library(HDF5_${_lang}_LIBRARY_${_lib} - NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR - HINTS ${HDF5_${_lang}_LIBRARY_DIRS} - ${HDF5_ROOT} - ${_HDF5_SEARCH_OPTS_LOCAL} - ) - unset(_HDF5_SEARCH_OPTS_LOCAL) - unset(_HDF5_SEARCH_NAMES_LOCAL) - if(HDF5_${_lang}_LIBRARY_${_lib}) - list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) - else() - list(APPEND HDF5_${_lang}_LIBRARIES ${_lib}) - endif() - endforeach() - if(HDF5_FIND_HL) - set(HDF5_${_lang}_HL_LIBRARIES) - foreach(_lib IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) - set(_HDF5_SEARCH_NAMES_LOCAL) - if("x${_lib}" MATCHES "hdf5") - # hdf5 library - set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) - if(HDF5_USE_STATIC_LIBRARIES) - if(WIN32) - set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}) - else() - set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a) - endif() - endif() - else() - # external library - set(_HDF5_SEARCH_OPTS_LOCAL) - endif() - find_library(HDF5_${_lang}_LIBRARY_${_lib} - NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR - HINTS ${HDF5_${_lang}_LIBRARY_DIRS} - ${HDF5_ROOT} - ${_HDF5_SEARCH_OPTS_LOCAL} - ) - unset(_HDF5_SEARCH_OPTS_LOCAL) - unset(_HDF5_SEARCH_NAMES_LOCAL) - if(HDF5_${_lang}_LIBRARY_${_lib}) - list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}}) - else() - list(APPEND HDF5_${_lang}_HL_LIBRARIES ${_lib}) - endif() - endforeach() - set(HDF5_HL_FOUND TRUE) - endif() - - set(HDF5_${_lang}_FOUND TRUE) - list(REMOVE_DUPLICATES HDF5_${_lang}_DEFINITIONS) - list(REMOVE_DUPLICATES HDF5_${_lang}_INCLUDE_DIRS) - else() - set(_HDF5_NEED_TO_SEARCH TRUE) - endif() - else() - set(_HDF5_NEED_TO_SEARCH TRUE) - endif() - endif() - if(HDF5_${_lang}_VERSION) - if(NOT HDF5_VERSION) - set(HDF5_VERSION ${HDF5_${_lang}_VERSION}) - elseif(NOT HDF5_VERSION VERSION_EQUAL HDF5_${_lang}_VERSION) - message(WARNING "HDF5 Version found for language ${_lang}, ${HDF5_${_lang}_VERSION} is different than previously found version ${HDF5_VERSION}") - endif() - endif() - if(DEFINED HDF5_${_lang}_IS_PARALLEL) - if(NOT DEFINED HDF5_IS_PARALLEL) - set(HDF5_IS_PARALLEL ${HDF5_${_lang}_IS_PARALLEL}) - elseif(NOT HDF5_IS_PARALLEL AND HDF5_${_lang}_IS_PARALLEL) - message(WARNING "HDF5 found for language ${_lang} is parallel but previously found language is not parallel.") - elseif(HDF5_IS_PARALLEL AND NOT HDF5_${_lang}_IS_PARALLEL) - message(WARNING "HDF5 found for language ${_lang} is not parallel but previously found language is parallel.") - endif() - endif() - endforeach() - unset(_HDF5_TEST_DIR) - unset(_HDF5_TEST_SRC) - unset(_lib) -else() - set(_HDF5_NEED_TO_SEARCH TRUE) -endif() - -if(NOT HDF5_FOUND AND HDF5_COMPILER_NO_INTERROGATE) - # No arguments necessary, all languages can use the compiler wrappers - set(HDF5_FOUND TRUE) - set(HDF5_METHOD "Included by compiler wrappers") - set(HDF5_REQUIRED_VARS HDF5_METHOD) -elseif(NOT HDF5_FOUND AND NOT _HDF5_NEED_TO_SEARCH) - # Compiler wrappers aren't being used by the build but were found and used - # to determine necessary include and library flags - set(HDF5_INCLUDE_DIRS) - set(HDF5_LIBRARIES) - set(HDF5_HL_LIBRARIES) - foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) - if(HDF5_${_lang}_FOUND) - if(NOT HDF5_${_lang}_COMPILER_NO_INTERROGATE) - list(APPEND HDF5_DEFINITIONS ${HDF5_${_lang}_DEFINITIONS}) - list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIRS}) - list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) - if(HDF5_FIND_HL) - list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) - endif() - endif() - endif() - endforeach() - list(REMOVE_DUPLICATES HDF5_DEFINITIONS) - list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) - set(HDF5_FOUND TRUE) - set(HDF5_REQUIRED_VARS HDF5_LIBRARIES) - if(HDF5_FIND_HL) - list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) - endif() -endif() - -find_program( HDF5_DIFF_EXECUTABLE - NAMES h5diff - HINTS ${HDF5_ROOT} - PATH_SUFFIXES bin Bin - ${_HDF5_SEARCH_OPTS} - DOC "HDF5 file differencing tool." ) -mark_as_advanced( HDF5_DIFF_EXECUTABLE ) - -if( NOT HDF5_FOUND ) - # seed the initial lists of libraries to find with items we know we need - set(HDF5_C_LIBRARY_NAMES hdf5) - set(HDF5_C_HL_LIBRARY_NAMES hdf5_hl ${HDF5_C_LIBRARY_NAMES} ) - - set(HDF5_CXX_LIBRARY_NAMES hdf5_cpp ${HDF5_C_LIBRARY_NAMES}) - set(HDF5_CXX_HL_LIBRARY_NAMES hdf5_hl_cpp ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_CXX_LIBRARY_NAMES}) - - set(HDF5_Fortran_LIBRARY_NAMES hdf5_fortran ${HDF5_C_LIBRARY_NAMES}) - set(HDF5_Fortran_HL_LIBRARY_NAMES hdf5_hl_fortran hdf5hl_fortran ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_Fortran_LIBRARY_NAMES}) - - # suffixes as seen on Linux, MSYS2, ... - set(_lib_suffixes hdf5) - if(NOT HDF5_PREFER_PARALLEL) - list(APPEND _lib_suffixes hdf5/serial) - endif() - if(HDF5_USE_STATIC_LIBRARIES) - set(_inc_suffixes include/static) - else() - set(_inc_suffixes include/shared) - endif() - - foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) - set(HDF5_${_lang}_LIBRARIES) - set(HDF5_${_lang}_HL_LIBRARIES) - - # The "main" library. - set(_hdf5_main_library "") - - # find the HDF5 libraries - foreach(LIB IN LISTS HDF5_${_lang}_LIBRARY_NAMES) - if(HDF5_USE_STATIC_LIBRARIES) - # According to bug 1643 on the CMake bug tracker, this is the - # preferred method for searching for a static library. - # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search - # first for the full static library name, but fall back to a - # generic search on the name if the static search fails. - set( THIS_LIBRARY_SEARCH_DEBUG - lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug - lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_D-static ${LIB}_debug-static ) - set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a ${LIB}-static) - else() - set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) - set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) - if(WIN32) - list(APPEND HDF5_DEFINITIONS "-DH5_BUILT_AS_DYNAMIC_LIB") - endif() - endif() - find_library(HDF5_${LIB}_LIBRARY_DEBUG - NAMES ${THIS_LIBRARY_SEARCH_DEBUG} - HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} - ${_HDF5_SEARCH_OPTS} - ) - find_library(HDF5_${LIB}_LIBRARY_RELEASE - NAMES ${THIS_LIBRARY_SEARCH_RELEASE} - HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} - ${_HDF5_SEARCH_OPTS} - ) - - # Set the "main" library if not already set. - if (NOT _hdf5_main_library) - if (HDF5_${LIB}_LIBRARY_RELEASE) - set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_RELEASE}") - elseif (HDF5_${LIB}_LIBRARY_DEBUG) - set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_DEBUG}") - endif () - endif () - - select_library_configurations( HDF5_${LIB} ) - list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${LIB}_LIBRARY}) - endforeach() - if(HDF5_${_lang}_LIBRARIES) - set(HDF5_${_lang}_FOUND TRUE) - endif() - - # Append the libraries for this language binding to the list of all - # required libraries. - list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES}) - - # find the HDF5 include directories - set(_hdf5_inc_extra_paths) - set(_hdf5_inc_extra_suffixes) - if("${_lang}" STREQUAL "Fortran") - set(HDF5_INCLUDE_FILENAME hdf5.mod HDF5.mod) - - # Add library-based search paths for Fortran modules. - if (NOT _hdf5_main_library STREQUAL "") - # gfortran module directory - if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "LCC") - get_filename_component(_hdf5_library_dir "${_hdf5_main_library}" DIRECTORY) - list(APPEND _hdf5_inc_extra_paths "${_hdf5_library_dir}") - unset(_hdf5_library_dir) - list(APPEND _hdf5_inc_extra_suffixes gfortran/modules) - endif () - endif () - elseif("${_lang}" STREQUAL "CXX") - set(HDF5_INCLUDE_FILENAME H5Cpp.h) - else() - set(HDF5_INCLUDE_FILENAME hdf5.h) - endif() - - unset(_hdf5_main_library) - - find_path(HDF5_${_lang}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME} - HINTS ${HDF5_ROOT} - PATHS $ENV{HOME}/.local/include ${_hdf5_inc_extra_paths} - PATH_SUFFIXES include Include ${_inc_suffixes} ${_lib_suffixes} ${_hdf5_inc_extra_suffixes} - ${_HDF5_SEARCH_OPTS} - ) - mark_as_advanced(HDF5_${_lang}_INCLUDE_DIR) - unset(_hdf5_inc_extra_paths) - unset(_hdf5_inc_extra_suffixes) - # set the _DIRS variable as this is what the user will normally use - set(HDF5_${_lang}_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) - list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR}) - - if(HDF5_FIND_HL) - foreach(LIB IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES) - if(HDF5_USE_STATIC_LIBRARIES) - # According to bug 1643 on the CMake bug tracker, this is the - # preferred method for searching for a static library. - # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643. We search - # first for the full static library name, but fall back to a - # generic search on the name if the static search fails. - set( THIS_LIBRARY_SEARCH_DEBUG - lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug - lib${LIB}d-static.a lib${LIB}_debug-static.a lib${LIB}d-static lib${LIB}_D-static lib${LIB}_debug-static ) - set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a lib${LIB}-static) - else() - set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared) - set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared) - endif() - find_library(HDF5_${LIB}_LIBRARY_DEBUG - NAMES ${THIS_LIBRARY_SEARCH_DEBUG} - HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} - ${_HDF5_SEARCH_OPTS} - ) - find_library(HDF5_${LIB}_LIBRARY_RELEASE - NAMES ${THIS_LIBRARY_SEARCH_RELEASE} - HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes} - ${_HDF5_SEARCH_OPTS} - ) - - select_library_configurations( HDF5_${LIB} ) - list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${LIB}_LIBRARY}) - endforeach() - - # Append the libraries for this language binding to the list of all - # required libraries. - list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES}) - endif() - endforeach() - if(HDF5_FIND_HL AND HDF5_HL_LIBRARIES) - set(HDF5_HL_FOUND TRUE) - endif() - - list(REMOVE_DUPLICATES HDF5_DEFINITIONS) - list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS) - - # If the HDF5 include directory was found, open H5pubconf.h to determine if - # HDF5 was compiled with parallel IO support - set( HDF5_IS_PARALLEL FALSE ) - foreach( _dir IN LISTS HDF5_INCLUDE_DIRS ) - foreach(_hdr "${_dir}/H5pubconf.h" "${_dir}/H5pubconf-64.h" "${_dir}/H5pubconf-32.h") - if( EXISTS "${_hdr}" ) - file( STRINGS "${_hdr}" - HDF5_HAVE_PARALLEL_DEFINE - REGEX "HAVE_PARALLEL 1" ) - if( HDF5_HAVE_PARALLEL_DEFINE ) - set( HDF5_IS_PARALLEL TRUE ) - endif() - unset(HDF5_HAVE_PARALLEL_DEFINE) - - file( STRINGS "${_hdr}" - HDF5_VERSION_DEFINE - REGEX "^[ \t]*#[ \t]*define[ \t]+H5_VERSION[ \t]+" ) - if( "${HDF5_VERSION_DEFINE}" MATCHES - "H5_VERSION[ \t]+\"([0-9\\.]+)(-patch([0-9]+))?\"" ) - set( HDF5_VERSION "${CMAKE_MATCH_1}" ) - if( CMAKE_MATCH_3 ) - set( HDF5_VERSION ${HDF5_VERSION}.${CMAKE_MATCH_3}) - endif() - endif() - unset(HDF5_VERSION_DEFINE) - endif() - endforeach() - endforeach() - unset(_hdr) - unset(_dir) - set( HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL - "HDF5 library compiled with parallel IO support" ) - mark_as_advanced( HDF5_IS_PARALLEL ) - - set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS) - if(HDF5_FIND_HL) - list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES) - endif() -endif() - -# For backwards compatibility we set HDF5_INCLUDE_DIR to the value of -# HDF5_INCLUDE_DIRS -if( HDF5_INCLUDE_DIRS ) - set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" ) -endif() - -# If HDF5_REQUIRED_VARS is empty at this point, then it's likely that -# something external is trying to explicitly pass already found -# locations -if(NOT HDF5_REQUIRED_VARS) - set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS) -endif() - -find_package_handle_standard_args(HDF5 - REQUIRED_VARS ${HDF5_REQUIRED_VARS} - VERSION_VAR HDF5_VERSION - HANDLE_COMPONENTS -) - -unset(_HDF5_SEARCH_OPTS) - -if( HDF5_FOUND AND NOT HDF5_DIR) - # hide HDF5_DIR for the non-advanced user to avoid confusion with - # HDF5_DIR-NOT_FOUND while HDF5 was found. - mark_as_advanced(HDF5_DIR) -endif() - -if (HDF5_FOUND) - if (NOT TARGET HDF5::HDF5) - add_library(HDF5::HDF5 INTERFACE IMPORTED) - string(REPLACE "-D" "" _hdf5_definitions "${HDF5_DEFINITIONS}") - set_target_properties(HDF5::HDF5 PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS}" - INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") - unset(_hdf5_definitions) - target_link_libraries(HDF5::HDF5 INTERFACE ${HDF5_LIBRARIES}) - endif () - - foreach (hdf5_lang IN LISTS HDF5_LANGUAGE_BINDINGS) - if (hdf5_lang STREQUAL "C") - set(hdf5_target_name "hdf5") - elseif (hdf5_lang STREQUAL "CXX") - set(hdf5_target_name "hdf5_cpp") - elseif (hdf5_lang STREQUAL "Fortran") - set(hdf5_target_name "hdf5_fortran") - else () - continue () - endif () - - if (NOT TARGET "hdf5::${hdf5_target_name}") - if (HDF5_COMPILER_NO_INTERROGATE) - add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) - string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") - set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" - INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") - else() - if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") - set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") - set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}") - set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}") - elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY") - set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY}") - set(_hdf5_location_release "${HDF5_${hdf5_lang}_LIBRARY_RELEASE}") - set(_hdf5_location_debug "${HDF5_${hdf5_lang}_LIBRARY_DEBUG}") - elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") - set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") - else () - # Error if we still don't have the location. - message(SEND_ERROR - "HDF5 was found, but a different variable was set which contains " - "the location of the `hdf5::${hdf5_target_name}` library.") - endif () - add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) - string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}") - if (NOT HDF5_${hdf5_lang}_INCLUDE_DIRS) - set(HDF5_${hdf5_lang}_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS}) - endif () - set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}" - INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") - if (_hdf5_location_release) - set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY - IMPORTED_CONFIGURATIONS RELEASE) - set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY - IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}") - endif() - if (_hdf5_location_debug) - set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY - IMPORTED_CONFIGURATIONS DEBUG) - set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY - IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}") - endif() - if (NOT _hdf5_location_release AND NOT _hdf5_location_debug) - set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY - IMPORTED_LOCATION "${_hdf5_location}") - endif() - if (_hdf5_libtype STREQUAL "SHARED") - set_property(TARGET "hdf5::${hdf5_target_name}" APPEND - PROPERTY - INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) - elseif (_hdf5_libtype STREQUAL "STATIC") - set_property(TARGET "hdf5::${hdf5_target_name}" APPEND - PROPERTY - INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) - endif () - unset(_hdf5_definitions) - unset(_hdf5_libtype) - unset(_hdf5_location) - unset(_hdf5_location_release) - unset(_hdf5_location_debug) - endif () - endif () - - if (NOT HDF5_FIND_HL) - continue () - endif () - - set(hdf5_alt_target_name "") - if (hdf5_lang STREQUAL "C") - set(hdf5_target_name "hdf5_hl") - elseif (hdf5_lang STREQUAL "CXX") - set(hdf5_target_name "hdf5_hl_cpp") - elseif (hdf5_lang STREQUAL "Fortran") - set(hdf5_target_name "hdf5_hl_fortran") - set(hdf5_alt_target_name "hdf5hl_fortran") - else () - continue () - endif () - - if (NOT TARGET "hdf5::${hdf5_target_name}") - if (HDF5_COMPILER_NO_INTERROGATE) - add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED) - string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") - set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" - INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") - else() - if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY") - set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}") - set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}") - set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}") - elseif (DEFINED "HDF5_${hdf5_lang}_HL_LIBRARY") - set(_hdf5_location "${HDF5_${hdf5_lang}_HL_LIBRARY}") - set(_hdf5_location_release "${HDF5_${hdf5_lang}_HL_LIBRARY_RELEASE}") - set(_hdf5_location_debug "${HDF5_${hdf5_lang}_HL_LIBRARY_DEBUG}") - elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}") - set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}") - elseif (hdf5_alt_target_name AND DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}") - set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}}") - else () - # Error if we still don't have the location. - message(SEND_ERROR - "HDF5 was found, but a different variable was set which contains " - "the location of the `hdf5::${hdf5_target_name}` library.") - endif () - add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED) - string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}") - set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}" - INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}") - if (_hdf5_location_release) - set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY - IMPORTED_CONFIGURATIONS RELEASE) - set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY - IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}") - endif() - if (_hdf5_location_debug) - set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY - IMPORTED_CONFIGURATIONS DEBUG) - set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY - IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}") - endif() - if (NOT _hdf5_location_release AND NOT _hdf5_location_debug) - set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY - IMPORTED_LOCATION "${_hdf5_location}") - endif() - if (_hdf5_libtype STREQUAL "SHARED") - set_property(TARGET "hdf5::${hdf5_target_name}" APPEND - PROPERTY - INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB) - elseif (_hdf5_libtype STREQUAL "STATIC") - set_property(TARGET "hdf5::${hdf5_target_name}" APPEND - PROPERTY - INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB) - endif () - unset(_hdf5_definitions) - unset(_hdf5_libtype) - unset(_hdf5_location) - endif () - endif () - endforeach () - unset(hdf5_lang) - - if (HDF5_DIFF_EXECUTABLE AND NOT TARGET hdf5::h5diff) - add_executable(hdf5::h5diff IMPORTED) - set_target_properties(hdf5::h5diff PROPERTIES - IMPORTED_LOCATION "${HDF5_DIFF_EXECUTABLE}") - endif () -endif () - -if (HDF5_FIND_DEBUG) - message(STATUS "HDF5_DIR: ${HDF5_DIR}") - message(STATUS "HDF5_DEFINITIONS: ${HDF5_DEFINITIONS}") - message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}") - message(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}") - message(STATUS "HDF5_HL_LIBRARIES: ${HDF5_HL_LIBRARIES}") - foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS) - message(STATUS "HDF5_${_lang}_DEFINITIONS: ${HDF5_${_lang}_DEFINITIONS}") - message(STATUS "HDF5_${_lang}_INCLUDE_DIR: ${HDF5_${_lang}_INCLUDE_DIR}") - message(STATUS "HDF5_${_lang}_INCLUDE_DIRS: ${HDF5_${_lang}_INCLUDE_DIRS}") - message(STATUS "HDF5_${_lang}_LIBRARY: ${HDF5_${_lang}_LIBRARY}") - message(STATUS "HDF5_${_lang}_LIBRARIES: ${HDF5_${_lang}_LIBRARIES}") - message(STATUS "HDF5_${_lang}_HL_LIBRARY: ${HDF5_${_lang}_HL_LIBRARY}") - message(STATUS "HDF5_${_lang}_HL_LIBRARIES: ${HDF5_${_lang}_HL_LIBRARIES}") - endforeach() - message(STATUS "Defined targets (if any):") - foreach(_lang IN ITEMS "" "_cpp" "_fortran") - foreach(_hl IN ITEMS "" "_hl") - foreach(_prefix IN ITEMS "hdf5::" "") - foreach(_suffix IN ITEMS "-static" "-shared" "") - set (_target ${_prefix}hdf5${_hl}${_lang}${_suffix}) - if (TARGET ${_target}) - message(STATUS "... ${_target}") - else() - #message(STATUS "... ${_target} does not exist") - endif() - endforeach() - endforeach() - endforeach() - endforeach() -endif() -unset(_lang) -unset(_HDF5_NEED_TO_SEARCH) - -cmake_policy(POP) diff --git a/plugins/decl_netcdf/cmake/4.1/SelectLibraryConfigurations.cmake b/plugins/decl_netcdf/cmake/4.1/SelectLibraryConfigurations.cmake deleted file mode 100644 index e26c9080a..000000000 --- a/plugins/decl_netcdf/cmake/4.1/SelectLibraryConfigurations.cmake +++ /dev/null @@ -1,185 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file LICENSE.rst or https://cmake.org/licensing for details. - -#[=======================================================================[.rst: -SelectLibraryConfigurations ---------------------------- - -This module is intended for use in :ref:`Find Modules` and provides a -command to automatically set library variables when package is available -with multiple :ref:`Build Configurations`. - -Load it in a CMake find module with: - -.. code-block:: cmake - - include(SelectLibraryConfigurations) - -Supported build configurations are ``Release`` and ``Debug`` as these are -the most common ones in such packages. - -.. note:: - - This module has been available since early versions of CMake, when the - ``_LIBRARIES`` result variable was used for linking found - packages. When writing standard find modules, :ref:`Imported Targets` should - be preferred. In addition to or as an alternative to this module, imported - targets provide finer control over linking through the - :prop_tgt:`IMPORTED_CONFIGURATIONS` property. - -Commands -^^^^^^^^ - -This module provides the following command: - -.. command:: select_library_configurations - - Sets and adjusts library variables based on debug and release build - configurations: - - .. code-block:: cmake - - select_library_configurations() - - This command is a helper for setting the ``_LIBRARY`` and - ``_LIBRARIES`` result variables when a library might be provided - with multiple build configurations. - - The argument is: - - ```` - The base name of the library, used as a prefix for variable names. This is - the name of the package as used in the ``Find.cmake`` module - filename, or the component name, when find module provides them. - - Prior to calling this command the following cache variables should be set - in the find module (for example, by the :command:`find_library` command): - - ``_LIBRARY_RELEASE`` - A cache variable storing the full path to the ``Release`` build of the - library. If not set or found, this command will set its value to - ``_LIBRARY_RELEASE-NOTFOUND``. - - ``_LIBRARY_DEBUG`` - A cache variable storing the full path to the ``Debug`` build of the - library. If not set or found, this command will set its value to - ``_LIBRARY_DEBUG-NOTFOUND``. - - This command then sets the following local result variables: - - ``_LIBRARY`` - A result variable that is set to the value of - ``_LIBRARY_RELEASE`` variable if found, otherwise it is set to the - value of ``_LIBRARY_DEBUG`` variable if found. If both are found, - the release library value takes precedence. If both are not found, it is set - to value ``_LIBRARY-NOTFOUND``. - - If the :manual:`CMake Generator ` in use supports - build configurations, then this variable will be a list of found libraries - each prepended with the ``optimized`` or ``debug`` keywords specifying which - library should be linked for the given configuration. These keywords are - used by the :command:`target_link_libraries` command. If a build - configuration has not been set or the generator in use does not support - build configurations, then this variable value will not contain these - keywords. - - ``_LIBRARIES`` - A result variable that is set to the same value as the - ``_LIBRARY`` variable. - - .. note:: - - The ``select_library_configurations()`` command should be called before - handling standard find module arguments with - :command:`find_package_handle_standard_args` to ensure that the - ``_FOUND`` result variable is correctly set based on - ``_LIBRARY`` or other related variables. - -Examples -^^^^^^^^ - -Setting library variables based on the build configuration inside a find module -file: - -.. code-block:: cmake - :caption: ``FindFoo.cmake`` - - # Find release and debug build of the library - find_library(Foo_LIBRARY_RELEASE ...) - find_library(Foo_LIBRARY_DEBUG ...) - - # Set Foo_LIBRARY and Foo_LIBRARIES result variables - include(SelectLibraryConfigurations) - select_library_configurations(Foo) - - # Set Foo_FOUND variable and print result message. - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args( - Foo - REQUIRED_VARS Foo_LIBRARY ... - ) - -When find module provides components with multiple build configurations: - -.. code-block:: cmake - :caption: ``FindFoo.cmake`` - - include(SelectLibraryConfigurations) - foreach(component IN LISTS Foo_FIND_COMPONENTS) - # ... - select_library_configurations(Foo_${component}) - # ... - endforeach() - -A project can then use this find module as follows: - -.. code-block:: cmake - :caption: ``CMakeLists.txt`` - - find_package(Foo) - target_link_libraries(project_target PRIVATE ${Foo_LIBRARIES}) - # ... -#]=======================================================================] - -# This macro was adapted from the FindQt4 CMake module and is maintained by Will -# Dicharry . - -macro(select_library_configurations basename) - if(NOT ${basename}_LIBRARY_RELEASE) - set(${basename}_LIBRARY_RELEASE "${basename}_LIBRARY_RELEASE-NOTFOUND" CACHE FILEPATH "Path to a library.") - endif() - if(NOT ${basename}_LIBRARY_DEBUG) - set(${basename}_LIBRARY_DEBUG "${basename}_LIBRARY_DEBUG-NOTFOUND" CACHE FILEPATH "Path to a library.") - endif() - - get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) - if( ${basename}_LIBRARY_DEBUG AND ${basename}_LIBRARY_RELEASE AND - NOT ${basename}_LIBRARY_DEBUG STREQUAL ${basename}_LIBRARY_RELEASE AND - ( _isMultiConfig OR CMAKE_BUILD_TYPE ) ) - # if the generator is multi-config or if CMAKE_BUILD_TYPE is set for - # single-config generators, set optimized and debug libraries - set( ${basename}_LIBRARY "" ) - foreach( _libname IN LISTS ${basename}_LIBRARY_RELEASE ) - list( APPEND ${basename}_LIBRARY optimized "${_libname}" ) - endforeach() - foreach( _libname IN LISTS ${basename}_LIBRARY_DEBUG ) - list( APPEND ${basename}_LIBRARY debug "${_libname}" ) - endforeach() - elseif( ${basename}_LIBRARY_RELEASE ) - set( ${basename}_LIBRARY ${${basename}_LIBRARY_RELEASE} ) - elseif( ${basename}_LIBRARY_DEBUG ) - set( ${basename}_LIBRARY ${${basename}_LIBRARY_DEBUG} ) - else() - set( ${basename}_LIBRARY "${basename}_LIBRARY-NOTFOUND") - endif() - - set( ${basename}_LIBRARIES "${${basename}_LIBRARY}" ) - - if( ${basename}_LIBRARY ) - set( ${basename}_FOUND TRUE ) - endif() - - mark_as_advanced( ${basename}_LIBRARY_RELEASE - ${basename}_LIBRARY_DEBUG - ) -endmacro() From eeab5c1fd6a79e3c89e0f9fb3407b2b417c71002 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Wed, 15 Apr 2026 12:03:12 +0200 Subject: [PATCH 20/59] Update CMakeLists.txt Co-authored-by: Julien Bigot --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14e7726be..04e7d48b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,8 +112,8 @@ if("${BUILD_DECL_NETCDF_PLUGIN}") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake") endif() if("${BUILD_DECL_HDF5_PLUGIN}") - # Workaround compiling with HDF5-2.0.0+ if(4.3 VERSION_GREATER "${CMAKE_VERSION}") + # Workaround compiling with HDF5-2.0.0+ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake/4.3") endif() endif() From 6a339091af893a4196eddfbcd8874f81ab9a1bc9 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Wed, 15 Apr 2026 12:04:12 +0200 Subject: [PATCH 21/59] Update plugins/decl_hdf5/CMakeLists.txt Co-authored-by: Julien Bigot --- plugins/decl_hdf5/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 75fdeb09d..4cd4edb3f 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -32,6 +32,7 @@ cmake_minimum_required(VERSION 3.22...4.2) project(pdi_decl_hdf5_plugin LANGUAGES C CXX) if(4.3 VERSION_GREATER "${CMAKE_VERSION}") + # Workaround for compiling with HDF5-2.0.0+ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake/4.3") endif() From 7ac00587c8d6f812fb3fa69f207e19685cf21749 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Wed, 15 Apr 2026 12:05:29 +0200 Subject: [PATCH 22/59] Update plugins/decl_netcdf/CMakeLists.txt Co-authored-by: Julien Bigot --- plugins/decl_netcdf/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/decl_netcdf/CMakeLists.txt b/plugins/decl_netcdf/CMakeLists.txt index 89aad2a47..50aaa9768 100644 --- a/plugins/decl_netcdf/CMakeLists.txt +++ b/plugins/decl_netcdf/CMakeLists.txt @@ -31,9 +31,9 @@ cmake_minimum_required(VERSION 3.22...4.2) project(pdi_decl_netcdf_plugin LANGUAGES C CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") -if("${CMAKE_VERSION}" VERSION_LESS 4.3) +if(4.3 VERSION_GREATER "${CMAKE_VERSION}") # Workaround for compiling with HDF5-2.0.0+ - list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/4.3") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/4.3") endif() option(BUILD_NETCDF_PARALLEL "Build Decl'NetCDF in parallel mode" ON) From ff9f88b23993f0e5b198aef4021de6cb364d4e6d Mon Sep 17 00:00:00 2001 From: Julien Bigot Date: Wed, 15 Apr 2026 12:07:44 +0200 Subject: [PATCH 23/59] Apply suggestions from code review Co-authored-by: Julien Bigot --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04e7d48b2..0cad14f32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,14 +107,14 @@ list(APPEND CMAKE_MODULE_PATH if("${BUILD_DECL_NETCDF_PLUGIN}") if(4.3 VERSION_GREATER "${CMAKE_VERSION}") # Workaround compiling with HDF5-2.0.0+ - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake/4.3") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/plugins/decl_netcdf/cmake/4.3") endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake") endif() if("${BUILD_DECL_HDF5_PLUGIN}") if(4.3 VERSION_GREATER "${CMAKE_VERSION}") # Workaround compiling with HDF5-2.0.0+ - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake/4.3") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/plugins/decl_hdf5/cmake/4.3") endif() endif() set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" CACHE STRING "" FORCE) From 73cd0fca080e5216bb91219eb47b3fdea5dd7fec Mon Sep 17 00:00:00 2001 From: Julien Bigot Date: Wed, 15 Apr 2026 12:08:21 +0200 Subject: [PATCH 24/59] Apply suggestion from @jbigot --- plugins/decl_hdf5/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 4cd4edb3f..80375631c 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -33,7 +33,7 @@ project(pdi_decl_hdf5_plugin LANGUAGES C CXX) if(4.3 VERSION_GREATER "${CMAKE_VERSION}") # Workaround for compiling with HDF5-2.0.0+ - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_hdf5/cmake/4.3") + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/4.3") endif() option(BUILD_BENCHMARKING "Build PDI benchmarks" ON) From 8678b69ce1e591800a8090d398d3840a8c7a34da Mon Sep 17 00:00:00 2001 From: Julien Bigot Date: Wed, 15 Apr 2026 12:10:53 +0200 Subject: [PATCH 25/59] Apply suggestions from code review Co-authored-by: Julien Bigot --- CMakeLists.txt | 6 ++++-- plugins/decl_hdf5/CMakeLists.txt | 3 ++- plugins/decl_netcdf/CMakeLists.txt | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cad14f32..c48d1f878 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,14 +106,16 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pdi/cmake") if("${BUILD_DECL_NETCDF_PLUGIN}") if(4.3 VERSION_GREATER "${CMAKE_VERSION}") - # Workaround compiling with HDF5-2.0.0+ + # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 + # Workaround for missing HDF5_IS_PARALLEL with HDF5-2.0.0+ in cmake pre-4.3 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/plugins/decl_netcdf/cmake/4.3") endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake") endif() if("${BUILD_DECL_HDF5_PLUGIN}") if(4.3 VERSION_GREATER "${CMAKE_VERSION}") - # Workaround compiling with HDF5-2.0.0+ + # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 + # Workaround for missing HDF5_IS_PARALLEL with HDF5-2.0.0+ in cmake pre-4.3 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/plugins/decl_hdf5/cmake/4.3") endif() endif() diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index 80375631c..0b5d1b523 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -32,7 +32,8 @@ cmake_minimum_required(VERSION 3.22...4.2) project(pdi_decl_hdf5_plugin LANGUAGES C CXX) if(4.3 VERSION_GREATER "${CMAKE_VERSION}") - # Workaround for compiling with HDF5-2.0.0+ + # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 + # Workaround for missing HDF5_IS_PARALLEL with HDF5-2.0.0+ in cmake pre-4.3 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/4.3") endif() diff --git a/plugins/decl_netcdf/CMakeLists.txt b/plugins/decl_netcdf/CMakeLists.txt index 50aaa9768..01b8be72f 100644 --- a/plugins/decl_netcdf/CMakeLists.txt +++ b/plugins/decl_netcdf/CMakeLists.txt @@ -32,7 +32,8 @@ cmake_minimum_required(VERSION 3.22...4.2) project(pdi_decl_netcdf_plugin LANGUAGES C CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") if(4.3 VERSION_GREATER "${CMAKE_VERSION}") - # Workaround for compiling with HDF5-2.0.0+ + # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 + # Workaround for missing HDF5_IS_PARALLEL with HDF5-2.0.0+ in cmake pre-4.3 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/4.3") endif() From 7a863c4f84fb62110e5c7715ec5d85d0364bf8e8 Mon Sep 17 00:00:00 2001 From: Julien Bigot Date: Wed, 15 Apr 2026 12:12:53 +0200 Subject: [PATCH 26/59] Apply suggestions from code review Co-authored-by: Julien Bigot --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c48d1f878..314a7dd26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,16 +106,16 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/pdi/cmake") if("${BUILD_DECL_NETCDF_PLUGIN}") if(4.3 VERSION_GREATER "${CMAKE_VERSION}") - # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 - # Workaround for missing HDF5_IS_PARALLEL with HDF5-2.0.0+ in cmake pre-4.3 + # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 + # Workaround for missing HDF5_IS_PARALLEL with HDF5-2.0.0+ in cmake pre-4.3 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/plugins/decl_netcdf/cmake/4.3") endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/plugins/decl_netcdf/cmake") endif() if("${BUILD_DECL_HDF5_PLUGIN}") if(4.3 VERSION_GREATER "${CMAKE_VERSION}") - # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 - # Workaround for missing HDF5_IS_PARALLEL with HDF5-2.0.0+ in cmake pre-4.3 + # Workaround missing "Prefer h5hl compilers if HDF5_FIND_HL is enabled" in cmake pre-4.1 + # Workaround for missing HDF5_IS_PARALLEL with HDF5-2.0.0+ in cmake pre-4.3 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/plugins/decl_hdf5/cmake/4.3") endif() endif() From 169bdadcbea2a0b7a6fbc6b70bd52a67ea1eb50d Mon Sep 17 00:00:00 2001 From: Julien Bigot Date: Wed, 15 Apr 2026 13:21:32 +0200 Subject: [PATCH 27/59] Fix compatibility with cmake pre 3.29 --- plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake | 2 ++ plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake b/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake index 0a15557f0..a65b1ebef 100644 --- a/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake +++ b/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake @@ -319,7 +319,9 @@ include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) include(FindPackageHandleStandardArgs) cmake_policy(PUSH) +if(POLICY CMP0159) cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_ +endif() # We haven't found HDF5 yet. Clear its state in case it is set in the parent # scope somewhere else. We can't rely on it because different components may diff --git a/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake b/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake index 0a15557f0..a65b1ebef 100644 --- a/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake +++ b/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake @@ -319,7 +319,9 @@ include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake) include(FindPackageHandleStandardArgs) cmake_policy(PUSH) +if(POLICY CMP0159) cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_ +endif() # We haven't found HDF5 yet. Clear its state in case it is set in the parent # scope somewhere else. We can't rely on it because different components may From f3d585a045c6e767dd9eaf9f72702edd80449662 Mon Sep 17 00:00:00 2001 From: Julien Bigot Date: Wed, 15 Apr 2026 13:41:34 +0200 Subject: [PATCH 28/59] Fix compatibility with cmake pre 3.25 --- plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake | 6 +++--- plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake b/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake index a65b1ebef..777ce3494 100644 --- a/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake +++ b/plugins/decl_hdf5/cmake/4.3/FindHDF5.cmake @@ -408,7 +408,7 @@ function(_HDF5_test_regular_compiler_C success version is_parallel) " fid = H5Fcreate(\"foo.h5\",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);\n" " return 0;\n" "}") - try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + try_compile(${success} "${_HDF5_TEST_DIR}" SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_c ) endif() @@ -454,7 +454,7 @@ function(_HDF5_test_regular_compiler_CXX success version is_parallel) " H5File file(\"foo.h5\", H5F_ACC_TRUNC);\n" " return 0;\n" "}") - try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + try_compile(${success} "${_HDF5_TEST_DIR}" SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_cxx ) endif() @@ -488,7 +488,7 @@ function(_HDF5_test_regular_compiler_Fortran success is_parallel) " call h5open_f(error)\n" " call h5close_f(error)\n" "end\n") - try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}") + try_compile(${success} "${_HDF5_TEST_DIR}" SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}") if(${success}) execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -showconfig OUTPUT_VARIABLE config_output diff --git a/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake b/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake index a65b1ebef..777ce3494 100644 --- a/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake +++ b/plugins/decl_netcdf/cmake/4.3/FindHDF5.cmake @@ -408,7 +408,7 @@ function(_HDF5_test_regular_compiler_C success version is_parallel) " fid = H5Fcreate(\"foo.h5\",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);\n" " return 0;\n" "}") - try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + try_compile(${success} "${_HDF5_TEST_DIR}" SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_c ) endif() @@ -454,7 +454,7 @@ function(_HDF5_test_regular_compiler_CXX success version is_parallel) " H5File file(\"foo.h5\", H5F_ACC_TRUNC);\n" " return 0;\n" "}") - try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" + try_compile(${success} "${_HDF5_TEST_DIR}" SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}" COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_cxx ) endif() @@ -488,7 +488,7 @@ function(_HDF5_test_regular_compiler_Fortran success is_parallel) " call h5open_f(error)\n" " call h5close_f(error)\n" "end\n") - try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}") + try_compile(${success} "${_HDF5_TEST_DIR}" SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}") if(${success}) execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -showconfig OUTPUT_VARIABLE config_output From c9817ddb003cac3206b432bdd8088f4ebda58f0e Mon Sep 17 00:00:00 2001 From: yushan wang Date: Wed, 15 Apr 2026 16:25:44 +0200 Subject: [PATCH 29/59] update changelog --- CHANGELOG.md | 1 + plugins/decl_hdf5/CHANGELOG.md | 1 + plugins/decl_hdf5/attribute_op.cxx | 2 +- plugins/decl_netcdf/CHANGELOG.md | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 873fdbcb5..5e438fa6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added * Enable plugin `decl_netcdf` in macOS CI +* Add cmake patch for missing `HDF5_IS_PARALLEL` with HDF5-2.0.0+ in cmake pre-4.3 ### Changed diff --git a/plugins/decl_hdf5/CHANGELOG.md b/plugins/decl_hdf5/CHANGELOG.md index 7f27d59ca..f148a0d59 100644 --- a/plugins/decl_hdf5/CHANGELOG.md +++ b/plugins/decl_hdf5/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added * Add subfiling support [#602](https://github.com/pdidev/pdi/issues/602) +* Add cmake patch for missing `HDF5_IS_PARALLEL` with HDF5-2.0.0+ in cmake pre-4.3 ### Changed diff --git a/plugins/decl_hdf5/attribute_op.cxx b/plugins/decl_hdf5/attribute_op.cxx index fcf6d6e48..060ee3a0a 100644 --- a/plugins/decl_hdf5/attribute_op.cxx +++ b/plugins/decl_hdf5/attribute_op.cxx @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) - * Copyright (C) 2021-2026 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC) + * Copyright (C) 2021 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC) * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/plugins/decl_netcdf/CHANGELOG.md b/plugins/decl_netcdf/CHANGELOG.md index f5b709732..f08641ffc 100644 --- a/plugins/decl_netcdf/CHANGELOG.md +++ b/plugins/decl_netcdf/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [[#603](https://github.com/pdidev/pdi/issues/603)] * Add type check when reading scalar variable from file [[#647](https://github.com/pdidev/pdi/issues/647)] +* Add cmake patch for missing `HDF5_IS_PARALLEL` with HDF5-2.0.0+ in cmake pre-4.3 ### Changed From b43a1c75d3f70c71e0a0d1265a3e6e4f3ce3e002 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Wed, 15 Apr 2026 18:25:13 +0200 Subject: [PATCH 30/59] update changelogs and spack.yaml --- CHANGELOG.md | 2 +- plugins/decl_hdf5/CHANGELOG.md | 2 +- plugins/decl_netcdf/CHANGELOG.md | 2 +- spack.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e438fa6c..a2206a642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added * Enable plugin `decl_netcdf` in macOS CI -* Add cmake patch for missing `HDF5_IS_PARALLEL` with HDF5-2.0.0+ in cmake pre-4.3 +* Added support for HDF5-2 by fixing an issue that arose when combining cmake < 4.3 with HDF5 >= 2 [#678](https://github.com/pdidev/pdi/issues/678) ### Changed diff --git a/plugins/decl_hdf5/CHANGELOG.md b/plugins/decl_hdf5/CHANGELOG.md index f148a0d59..60085c44e 100644 --- a/plugins/decl_hdf5/CHANGELOG.md +++ b/plugins/decl_hdf5/CHANGELOG.md @@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added * Add subfiling support [#602](https://github.com/pdidev/pdi/issues/602) -* Add cmake patch for missing `HDF5_IS_PARALLEL` with HDF5-2.0.0+ in cmake pre-4.3 +* Added support for HDF5-2 by fixing an issue that arose when combining cmake < 4.3 with HDF5 >= 2 [#678](https://github.com/pdidev/pdi/issues/678) ### Changed diff --git a/plugins/decl_netcdf/CHANGELOG.md b/plugins/decl_netcdf/CHANGELOG.md index f08641ffc..43fc33b7e 100644 --- a/plugins/decl_netcdf/CHANGELOG.md +++ b/plugins/decl_netcdf/CHANGELOG.md @@ -11,7 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [[#603](https://github.com/pdidev/pdi/issues/603)] * Add type check when reading scalar variable from file [[#647](https://github.com/pdidev/pdi/issues/647)] -* Add cmake patch for missing `HDF5_IS_PARALLEL` with HDF5-2.0.0+ in cmake pre-4.3 +* Added support for HDF5-2 by fixing an issue that arose when combining cmake < 4.3 with HDF5 >= 2 [#678](https://github.com/pdidev/pdi/issues/678) ### Changed diff --git a/spack.yaml b/spack.yaml index f9f18a2b2..46dde0673 100644 --- a/spack.yaml +++ b/spack.yaml @@ -31,7 +31,7 @@ spack: specs: - 'cmake@3.22.1:4' - 'doxygen@1.9.1:1' - - 'hdf5@1.10.7:1' + - 'hdf5@1.10.7:2' - 'libyaml@0.2.2:' - 'mpi' - 'netcdf-c@4.8.1:4' From b842376ef443bc96be890f3d643bd51981b78ce1 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 20 Mar 2026 14:31:29 +0100 Subject: [PATCH 31/59] add fix for hdf5 2.0.0 --- CMakeLists.txt | 5 ++++- plugins/decl_hdf5/CMakeLists.txt | 6 ++++-- plugins/decl_netcdf/cmake/FindNetCDF.cmake | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index debe4c134..e72a6d844 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,7 +308,7 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") sbuild_add_dependency(HDF5 "${USE_DEFAULT}" EMBEDDED_PATH "vendor/hdf5-1.12.3" COMPONENTS ${HDF5_COMPONENTS} - MODULE_VARS HDF5_IS_PARALLEL HDF5_VERSION + MODULE_VARS HDF5_IS_PARALLEL HDF5_PROVIDES_PARALLEL HDF5_VERSION CMAKE_CACHE_ARGS -DBUILD_STATIC_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF @@ -326,6 +326,9 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() + if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) + set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") + endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "You requested a parallel HDF5 build (-DBUILD_HDF5_PARALLEL=ON) but a sequential SYSTEM version has been found\n" diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index def1aede2..b04005bba 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -51,14 +51,16 @@ find_package(HDF5 REQUIRED COMPONENTS C) if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - +if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) + set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") +endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "Parallel HDF5 required, sequential HDF5 only found. Please set -DBUILD_HDF5_PARALLEL=OFF to disable parallel HDF5") endif() set(HDF5_DEPS hdf5::hdf5) # MPI -if("${HDF5_IS_PARALLEL}") +if("${HDF5_IS_PARALLEL}" OR "${HDF5_PROVIDES_PARALLEL}") if("${BUILD_TESTING}" AND "${BUILD_FORTRAN}") set(MPI_COMPONENTS Fortran) endif() diff --git a/plugins/decl_netcdf/cmake/FindNetCDF.cmake b/plugins/decl_netcdf/cmake/FindNetCDF.cmake index 0cdd109d5..b1465e884 100644 --- a/plugins/decl_netcdf/cmake/FindNetCDF.cmake +++ b/plugins/decl_netcdf/cmake/FindNetCDF.cmake @@ -369,7 +369,7 @@ if("${NetCDF_FOUND}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT "${HDF5_IS_PARALLEL}") + if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT ("${HDF5_PROVIDES_PARALLEL}" OR "${HDF5_IS_PARALLEL}")) message(ERROR "Parallel HDF5 required by NetCDF, sequential HDF5 only found.") endif() list(APPEND NetCDF_LINK_LIBRARIES hdf5::hdf5) From fc361bbaece81a36f95198812518cad28136fdbd Mon Sep 17 00:00:00 2001 From: yushan wang Date: Thu, 9 Apr 2026 09:33:35 +0200 Subject: [PATCH 32/59] Fix MPI condition for HDF5 parallel support --- plugins/decl_hdf5/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index b04005bba..ca6284d1a 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -60,7 +60,7 @@ endif() set(HDF5_DEPS hdf5::hdf5) # MPI -if("${HDF5_IS_PARALLEL}" OR "${HDF5_PROVIDES_PARALLEL}") +if("${HDF5_IS_PARALLEL}") if("${BUILD_TESTING}" AND "${BUILD_FORTRAN}") set(MPI_COMPONENTS Fortran) endif() From 7b288e9c70d606db6d954c049f4014f61b6d292d Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 11:47:29 +0200 Subject: [PATCH 33/59] add test for precision conversion --- .../HDF5_C/d2s_precision_read_test.c | 73 ++++++++++++++++++ .../HDF5_C/d2s_precision_write_test.c | 75 +++++++++++++++++++ .../PDI_C/d2s_precision_read_test.c | 68 +++++++++++++++++ .../PDI_C/d2s_precision_write_test.c | 61 +++++++++++++++ 4 files changed, 277 insertions(+) create mode 100644 plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c create mode 100644 plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c create mode 100644 plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c create mode 100644 plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c diff --git a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c new file mode 100644 index 000000000..4f0c0becb --- /dev/null +++ b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include +#include +#include +#include + +#define FILE "d2s_test.h5" + +int main() +{ + printf("HDF5 d2s_precision_read_test started\n"); + hid_t file_id = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT); + if (file_id < 0) { + return 1; + } + + double dset_data[1000]; + for (int i = 0; i < 1000; i++) { + dset_data[i] = 3.14; + } + + hid_t dataset_id = H5Dopen2(file_id, "float_data", H5P_DEFAULT); + if (dataset_id < 0) { + return 1; + } + + herr_t status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); + if (status < 0) { + return 1; + } + + for (int i = 0; i < 1000; i++) { + if (fabs(dset_data[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { + fprintf(stderr, "dset_data[%d]: %f != %f, diff = %f\n ", i, dset_data[i], i * 10.0 + 3.141592653589793, fabs(dset_data[i] - (i * 10.0 + 3.141592653589793))); + return 1; + } + } + + status = H5Dclose(dataset_id); + if (status < 0) { + return 1; + } + status = H5Fclose(file_id); + if (file_id < 0) { + return 1; + } + + printf("HDF5_C d2s_precision_read_test finalized\n"); + return 0; +} diff --git a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c new file mode 100644 index 000000000..4dc917c33 --- /dev/null +++ b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include +#include +#include + +#define FILE "d2s_test.h5" + +int main() +{ + printf("HDF5 d2s_precision_write_test started\n"); + hid_t file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if (file_id < 0) { + return 1; + } + + hsize_t coords[2] = {100, 10}; + hid_t dataspace_id = H5Screate_simple(2, coords, NULL); + if (dataspace_id < 0) { + return 1; + } + + double dset_data[1000]; + for (int i = 0; i < 1000; i++) { + dset_data[i] = i * 10.0 + 3.141592653589793; + } + + hid_t dataset_id = H5Dcreate2(file_id, "/float_data", H5T_NATIVE_FLOAT, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if (dataset_id < 0) { + return 1; + } + + herr_t status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); + if (status < 0) { + return 1; + } + + status = H5Sclose(dataspace_id); + if (status < 0) { + return 1; + } + status = H5Dclose(dataset_id); + if (status < 0) { + return 1; + } + status = H5Fclose(file_id); + if (file_id < 0) { + return 1; + } + + printf("HDF5_C d2s_precision_write_test finalized\n"); + return 0; +} diff --git a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c new file mode 100644 index 000000000..9daa53b0f --- /dev/null +++ b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include +#include +#include +#include + +#define FILE "d2s_test.h5" + +int main() +{ + printf("PDI d2s_precision_read_test started\n"); + const char* CONFIG_YAML + = "logging: trace \n" + "data: \n" + " double_data: { size: [100, 10], type: array, subtype: double } \n" + "plugins: \n" + " decl_hdf5: \n" + " - file: d2s_test.h5 \n" + " datasets: \n" + " float_data: {size: [100, 10], type: array, subtype: float }\n" + " read: \n" + " double_data: \n" + " dataset: float_data \n"; + + PC_tree_t conf = PC_parse_string(CONFIG_YAML); + PDI_init(conf); + double test_array[1000]; + for (int i = 0; i < 1000; i++) { + test_array[i] = 3.14; + } + PDI_expose("double_data", test_array, PDI_IN); + + for (int i = 0; i < 1000; i++) { + if (fabs(test_array[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { + fprintf(stderr, "test_array[%d] %f != %f, diff = %f\n ", i, test_array[i], i * 10.0 + 3.141592653589793, fabs(test_array[i] - (i * 10.0 + 3.141592653589793))); + return 1; + } + } + + PDI_finalize(); + PC_tree_destroy(&conf); + + printf("PDI d2s_precision_read_test finalized\n"); + return 0; +} diff --git a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c new file mode 100644 index 000000000..a59faade3 --- /dev/null +++ b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include +#include +#include + +#define FILE "d2s_test.h5" + +int main() +{ + printf("PDI d2s_precision_write_test started\n"); + const char* CONFIG_YAML + = "logging: trace \n" + "data: \n" + " double_data: { size: [100, 10], type: array, subtype: double } \n" + "plugins: \n" + " decl_hdf5: \n" + " - file: d2s_test.h5 \n" + " datasets: \n" + " float_data: {size: [100, 10], type: array, subtype: float }\n" + " write: \n" + " double_data: \n" + " dataset: float_data \n"; + + PC_tree_t conf = PC_parse_string(CONFIG_YAML); + PDI_init(conf); + double test_array[1000]; + + for (int i = 0; i < 1000; i++) { + test_array[i] = i * 10.0 + 3.141592653589793; + } + + PDI_expose("double_data", test_array, PDI_OUT); + PDI_finalize(); + PC_tree_destroy(&conf); + + printf("PDI d2s_precision_write_test finalized\n"); + return 0; +} From 97edfe916cc0b7a8aaf50a2b49e757db6e548a18 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 13:43:05 +0200 Subject: [PATCH 34/59] fix indent --- .../HDF5_C/d2s_precision_read_test.c | 19 ++++++++----- .../PDI_C/d2s_precision_read_test.c | 27 ++++++++++++------- .../PDI_C/d2s_precision_write_test.c | 10 +++---- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c index 4f0c0becb..1abb0c990 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c +++ b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c @@ -24,8 +24,8 @@ #include #include -#include #include +#include #define FILE "d2s_test.h5" @@ -52,11 +52,18 @@ int main() return 1; } - for (int i = 0; i < 1000; i++) { - if (fabs(dset_data[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { - fprintf(stderr, "dset_data[%d]: %f != %f, diff = %f\n ", i, dset_data[i], i * 10.0 + 3.141592653589793, fabs(dset_data[i] - (i * 10.0 + 3.141592653589793))); - return 1; - } + for (int i = 0; i < 1000; i++) { + if (fabs(dset_data[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { + fprintf( + stderr, + "dset_data[%d]: %f != %f, diff = %f\n ", + i, + dset_data[i], + i * 10.0 + 3.141592653589793, + fabs(dset_data[i] - (i * 10.0 + 3.141592653589793)) + ); + return 1; + } } status = H5Dclose(dataset_id); diff --git a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c index 9daa53b0f..ac916a623 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c +++ b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c @@ -23,9 +23,9 @@ ******************************************************************************/ #include +#include #include #include -#include #define FILE "d2s_test.h5" @@ -40,10 +40,10 @@ int main() " decl_hdf5: \n" " - file: d2s_test.h5 \n" " datasets: \n" - " float_data: {size: [100, 10], type: array, subtype: float }\n" - " read: \n" - " double_data: \n" - " dataset: float_data \n"; + " float_data: {size: [100, 10], type: array, subtype: float }\n" + " read: \n" + " double_data: \n" + " dataset: float_data \n"; PC_tree_t conf = PC_parse_string(CONFIG_YAML); PDI_init(conf); @@ -53,11 +53,18 @@ int main() } PDI_expose("double_data", test_array, PDI_IN); - for (int i = 0; i < 1000; i++) { - if (fabs(test_array[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { - fprintf(stderr, "test_array[%d] %f != %f, diff = %f\n ", i, test_array[i], i * 10.0 + 3.141592653589793, fabs(test_array[i] - (i * 10.0 + 3.141592653589793))); - return 1; - } + for (int i = 0; i < 1000; i++) { + if (fabs(test_array[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { + fprintf( + stderr, + "test_array[%d] %f != %f, diff = %f\n ", + i, + test_array[i], + i * 10.0 + 3.141592653589793, + fabs(test_array[i] - (i * 10.0 + 3.141592653589793)) + ); + return 1; + } } PDI_finalize(); diff --git a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c index a59faade3..221214455 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c +++ b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c @@ -39,17 +39,17 @@ int main() " decl_hdf5: \n" " - file: d2s_test.h5 \n" " datasets: \n" - " float_data: {size: [100, 10], type: array, subtype: float }\n" - " write: \n" - " double_data: \n" - " dataset: float_data \n"; + " float_data: {size: [100, 10], type: array, subtype: float }\n" + " write: \n" + " double_data: \n" + " dataset: float_data \n"; PC_tree_t conf = PC_parse_string(CONFIG_YAML); PDI_init(conf); double test_array[1000]; for (int i = 0; i < 1000; i++) { - test_array[i] = i * 10.0 + 3.141592653589793; + test_array[i] = i * 10.0 + 3.141592653589793; } PDI_expose("double_data", test_array, PDI_OUT); From adc2e8d003962f79c1af8fa638b05247ac37a112 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 11:49:02 +0200 Subject: [PATCH 35/59] Add 'd2s_precision' to ALL_TEST_NAMES --- plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt b/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt index 7b18f57d1..2d76c9d2e 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt +++ b/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt @@ -27,7 +27,7 @@ cmake_minimum_required(VERSION 3.22...4.2) set(RUNTEST_DIR "${CMAKE_CURRENT_LIST_DIR}/../../cmake/runtest-dir") -set(ALL_TEST_NAMES array dataset group struct variables) +set(ALL_TEST_NAMES array dataset group struct variables d2s_precision ) if("${BUILD_HDF5_PARALLEL}") list(APPEND ALL_TEST_NAMES mpi mpi_independent) endif() From f78960d23d6c649436d3cc147886ac0d96b3d9a4 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 13:01:22 +0200 Subject: [PATCH 36/59] Remove parallel HDF5 version check --- plugins/decl_hdf5/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/decl_hdf5/CMakeLists.txt b/plugins/decl_hdf5/CMakeLists.txt index ca6284d1a..def1aede2 100644 --- a/plugins/decl_hdf5/CMakeLists.txt +++ b/plugins/decl_hdf5/CMakeLists.txt @@ -51,9 +51,7 @@ find_package(HDF5 REQUIRED COMPONENTS C) if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() -if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) - set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") -endif() + if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "Parallel HDF5 required, sequential HDF5 only found. Please set -DBUILD_HDF5_PARALLEL=OFF to disable parallel HDF5") endif() From 6d24ef837e2874e1d9b9c79e6589d1ab4a47b0ab Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 13:02:08 +0200 Subject: [PATCH 37/59] Fix HDF5 parallel check in FindNetCDF.cmake --- plugins/decl_netcdf/cmake/FindNetCDF.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/decl_netcdf/cmake/FindNetCDF.cmake b/plugins/decl_netcdf/cmake/FindNetCDF.cmake index b1465e884..0cdd109d5 100644 --- a/plugins/decl_netcdf/cmake/FindNetCDF.cmake +++ b/plugins/decl_netcdf/cmake/FindNetCDF.cmake @@ -369,7 +369,7 @@ if("${NetCDF_FOUND}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT ("${HDF5_PROVIDES_PARALLEL}" OR "${HDF5_IS_PARALLEL}")) + if("PARALLEL4" IN_LIST NetCDF_FEATURES AND NOT "${HDF5_IS_PARALLEL}") message(ERROR "Parallel HDF5 required by NetCDF, sequential HDF5 only found.") endif() list(APPEND NetCDF_LINK_LIBRARIES hdf5::hdf5) From 21df9af7b32f8d465db1b72a0b900277870c7e8e Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 13:02:39 +0200 Subject: [PATCH 38/59] Refactor HDF5 version checks in CMakeLists Removed check for HDF5 version greater than 2.0.0 and related variable assignment. --- CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e72a6d844..debe4c134 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,7 +308,7 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") sbuild_add_dependency(HDF5 "${USE_DEFAULT}" EMBEDDED_PATH "vendor/hdf5-1.12.3" COMPONENTS ${HDF5_COMPONENTS} - MODULE_VARS HDF5_IS_PARALLEL HDF5_PROVIDES_PARALLEL HDF5_VERSION + MODULE_VARS HDF5_IS_PARALLEL HDF5_VERSION CMAKE_CACHE_ARGS -DBUILD_STATIC_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF @@ -326,9 +326,6 @@ if("${BUILD_DECL_HDF5_PLUGIN}" OR "${BUILD_DECL_NETCDF_PLUGIN}") if("${HDF5_VERSION}" VERSION_LESS 1.10) message(FATAL_ERROR "HDF5 version 1.10 at least required, HDF5 ${HDF5_VERSION} found.") endif() - if("${HDF5_VERSION}" VERSION_GREATER_EQUAL 2.0.0) - set(HDF5_IS_PARALLEL "${HDF5_PROVIDES_PARALLEL}") - endif() if("${BUILD_HDF5_PARALLEL}" AND NOT "${HDF5_IS_PARALLEL}") message(FATAL_ERROR "You requested a parallel HDF5 build (-DBUILD_HDF5_PARALLEL=ON) but a sequential SYSTEM version has been found\n" From 121fa7b4283c6540e6ac48d215f85528aab8ae1e Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 14 Apr 2026 13:52:11 +0200 Subject: [PATCH 39/59] update decl_hdf5/CHANGELOG.md --- plugins/decl_hdf5/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/decl_hdf5/CHANGELOG.md b/plugins/decl_hdf5/CHANGELOG.md index 45dd6b9dd..09cd0709e 100644 --- a/plugins/decl_hdf5/CHANGELOG.md +++ b/plugins/decl_hdf5/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added * Add subfiling support [#602](https://github.com/pdidev/pdi/issues/602) +* Add tests for HDF5 precision conversion (data in double precision while dataset declared with simple precision in file) ### Changed * Fully qualify `std::move` calls to prevent a compilation warning and incorrect From 4db4f55caacbe4d9093a6104c10161e22e7f6cf0 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Thu, 16 Apr 2026 16:30:20 +0200 Subject: [PATCH 40/59] update precision conversion test using new testing.h --- .../tests/compatibility_tests/CMakeLists.txt | 6 +- .../HDF5_C/d2s_precision_read_test.c | 80 ------------ .../HDF5_C/d2s_precision_write_test.c | 75 ----------- .../PDI_C/d2s_precision_read_test.c | 75 ----------- .../PDI_C/d2s_precision_write_test.c | 61 --------- .../decl_hdf5_precision_conversion_test.cxx | 119 ++++++++++++++++++ 6 files changed, 124 insertions(+), 292 deletions(-) delete mode 100644 plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c delete mode 100644 plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c delete mode 100644 plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c delete mode 100644 plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c create mode 100644 plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx diff --git a/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt b/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt index 2d76c9d2e..81551ca2f 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt +++ b/plugins/decl_hdf5/tests/compatibility_tests/CMakeLists.txt @@ -27,7 +27,7 @@ cmake_minimum_required(VERSION 3.22...4.2) set(RUNTEST_DIR "${CMAKE_CURRENT_LIST_DIR}/../../cmake/runtest-dir") -set(ALL_TEST_NAMES array dataset group struct variables d2s_precision ) +set(ALL_TEST_NAMES array dataset group struct variables) if("${BUILD_HDF5_PARALLEL}") list(APPEND ALL_TEST_NAMES mpi mpi_independent) endif() @@ -60,3 +60,7 @@ foreach(test_name ${ALL_TEST_NAMES}) endforeach(read_prefix) endforeach(write_prefix) endforeach(test_name) + +add_executable(decl_hdf5_conversion_test decl_hdf5_precision_conversion_test.cxx) +target_link_libraries(decl_hdf5_conversion_test ${HDF5_DEPS} PDI::PDI_C GTest::gmock GTest::gmock_main GTest::gtest GTest::gtest_main) +gtest_discover_tests(decl_hdf5_conversion_test) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c deleted file mode 100644 index 1abb0c990..000000000 --- a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_read_test.c +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of CEA nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific - * prior written permission. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ - -#include -#include -#include -#include - -#define FILE "d2s_test.h5" - -int main() -{ - printf("HDF5 d2s_precision_read_test started\n"); - hid_t file_id = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT); - if (file_id < 0) { - return 1; - } - - double dset_data[1000]; - for (int i = 0; i < 1000; i++) { - dset_data[i] = 3.14; - } - - hid_t dataset_id = H5Dopen2(file_id, "float_data", H5P_DEFAULT); - if (dataset_id < 0) { - return 1; - } - - herr_t status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); - if (status < 0) { - return 1; - } - - for (int i = 0; i < 1000; i++) { - if (fabs(dset_data[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { - fprintf( - stderr, - "dset_data[%d]: %f != %f, diff = %f\n ", - i, - dset_data[i], - i * 10.0 + 3.141592653589793, - fabs(dset_data[i] - (i * 10.0 + 3.141592653589793)) - ); - return 1; - } - } - - status = H5Dclose(dataset_id); - if (status < 0) { - return 1; - } - status = H5Fclose(file_id); - if (file_id < 0) { - return 1; - } - - printf("HDF5_C d2s_precision_read_test finalized\n"); - return 0; -} diff --git a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c b/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c deleted file mode 100644 index 4dc917c33..000000000 --- a/plugins/decl_hdf5/tests/compatibility_tests/HDF5_C/d2s_precision_write_test.c +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of CEA nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific - * prior written permission. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ - -#include -#include -#include - -#define FILE "d2s_test.h5" - -int main() -{ - printf("HDF5 d2s_precision_write_test started\n"); - hid_t file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - if (file_id < 0) { - return 1; - } - - hsize_t coords[2] = {100, 10}; - hid_t dataspace_id = H5Screate_simple(2, coords, NULL); - if (dataspace_id < 0) { - return 1; - } - - double dset_data[1000]; - for (int i = 0; i < 1000; i++) { - dset_data[i] = i * 10.0 + 3.141592653589793; - } - - hid_t dataset_id = H5Dcreate2(file_id, "/float_data", H5T_NATIVE_FLOAT, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - if (dataset_id < 0) { - return 1; - } - - herr_t status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); - if (status < 0) { - return 1; - } - - status = H5Sclose(dataspace_id); - if (status < 0) { - return 1; - } - status = H5Dclose(dataset_id); - if (status < 0) { - return 1; - } - status = H5Fclose(file_id); - if (file_id < 0) { - return 1; - } - - printf("HDF5_C d2s_precision_write_test finalized\n"); - return 0; -} diff --git a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c deleted file mode 100644 index ac916a623..000000000 --- a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_read_test.c +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of CEA nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific - * prior written permission. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ - -#include -#include -#include -#include - -#define FILE "d2s_test.h5" - -int main() -{ - printf("PDI d2s_precision_read_test started\n"); - const char* CONFIG_YAML - = "logging: trace \n" - "data: \n" - " double_data: { size: [100, 10], type: array, subtype: double } \n" - "plugins: \n" - " decl_hdf5: \n" - " - file: d2s_test.h5 \n" - " datasets: \n" - " float_data: {size: [100, 10], type: array, subtype: float }\n" - " read: \n" - " double_data: \n" - " dataset: float_data \n"; - - PC_tree_t conf = PC_parse_string(CONFIG_YAML); - PDI_init(conf); - double test_array[1000]; - for (int i = 0; i < 1000; i++) { - test_array[i] = 3.14; - } - PDI_expose("double_data", test_array, PDI_IN); - - for (int i = 0; i < 1000; i++) { - if (fabs(test_array[i] - (i * 10.0 + 3.141592653589793)) > 1.e-4) { - fprintf( - stderr, - "test_array[%d] %f != %f, diff = %f\n ", - i, - test_array[i], - i * 10.0 + 3.141592653589793, - fabs(test_array[i] - (i * 10.0 + 3.141592653589793)) - ); - return 1; - } - } - - PDI_finalize(); - PC_tree_destroy(&conf); - - printf("PDI d2s_precision_read_test finalized\n"); - return 0; -} diff --git a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c b/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c deleted file mode 100644 index 221214455..000000000 --- a/plugins/decl_hdf5/tests/compatibility_tests/PDI_C/d2s_precision_write_test.c +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of CEA nor the names of its contributors may be used to - * endorse or promote products derived from this software without specific - * prior written permission. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ - -#include -#include -#include - -#define FILE "d2s_test.h5" - -int main() -{ - printf("PDI d2s_precision_write_test started\n"); - const char* CONFIG_YAML - = "logging: trace \n" - "data: \n" - " double_data: { size: [100, 10], type: array, subtype: double } \n" - "plugins: \n" - " decl_hdf5: \n" - " - file: d2s_test.h5 \n" - " datasets: \n" - " float_data: {size: [100, 10], type: array, subtype: float }\n" - " write: \n" - " double_data: \n" - " dataset: float_data \n"; - - PC_tree_t conf = PC_parse_string(CONFIG_YAML); - PDI_init(conf); - double test_array[1000]; - - for (int i = 0; i < 1000; i++) { - test_array[i] = i * 10.0 + 3.141592653589793; - } - - PDI_expose("double_data", test_array, PDI_OUT); - PDI_finalize(); - PC_tree_destroy(&conf); - - printf("PDI d2s_precision_write_test finalized\n"); - return 0; -} diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx new file mode 100644 index 000000000..5b981155a --- /dev/null +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of CEA nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include +#include +#include + +#include + +#include + +using PDI::make_random; +using PDI::random_init; +using testing::Eq; +using testing::StartsWith; +using testing::StrEq; + +class DeclHdf5: public ::PDI::PdiTest +{}; + +/* Precision conversion with decl_hdf5 + * data in double precision + * file dataset in simple precision + */ +TEST_F(DeclHdf5, PrecisionConversion) +{ + InitPdi(PC_parse_string(R"==( +logging: trace +metadata: + N: int +data: + array: {type: array, size: [$N, $N], subtype: double} +plugins: + decl_hdf5: + - file: d2d_test.h5 + datasets: + double_ds: {type: array, size: [$N, $N], subtype: double} + write: + array: + dataset: double_ds + - file: d2f_test.h5 + datasets: + float_ds: {type: array, size: [$N, $N], subtype: float} + write: + array: + dataset: float_ds + - file: d2i_test.h5 + datasets: + int_ds: {type: array, size: [$N, $N], subtype: int} + write: + array: + dataset: int_ds +)==")); + + EXPECT_FALSE(std::filesystem::exists("d2d_test.h5")); + EXPECT_FALSE(std::filesystem::exists("d2f_test.h5")); + EXPECT_FALSE(std::filesystem::exists("d2i_test.h5")); + + int const N = 100; + PDI_expose("N", &N, PDI_OUT); + + auto const test_array = make_a>(); + PDI_expose("array", test_array.data(), PDI_OUT); + + EXPECT_TRUE(std::filesystem::exists("d2d_test.h5")); + EXPECT_TRUE(std::filesystem::exists("d2f_test.h5")); + EXPECT_TRUE(std::filesystem::exists("d2i_test.h5")); + + hid_t file_id = H5Fopen("d2d_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT); + hid_t dataset_id = H5Dopen2(file_id, "/double_ds", H5P_DEFAULT); + hid_t type_id = H5Dget_type(dataset_id); + + EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F64LE)); + + H5Tclose(type_id); + H5Dclose(dataset_id); + H5Fclose(file_id); + + file_id = H5Fopen("d2f_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT); + dataset_id = H5Dopen2(file_id, "/float_ds", H5P_DEFAULT); + type_id = H5Dget_type(dataset_id); + + EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F32LE)); + + H5Tclose(type_id); + H5Dclose(dataset_id); + H5Fclose(file_id); + + file_id = H5Fopen("d2i_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT); + dataset_id = H5Dopen2(file_id, "/int_ds", H5P_DEFAULT); + type_id = H5Dget_type(dataset_id); + + EXPECT_TRUE(H5Tequal(type_id, H5T_STD_I32LE)); + + H5Tclose(type_id); + H5Dclose(dataset_id); + H5Fclose(file_id); +} From 450cdf85cf3da9952edbc2a6ec7335a8f9759af2 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Thu, 16 Apr 2026 16:44:00 +0200 Subject: [PATCH 41/59] Update precision conversion test documentation and remove unused includes --- .../decl_hdf5_precision_conversion_test.cxx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 5b981155a..d25575150 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -30,18 +30,12 @@ #include -using PDI::make_random; -using PDI::random_init; -using testing::Eq; -using testing::StartsWith; -using testing::StrEq; - class DeclHdf5: public ::PDI::PdiTest {}; /* Precision conversion with decl_hdf5 * data in double precision - * file dataset in simple precision + * file dataset in double, float, and int */ TEST_F(DeclHdf5, PrecisionConversion) { From 6ab160ca0e2196b62d50b32371f592e15f61852a Mon Sep 17 00:00:00 2001 From: yushan wang Date: Thu, 16 Apr 2026 16:47:50 +0200 Subject: [PATCH 42/59] Remove unused includes from decl_hdf5_precision_conversion_test.cxx --- .../compatibility_tests/decl_hdf5_precision_conversion_test.cxx | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index d25575150..5f1bf347f 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -23,8 +23,6 @@ ******************************************************************************/ #include -#include -#include #include From f12d6010ccab44de546d6bf5264421b029ccd43f Mon Sep 17 00:00:00 2001 From: yushan wang Date: Thu, 16 Apr 2026 17:30:06 +0200 Subject: [PATCH 43/59] Apply suggestions from code review Co-authored-by: Julien Bigot --- .../decl_hdf5_precision_conversion_test.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 5f1bf347f..1f3811fc4 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -69,10 +69,10 @@ logging: trace EXPECT_FALSE(std::filesystem::exists("d2f_test.h5")); EXPECT_FALSE(std::filesystem::exists("d2i_test.h5")); - int const N = 100; + static constexpr int const N = 100; PDI_expose("N", &N, PDI_OUT); - auto const test_array = make_a>(); + auto const test_array = make_a, N>>(); PDI_expose("array", test_array.data(), PDI_OUT); EXPECT_TRUE(std::filesystem::exists("d2d_test.h5")); From 20a8ab1441abf55556787b319c624761c5c40468 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Thu, 16 Apr 2026 17:57:34 +0200 Subject: [PATCH 44/59] compare the results using hdf5 read. Remain : compare double with int --- .../decl_hdf5_precision_conversion_test.cxx | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 1f3811fc4..dc102d75d 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -31,6 +31,13 @@ class DeclHdf5: public ::PDI::PdiTest {}; +template +bool are_equal(double d, T f) { + double diff = std::abs(d - static_cast(f)); + // Scale epsilon by the larger of the two values + return diff <= (std::max(std::abs(d), std::abs(static_cast(f))) + * std::numeric_limits::epsilon()); +} /* Precision conversion with decl_hdf5 * data in double precision * file dataset in double, float, and int @@ -84,6 +91,18 @@ logging: trace hid_t type_id = H5Dget_type(dataset_id); EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F64LE)); + auto read_double_array = make_a, N>>(); + + herr_t status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, read_double_array.data()); + + for (auto i = 0; i < N; i++) + { + for (auto j = 0; j < N; j++) + { + EXPECT_TRUE(are_equal(test_array[i][j], read_double_array[i][j])); + } + } H5Tclose(type_id); H5Dclose(dataset_id); @@ -94,6 +113,18 @@ logging: trace type_id = H5Dget_type(dataset_id); EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F32LE)); + auto read_float_array = make_a, N>>(); + + status = H5Dread(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, + H5P_DEFAULT, read_float_array.data()); + + for (auto i = 0; i < N; i++) + { + for (auto j = 0; j < N; j++) + { + EXPECT_TRUE(are_equal(test_array[i][j], read_float_array[i][j])); + } + } H5Tclose(type_id); H5Dclose(dataset_id); @@ -104,6 +135,18 @@ logging: trace type_id = H5Dget_type(dataset_id); EXPECT_TRUE(H5Tequal(type_id, H5T_STD_I32LE)); + auto read_int_array = make_a, N>>(); + + status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, + H5P_DEFAULT, read_int_array.data()); + + // for (auto i = 0; i < N; i++) + // { + // for (auto j = 0; j < N; j++) + // { + // EXPECT_TRUE(are_equal(test_array[i][j], read_int_array[i][j])); + // } + // } H5Tclose(type_id); H5Dclose(dataset_id); From 5e52643ff0e44374168bfea87a14e6be98b80517 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 17 Apr 2026 10:15:26 +0200 Subject: [PATCH 45/59] Refactor precision conversion tests to use template functions for comparing 2D fields --- .../decl_hdf5_precision_conversion_test.cxx | 82 ++++++++++--------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index dc102d75d..5971e5f39 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -22,6 +22,7 @@ * THE SOFTWARE. ******************************************************************************/ +#include #include #include @@ -31,13 +32,34 @@ class DeclHdf5: public ::PDI::PdiTest {}; -template -bool are_equal(double d, T f) { - double diff = std::abs(d - static_cast(f)); - // Scale epsilon by the larger of the two values - return diff <= (std::max(std::abs(d), std::abs(static_cast(f))) - * std::numeric_limits::epsilon()); +template // Only for floating point values +bool compare_2dfields(const std::array, N>& d_data, const std::array, N>& read_data) +{ + for (size_t i = 0; i < N; ++i) { + for (size_t j = 0; j < N; ++j) { + const double diff = std::abs(d_data[i][j] - static_cast(read_data[i][j])); + if (diff > std::numeric_limits::epsilon()) { + return false; + } + } + } + return true; +} + +template +requires std::is_integral_v // Only for integer values +bool compare_2dfields(const std::array, N>& d_data, const std::array, N>& read_data) +{ + for (size_t i = 0; i < N; ++i) { + for (size_t j = 0; j < N; ++j) { + if (static_cast(std::trunc(d_data[i][j])) != read_data[i][j]) { + return false; + } + } + } + return true; } + /* Precision conversion with decl_hdf5 * data in double precision * file dataset in double, float, and int @@ -76,7 +98,7 @@ logging: trace EXPECT_FALSE(std::filesystem::exists("d2f_test.h5")); EXPECT_FALSE(std::filesystem::exists("d2i_test.h5")); - static constexpr int const N = 100; + static constexpr size_t const N = 100; PDI_expose("N", &N, PDI_OUT); auto const test_array = make_a, N>>(); @@ -86,67 +108,49 @@ logging: trace EXPECT_TRUE(std::filesystem::exists("d2f_test.h5")); EXPECT_TRUE(std::filesystem::exists("d2i_test.h5")); + // read double precision dataset and compare hid_t file_id = H5Fopen("d2d_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT); hid_t dataset_id = H5Dopen2(file_id, "/double_ds", H5P_DEFAULT); hid_t type_id = H5Dget_type(dataset_id); EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F64LE)); - auto read_double_array = make_a, N>>(); + auto read_double_array = make_a, N>>(); - herr_t status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, read_double_array.data()); + herr_t status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_double_array.data()); - for (auto i = 0; i < N; i++) - { - for (auto j = 0; j < N; j++) - { - EXPECT_TRUE(are_equal(test_array[i][j], read_double_array[i][j])); - } - } + EXPECT_TRUE(compare_2dfields(test_array, read_double_array)); H5Tclose(type_id); H5Dclose(dataset_id); H5Fclose(file_id); + // read simple precision dataset and compare file_id = H5Fopen("d2f_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT); dataset_id = H5Dopen2(file_id, "/float_ds", H5P_DEFAULT); type_id = H5Dget_type(dataset_id); EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F32LE)); - auto read_float_array = make_a, N>>(); + auto read_float_array = make_a, N>>(); - status = H5Dread(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, read_float_array.data()); + status = H5Dread(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_float_array.data()); - for (auto i = 0; i < N; i++) - { - for (auto j = 0; j < N; j++) - { - EXPECT_TRUE(are_equal(test_array[i][j], read_float_array[i][j])); - } - } + EXPECT_TRUE(compare_2dfields(test_array, read_float_array)); H5Tclose(type_id); H5Dclose(dataset_id); H5Fclose(file_id); + // read ingeger dataset and compare file_id = H5Fopen("d2i_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT); dataset_id = H5Dopen2(file_id, "/int_ds", H5P_DEFAULT); type_id = H5Dget_type(dataset_id); EXPECT_TRUE(H5Tequal(type_id, H5T_STD_I32LE)); - auto read_int_array = make_a, N>>(); - - status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, read_int_array.data()); - - // for (auto i = 0; i < N; i++) - // { - // for (auto j = 0; j < N; j++) - // { - // EXPECT_TRUE(are_equal(test_array[i][j], read_int_array[i][j])); - // } - // } + auto read_int_array = make_a, N>>(); + + status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_int_array.data()); + + EXPECT_TRUE(compare_2dfields(test_array, read_int_array)); H5Tclose(type_id); H5Dclose(dataset_id); From cec1507b55c0b006c60e6c4af1cc447a2b649cd0 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 17 Apr 2026 12:24:14 +0200 Subject: [PATCH 46/59] Apply suggestions from code review Co-authored-by: Julien Bigot --- .../decl_hdf5_precision_conversion_test.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 5971e5f39..09f672373 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -130,10 +130,10 @@ logging: trace type_id = H5Dget_type(dataset_id); EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F32LE)); - auto read_float_array = make_a, N>>(); + std::array, N>> read_float_array; status = H5Dread(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_float_array.data()); - + ASSERT_GE(status, 0); EXPECT_TRUE(compare_2dfields(test_array, read_float_array)); H5Tclose(type_id); @@ -146,10 +146,10 @@ logging: trace type_id = H5Dget_type(dataset_id); EXPECT_TRUE(H5Tequal(type_id, H5T_STD_I32LE)); - auto read_int_array = make_a, N>>(); + std::array, N>> read_int_array; status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_int_array.data()); - + ASSERT_GE(status, 0); EXPECT_TRUE(compare_2dfields(test_array, read_int_array)); H5Tclose(type_id); From ddedac5d4f51d92f5b24c39e2ce90a103b4c19f7 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 17 Apr 2026 13:29:27 +0200 Subject: [PATCH 47/59] fix some typo and add gtest style d2d and f2d checking --- .../decl_hdf5_precision_conversion_test.cxx | 49 +++++-------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 09f672373..33fec5c5c 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -22,8 +22,8 @@ * THE SOFTWARE. ******************************************************************************/ -#include #include +#include #include @@ -32,34 +32,6 @@ class DeclHdf5: public ::PDI::PdiTest {}; -template // Only for floating point values -bool compare_2dfields(const std::array, N>& d_data, const std::array, N>& read_data) -{ - for (size_t i = 0; i < N; ++i) { - for (size_t j = 0; j < N; ++j) { - const double diff = std::abs(d_data[i][j] - static_cast(read_data[i][j])); - if (diff > std::numeric_limits::epsilon()) { - return false; - } - } - } - return true; -} - -template -requires std::is_integral_v // Only for integer values -bool compare_2dfields(const std::array, N>& d_data, const std::array, N>& read_data) -{ - for (size_t i = 0; i < N; ++i) { - for (size_t j = 0; j < N; ++j) { - if (static_cast(std::trunc(d_data[i][j])) != read_data[i][j]) { - return false; - } - } - } - return true; -} - /* Precision conversion with decl_hdf5 * data in double precision * file dataset in double, float, and int @@ -114,11 +86,11 @@ logging: trace hid_t type_id = H5Dget_type(dataset_id); EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F64LE)); - auto read_double_array = make_a, N>>(); + std::array, N> read_double_array; herr_t status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_double_array.data()); - EXPECT_TRUE(compare_2dfields(test_array, read_double_array)); + EXPECT_EQ(test_array, read_double_array); H5Tclose(type_id); H5Dclose(dataset_id); @@ -130,12 +102,16 @@ logging: trace type_id = H5Dget_type(dataset_id); EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F32LE)); - std::array, N>> read_float_array; + std::array < std::array, N > read_float_array; status = H5Dread(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_float_array.data()); ASSERT_GE(status, 0); - EXPECT_TRUE(compare_2dfields(test_array, read_float_array)); - + + for(auto i=0; i, N>> read_int_array; + std::array < std::array, N > read_int_array; status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_int_array.data()); ASSERT_GE(status, 0); - EXPECT_TRUE(compare_2dfields(test_array, read_int_array)); + + H5Tclose(type_id); H5Dclose(dataset_id); From 4180b158ea63eafcceec2503b8652fbcaf129e7a Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 17 Apr 2026 13:30:21 +0200 Subject: [PATCH 48/59] remain: int2double checking --- .../decl_hdf5_precision_conversion_test.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 33fec5c5c..25d1c59d7 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -106,7 +106,7 @@ logging: trace status = H5Dread(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_float_array.data()); ASSERT_GE(status, 0); - + for(auto i=0; i Date: Fri, 17 Apr 2026 13:31:01 +0200 Subject: [PATCH 49/59] indent --- .../decl_hdf5_precision_conversion_test.cxx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 25d1c59d7..59988a466 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -102,16 +102,15 @@ logging: trace type_id = H5Dget_type(dataset_id); EXPECT_TRUE(H5Tequal(type_id, H5T_IEEE_F32LE)); - std::array < std::array, N > read_float_array; + std::array< std::array, N > read_float_array; status = H5Dread(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_float_array.data()); ASSERT_GE(status, 0); - for(auto i=0; i, N > read_int_array; + std::array< std::array, N > read_int_array; status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_int_array.data()); ASSERT_GE(status, 0); - // checking ... + // checking ... // working on it H5Tclose(type_id); From fd37e5a6ea561012ed889a6d3b14c95f5f012369 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 17 Apr 2026 13:33:12 +0200 Subject: [PATCH 50/59] add status checking for hdf5 read --- .../compatibility_tests/decl_hdf5_precision_conversion_test.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 59988a466..816f8cf98 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -89,6 +89,7 @@ logging: trace std::array, N> read_double_array; herr_t status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_double_array.data()); + ASSERT_GE(status, 0); EXPECT_EQ(test_array, read_double_array); From 5cdd046d38c192412213fc7dfc34eb5d08c79dac Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 17 Apr 2026 13:39:26 +0200 Subject: [PATCH 51/59] one possible way to compare int and double --- .../decl_hdf5_precision_conversion_test.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 816f8cf98..b8079b7e0 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -128,7 +128,12 @@ logging: trace ASSERT_GE(status, 0); // checking ... - // working on it + // option 1 + bool int2double_match = std::ranges::equal(read_int_array | std::views::join, test_array | std::views::join, [](double read_val, int ref_val) { + return static_cast(std::trunc(ref_val)) == read_val; + }); + + EXPECT_TRUE(int2double_match); H5Tclose(type_id); H5Dclose(dataset_id); From 8a01504787c76295e64a3308400f86503b21c015 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 17 Apr 2026 13:43:54 +0200 Subject: [PATCH 52/59] fix: correct lambda parameter types in int to double comparison --- .../compatibility_tests/decl_hdf5_precision_conversion_test.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index b8079b7e0..0d154bd79 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -129,7 +129,7 @@ logging: trace // checking ... // option 1 - bool int2double_match = std::ranges::equal(read_int_array | std::views::join, test_array | std::views::join, [](double read_val, int ref_val) { + bool int2double_match = std::ranges::equal(read_int_array | std::views::join, test_array | std::views::join, [](int read_val, double ref_val) { return static_cast(std::trunc(ref_val)) == read_val; }); From d372511bac81bf69b8f1f57de932a4383e161315 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 17 Apr 2026 14:03:58 +0200 Subject: [PATCH 53/59] attempt for fixing CI faileur with spack oldest --- .../decl_hdf5_precision_conversion_test.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 0d154bd79..eeebda1c8 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -129,8 +129,10 @@ logging: trace // checking ... // option 1 - bool int2double_match = std::ranges::equal(read_int_array | std::views::join, test_array | std::views::join, [](int read_val, double ref_val) { - return static_cast(std::trunc(ref_val)) == read_val; + bool int2double_match = std::equal(read_int_array.begin(), read_int_array.end(), test_array.begin(), [](const auto& read_row, const auto& ref_row) { + return std::equal(read_row.begin(), read_row.end(), ref_row.begin(), [](int read_val, double ref_val) { + return static_cast(std::trunc(ref_val)) == read_val; + }); }); EXPECT_TRUE(int2double_match); From f60cb2501c7c3bc9f838657d39a0affba235a6c8 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Fri, 17 Apr 2026 14:22:42 +0200 Subject: [PATCH 54/59] indent --- .../decl_hdf5_precision_conversion_test.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index eeebda1c8..10a23b660 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -129,11 +129,12 @@ logging: trace // checking ... // option 1 - bool int2double_match = std::equal(read_int_array.begin(), read_int_array.end(), test_array.begin(), [](const auto& read_row, const auto& ref_row) { - return std::equal(read_row.begin(), read_row.end(), ref_row.begin(), [](int read_val, double ref_val) { - return static_cast(std::trunc(ref_val)) == read_val; - }); - }); + bool int2double_match + = std::equal(read_int_array.begin(), read_int_array.end(), test_array.begin(), [](const auto& read_row, const auto& ref_row) { + return std::equal(read_row.begin(), read_row.end(), ref_row.begin(), [](int read_val, double ref_val) { + return static_cast(std::trunc(ref_val)) == read_val; + }); + }); EXPECT_TRUE(int2double_match); From 7102952062c0a671ad542ba0d59e647e8c30cb1c Mon Sep 17 00:00:00 2001 From: yushan wang Date: Mon, 20 Apr 2026 10:16:11 +0200 Subject: [PATCH 55/59] refactor: update HDF5 precision conversion test in a more compact way --- .../decl_hdf5_precision_conversion_test.cxx | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 10a23b660..5a6a39963 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -108,9 +108,9 @@ logging: trace status = H5Dread(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_float_array.data()); ASSERT_GE(status, 0); - for (auto i = 0; i < N; i++) { - EXPECT_THAT(read_float_array[i], ::testing::Pointwise(::testing::FloatEq(), test_array[i])); - } + EXPECT_THAT(read_float_array, testing::ElementsAreArray(test_array | std::views::transform([](std::array const & aref) { + return testing::Pointwise(testing::FloatEq(), aref); + }))); H5Tclose(type_id); H5Dclose(dataset_id); @@ -127,16 +127,11 @@ logging: trace status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_int_array.data()); ASSERT_GE(status, 0); - // checking ... - // option 1 - bool int2double_match - = std::equal(read_int_array.begin(), read_int_array.end(), test_array.begin(), [](const auto& read_row, const auto& ref_row) { - return std::equal(read_row.begin(), read_row.end(), ref_row.begin(), [](int read_val, double ref_val) { - return static_cast(std::trunc(ref_val)) == read_val; - }); - }); - - EXPECT_TRUE(int2double_match); + EXPECT_THAT(read_int_array, testing::ElementsAreArray(test_array | std::views::transform([](std::array const & aref) { + return testing::ElementsAreArray(aref | std::views::transform([](double const & ref) { + return static_cast(ref); + })); + }))); H5Tclose(type_id); H5Dclose(dataset_id); From 5dd30bb097458c3e52cff609fae1a7e9d8119498 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Mon, 20 Apr 2026 13:20:01 +0200 Subject: [PATCH 56/59] skip precision conversion test when clang15 --- .../decl_hdf5_precision_conversion_test.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index 5a6a39963..b441326c9 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -38,6 +38,10 @@ class DeclHdf5: public ::PDI::PdiTest */ TEST_F(DeclHdf5, PrecisionConversion) { +#if defined(__clang__) && (__clang_major__ == 15) + GTEST_SKIP() << "Skipping test because Clang 15 has known issues with ranges."; +#endif + InitPdi(PC_parse_string(R"==( logging: trace metadata: @@ -116,7 +120,7 @@ logging: trace H5Dclose(dataset_id); H5Fclose(file_id); - // read ingeger dataset and compare + // read integer dataset and compare file_id = H5Fopen("d2i_test.h5", H5F_ACC_RDONLY, H5P_DEFAULT); dataset_id = H5Dopen2(file_id, "/int_ds", H5P_DEFAULT); type_id = H5Dget_type(dataset_id); From 717cbc61222b4e7c92eb53619322aabd8c18e6bd Mon Sep 17 00:00:00 2001 From: yushan wang Date: Mon, 20 Apr 2026 16:37:08 +0200 Subject: [PATCH 57/59] avoid compiling precision conversion test with clang15 --- .../decl_hdf5_precision_conversion_test.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index b441326c9..f699e25a7 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -29,6 +29,9 @@ #include +#if defined(__clang__) && (__clang_major__ == 15) +// Skipping test because Clang 15 has known issues with ranges. +#else class DeclHdf5: public ::PDI::PdiTest {}; @@ -38,10 +41,6 @@ class DeclHdf5: public ::PDI::PdiTest */ TEST_F(DeclHdf5, PrecisionConversion) { -#if defined(__clang__) && (__clang_major__ == 15) - GTEST_SKIP() << "Skipping test because Clang 15 has known issues with ranges."; -#endif - InitPdi(PC_parse_string(R"==( logging: trace metadata: @@ -141,3 +140,5 @@ logging: trace H5Dclose(dataset_id); H5Fclose(file_id); } + +#endif From 44168952f33852f1b7261d98289515fd151aa020 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 21 Apr 2026 16:53:29 +0200 Subject: [PATCH 58/59] skip only numerical comparaison with clang15 --- .../decl_hdf5_precision_conversion_test.cxx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index f699e25a7..e21845c6b 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -29,9 +29,6 @@ #include -#if defined(__clang__) && (__clang_major__ == 15) -// Skipping test because Clang 15 has known issues with ranges. -#else class DeclHdf5: public ::PDI::PdiTest {}; @@ -111,9 +108,13 @@ logging: trace status = H5Dread(dataset_id, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_float_array.data()); ASSERT_GE(status, 0); +#if defined(__clang__) && (__clang_major__ == 15) +// Skipping the numerical comparaison because Clang 15 has known issues with ranges. +#else EXPECT_THAT(read_float_array, testing::ElementsAreArray(test_array | std::views::transform([](std::array const & aref) { return testing::Pointwise(testing::FloatEq(), aref); }))); +#endif H5Tclose(type_id); H5Dclose(dataset_id); @@ -130,15 +131,17 @@ logging: trace status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_int_array.data()); ASSERT_GE(status, 0); +#if defined(__clang__) && (__clang_major__ == 15) +// Skipping the numerical comparaison because Clang 15 has known issues with ranges. +#else EXPECT_THAT(read_int_array, testing::ElementsAreArray(test_array | std::views::transform([](std::array const & aref) { return testing::ElementsAreArray(aref | std::views::transform([](double const & ref) { return static_cast(ref); })); }))); +#endif H5Tclose(type_id); H5Dclose(dataset_id); H5Fclose(file_id); -} - -#endif +} \ No newline at end of file From 54ac0f08a7886118bd5a9beb6a5e637571ce0d22 Mon Sep 17 00:00:00 2001 From: yushan wang Date: Tue, 21 Apr 2026 16:57:28 +0200 Subject: [PATCH 59/59] empty line at eof --- .../compatibility_tests/decl_hdf5_precision_conversion_test.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx index e21845c6b..14100772b 100644 --- a/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx +++ b/plugins/decl_hdf5/tests/compatibility_tests/decl_hdf5_precision_conversion_test.cxx @@ -144,4 +144,4 @@ logging: trace H5Tclose(type_id); H5Dclose(dataset_id); H5Fclose(file_id); -} \ No newline at end of file +}