| 1 |
######################################################################## |
| 2 |
# See associated tribits/Copyright.txt file for copyright and license! # |
| 3 |
######################################################################## |
| 4 |
|
| 5 |
set(HDF5_INTERNAL_IS_MODERN FALSE) |
| 6 |
|
| 7 |
if (Netcdf_ALLOW_MODERN) |
| 8 |
|
| 9 |
print_var(Netcdf_ALLOW_MODERN) |
| 10 |
message("-- Using find_package(HDF5 CONFIG) ...") |
| 11 |
find_package(HDF5 CONFIG) |
| 12 |
if (HDF5_FOUND) |
| 13 |
message("-- Found HDF5_CONFIG=${HDF5_CONFIG}") |
| 14 |
message("-- Generating Netcdf::all_libs and NetcdfConfig.cmake") |
| 15 |
message("-- HDF5_EXPORT_LIBRARIES=${HDF5_EXPORT_LIBRARIES}") |
| 16 |
tribits_extpkg_create_imported_all_libs_target_and_config_file( |
| 17 |
HDF5 |
| 18 |
INNER_FIND_PACKAGE_NAME HDF5 |
| 19 |
IMPORTED_TARGETS_FOR_ALL_LIBS ${HDF5_EXPORT_LIBRARIES}) |
| 20 |
set(HDF5_INTERNAL_IS_MODERN TRUE) |
| 21 |
endif() |
| 22 |
|
| 23 |
endif() |
| 24 |
|
| 25 |
set(HDF5_FOUND_MODERN_CONFIG_FILE ${HDF5_INTERNAL_IS_MODERN} CACHE INTERNAL "True if HDF5 was found by the modern method") |
| 26 |
|
| 27 |
if (NOT TARGET HDF5::all_libs) |
| 28 |
|
| 29 |
# First, set up the variables for the (backward-compatible) TriBITS way of |
| 30 |
# finding HDF5. These are used in case find_package(HDF5 ...) is not called |
| 31 |
# or does not find HDF5. Also, these variables need to be non-null in order |
| 32 |
# to trigger the right behavior in the function |
| 33 |
# tribits_tpl_find_include_dirs_and_libraries(). |
| 34 |
|
| 35 |
set(REQUIRED_HEADERS hdf5.h) |
| 36 |
set(REQUIRED_LIBS_NAMES hdf5) |
| 37 |
|
| 38 |
if (HDF5_REQUIRE_FORTRAN) |
| 39 |
set(REQUIRED_LIBS_NAMES ${REQUIRED_LIBS_NAMES} hdf5_fortran) |
| 40 |
endif() |
| 41 |
|
| 42 |
if (TPL_ENABLE_MPI) |
| 43 |
set(REQUIRED_LIBS_NAMES ${REQUIRED_LIBS_NAMES} z) |
| 44 |
endif() |
| 45 |
|
| 46 |
if (TPL_ENABLE_Netcdf) |
| 47 |
set(REQUIRED_LIBS_NAMES ${REQUIRED_LIBS_NAMES} hdf5_hl) |
| 48 |
endif() |
| 49 |
|
| 50 |
# |
| 51 |
# Second, search for HDF5 components (if allowed) using the standard |
| 52 |
# find_package(HDF5 ...). |
| 53 |
# |
| 54 |
tribits_tpl_allow_pre_find_package(HDF5 HDF5_ALLOW_PREFIND) |
| 55 |
if (HDF5_ALLOW_PREFIND) |
| 56 |
|
| 57 |
message("-- Using find_package(HDF5 ...) ...") |
| 58 |
|
| 59 |
set(HDF5_COMPONENTS C) |
| 60 |
if (HDF5_REQUIRE_FORTRAN) |
| 61 |
list(APPEND HDF5_COMPONENTS Fortran) |
| 62 |
endif() |
| 63 |
|
| 64 |
if (TPL_ENABLE_MPI) |
| 65 |
set(HDF5_PREFER_PARALLEL TRUE) |
| 66 |
endif() |
| 67 |
|
| 68 |
find_package(HDF5 COMPONENTS ${HDF5_COMPONENTS}) |
| 69 |
|
| 70 |
# Make sure that HDF5 is parallel. |
| 71 |
if (TPL_ENABLE_MPI AND NOT HDF5_IS_PARALLEL) |
| 72 |
message(FATAL_ERROR "Trilinos is configured for MPI, HDF5 is not. |
| 73 |
Did CMake find the correct libraries? |
| 74 |
Try setting HDF5_INCLUDE_DIRS and/or HDF5_LIBRARY_DIRS explicitly. |
| 75 |
") |
| 76 |
endif() |
| 77 |
|
| 78 |
if (HDF5_FOUND) |
| 79 |
# Tell TriBITS that we found HDF5 and there no need to look any further! |
| 80 |
set(TPL_HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS} CACHE PATH |
| 81 |
"HDF5 include dirs") |
| 82 |
set(TPL_HDF5_LIBRARIES ${HDF5_LIBRARIES} CACHE FILEPATH |
| 83 |
"HDF5 libraries") |
| 84 |
set(TPL_HDF5_LIBRARY_DIRS ${HDF5_LIBRARY_DIRS} CACHE PATH |
| 85 |
"HDF5 library dirs") |
| 86 |
endif() |
| 87 |
|
| 88 |
endif() |
| 89 |
|
| 90 |
# |
| 91 |
# Third, call tribits_tpl_find_include_dirs_and_libraries() |
| 92 |
# |
| 93 |
tribits_tpl_find_include_dirs_and_libraries( HDF5 |
| 94 |
REQUIRED_HEADERS ${REQUIRED_HEADERS} |
| 95 |
REQUIRED_LIBS_NAMES ${REQUIRED_LIBS_NAMES} |
| 96 |
) |
| 97 |
# NOTE: If find_package(HDF5 ...) was called and successfully found HDF5, then |
| 98 |
# tribits_tpl_find_include_dirs_and_libraries() will use the already-set |
| 99 |
# variables TPL_HDF5_INCLUDE_DIRS and TPL_HDF5_LIBRARIES and then print them |
| 100 |
# out (and set some other standard variables as well). This is the final |
| 101 |
# "hook" into the TriBITS TPL system. |
| 102 |
|
| 103 |
endif() |