Skip to content

Commit 6486000

Browse files
committed
FindHDF5: restrict Fortran search to be in C include path
FindHDF5: make Fortran find faster and stricter
1 parent 38dfd60 commit 6486000

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

cmake/Modules/FindHDF5.cmake

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,6 @@ endfunction(pop_flag)
9292

9393
function(detect_config)
9494

95-
if(Fortran IN_LIST HDF5_FIND_COMPONENTS AND NOT HDF5_Fortran_FOUND)
96-
return()
97-
endif()
98-
99-
if(CXX IN_LIST HDF5_FIND_COMPONENTS AND NOT HDF5_CXX_FOUND)
100-
return()
101-
endif()
102-
10395
set(CMAKE_REQUIRED_INCLUDES ${HDF5_C_INCLUDE_DIR})
10496

10597
find_file(h5_conf
@@ -238,12 +230,23 @@ if(HDF5_Fortran_HL_stub AND HDF5_Fortran_stub)
238230
list(APPEND HDF5_Fortran_LIBRARIES ${HDF5_Fortran_HL_stub} ${HDF5_Fortran_stub})
239231
endif()
240232

241-
find_path(HDF5_Fortran_INCLUDE_DIR
242-
NAMES hdf5.mod
243-
HINTS ${hdf5_inc_dirs} ${pc_hdf5_INCLUDE_DIRS}
244-
PATH_SUFFIXES ${hdf5_msuf}
245-
PATHS ${hdf5_binpref}
246-
DOC "HDF5 Fortran modules")
233+
if(HDF5_ROOT OR DEFINED ENV{HDF5_ROOT})
234+
find_path(HDF5_Fortran_INCLUDE_DIR
235+
NAMES hdf5.mod
236+
NO_DEFAULT_PATH
237+
HINTS ${HDF5_ROOT} ENV HDF5_ROOT
238+
PATH_SUFFIXES ${hdf5_msuf}
239+
DOC "HDF5 Fortran module path"
240+
)
241+
else()
242+
find_path(HDF5_Fortran_INCLUDE_DIR
243+
NAMES hdf5.mod
244+
HINTS ${HDF5_C_INCLUDE_DIR} ${hdf5_inc_dirs} ${pc_hdf5_INCLUDE_DIRS}
245+
PATHS ${hdf5_binpref}
246+
PATH_SUFFIXES ${hdf5_msuf}
247+
DOC "HDF5 Fortran module path"
248+
)
249+
endif()
247250

248251
if(HDF5_Fortran_LIBRARY AND HDF5_Fortran_HL_LIBRARY AND HDF5_Fortran_INCLUDE_DIR)
249252
set(HDF5_Fortran_LIBRARIES ${HDF5_Fortran_LIBRARIES} PARENT_SCOPE)
@@ -653,14 +656,6 @@ endif()
653656
# find_package(hdf5 CONFIG)
654657
# message(STATUS "hdf5 found ${hdf5_FOUND}")
655658

656-
if(Fortran IN_LIST HDF5_FIND_COMPONENTS)
657-
find_hdf5_fortran()
658-
endif()
659-
660-
if(CXX IN_LIST HDF5_FIND_COMPONENTS)
661-
find_hdf5_cxx()
662-
endif()
663-
664659
# C is always needed
665660
find_hdf5_c()
666661

@@ -669,6 +664,14 @@ if(HDF5_C_FOUND)
669664
detect_config()
670665
endif(HDF5_C_FOUND)
671666

667+
if(HDF5_C_FOUND AND CXX IN_LIST HDF5_FIND_COMPONENTS)
668+
find_hdf5_cxx()
669+
endif()
670+
671+
if(HDF5_C_FOUND AND Fortran IN_LIST HDF5_FIND_COMPONENTS)
672+
find_hdf5_fortran()
673+
endif()
674+
672675
# --- configure time checks
673676
# these checks avoid messy, confusing errors at build time
674677
check_hdf5_link()

0 commit comments

Comments
 (0)