Skip to content

Commit ceaa22d

Browse files
committed
FindHDF5: when HDF5_ROOT specified, only search that path for h5cc compiler wrappers
Some HDF5 installs don't have compiler wrappers, and then Anaconda's would get found, causing the search to fail.
1 parent 9075bae commit ceaa22d

File tree

1 file changed

+57
-25
lines changed

1 file changed

+57
-25
lines changed

cmake/Modules/FindHDF5.cmake

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,23 @@ if(NOT parallel IN_LIST HDF5_FIND_COMPONENTS)
348348
list(PREPEND wrapper_names h5fc h5fc-64)
349349
endif()
350350

351-
find_program(HDF5_Fortran_COMPILER_EXECUTABLE
352-
NAMES ${wrapper_names}
353-
NAMES_PER_DIR
354-
HINTS ${HOMEBREW_PREFIX} ENV HOMEBREW_PREFIX ${MACPORTS_PREFIX} ENV MACPORTS_PREFIX
355-
PATHS ${hdf5_binpref}
356-
PATH_SUFFIXES ${hdf5_binsuf}
357-
)
351+
if(HDF5_ROOT OR DEFINED ENV{HDF5_ROOT})
352+
find_program(HDF5_Fortran_COMPILER_EXECUTABLE
353+
NAMES ${wrapper_names}
354+
NAMES_PER_DIR
355+
NO_DEFAULT_PATH
356+
HINTS ${HDF5_ROOT} ENV HDF5_ROOT
357+
PATH_SUFFIXES ${hdf5_binsuf}
358+
)
359+
else()
360+
find_program(HDF5_Fortran_COMPILER_EXECUTABLE
361+
NAMES ${wrapper_names}
362+
NAMES_PER_DIR
363+
HINTS ${HOMEBREW_PREFIX} ENV HOMEBREW_PREFIX ${MACPORTS_PREFIX} ENV MACPORTS_PREFIX
364+
PATHS ${hdf5_binpref}
365+
PATH_SUFFIXES ${hdf5_binsuf}
366+
)
367+
endif()
358368

359369
if(HDF5_Fortran_COMPILER_EXECUTABLE)
360370
get_flags(${HDF5_Fortran_COMPILER_EXECUTABLE} f_raw)
@@ -386,13 +396,23 @@ function(hdf5_cxx_wrap lib_var inc_var)
386396
set(lib_dirs)
387397
set(inc_dirs)
388398

389-
find_program(HDF5_CXX_COMPILER_EXECUTABLE
390-
NAMES h5c++ h5c++-64
391-
NAMES_PER_DIR
392-
HINTS ${HOMEBREW_PREFIX} ENV HOMEBREW_PREFIX ${MACPORTS_PREFIX} ENV MACPORTS_PREFIX
393-
PATHS ${hdf5_binpref}
394-
PATH_SUFFIXES ${hdf5_binsuf}
395-
)
399+
if(HDF5_ROOT OR DEFINED ENV{HDF5_ROOT})
400+
find_program(HDF5_CXX_COMPILER_EXECUTABLE
401+
NAMES ${wrapper_names}
402+
NAMES_PER_DIR
403+
NO_DEFAULT_PATH
404+
HINTS ${HDF5_ROOT} ENV HDF5_ROOT
405+
PATH_SUFFIXES ${hdf5_binsuf}
406+
)
407+
else()
408+
find_program(HDF5_CXX_COMPILER_EXECUTABLE
409+
NAMES h5c++ h5c++-64
410+
NAMES_PER_DIR
411+
HINTS ${HOMEBREW_PREFIX} ENV HOMEBREW_PREFIX ${MACPORTS_PREFIX} ENV MACPORTS_PREFIX
412+
PATHS ${hdf5_binpref}
413+
PATH_SUFFIXES ${hdf5_binsuf}
414+
)
415+
endif()
396416

397417
if(HDF5_CXX_COMPILER_EXECUTABLE)
398418
get_flags(${HDF5_CXX_COMPILER_EXECUTABLE} cxx_raw)
@@ -423,13 +443,23 @@ if(NOT parallel IN_LIST HDF5_FIND_COMPONENTS)
423443
list(PREPEND wrapper_names h5cc h5cc-64)
424444
endif()
425445

426-
find_program(HDF5_C_COMPILER_EXECUTABLE
427-
NAMES ${wrapper_names}
428-
NAMES_PER_DIR
429-
HINTS ${HOMEBREW_PREFIX} ENV HOMEBREW_PREFIX ${MACPORTS_PREFIX} ENV MACPORTS_PREFIX
430-
PATHS ${hdf5_binpref}
431-
PATH_SUFFIXES ${hdf5_binsuf}
432-
)
446+
if(HDF5_ROOT OR DEFINED ENV{HDF5_ROOT})
447+
find_program(HDF5_C_COMPILER_EXECUTABLE
448+
NAMES ${wrapper_names}
449+
NAMES_PER_DIR
450+
NO_DEFAULT_PATH
451+
HINTS ${HDF5_ROOT} ENV HDF5_ROOT
452+
PATH_SUFFIXES ${hdf5_binsuf}
453+
)
454+
else()
455+
find_program(HDF5_C_COMPILER_EXECUTABLE
456+
NAMES ${wrapper_names}
457+
NAMES_PER_DIR
458+
HINTS ${HOMEBREW_PREFIX} ENV HOMEBREW_PREFIX ${MACPORTS_PREFIX} ENV MACPORTS_PREFIX
459+
PATHS ${hdf5_binpref}
460+
PATH_SUFFIXES ${hdf5_binsuf}
461+
)
462+
endif()
433463

434464
if(HDF5_C_COMPILER_EXECUTABLE)
435465
get_flags(${HDF5_C_COMPILER_EXECUTABLE} c_raw)
@@ -576,7 +606,11 @@ endif()
576606

577607
# Conda causes numerous problems with finding HDF5, so exclude from search
578608
if(DEFINED ENV{CONDA_PREFIX})
579-
list(APPEND CMAKE_IGNORE_PATH $ENV{CONDA_PREFIX}/bin $ENV{CONDA_PREFIX}/lib $ENV{CONDA_PREFIX}/include)
609+
set(h5_ignore_path
610+
$ENV{CONDA_PREFIX}/bin $ENV{CONDA_PREFIX}/lib $ENV{CONDA_PREFIX}/include
611+
$ENV{CONDA_PREFIX}/Library/bin $ENV{CONDA_PREFIX}/Library/lib $ENV{CONDA_PREFIX}/Library/include
612+
)
613+
list(APPEND CMAKE_IGNORE_PATH ${h5_ignore_path})
580614
endif()
581615

582616
# we don't use pkg-config names because some distros pkg-config for HDF5 is broken
@@ -643,9 +677,7 @@ set(CMAKE_REQUIRED_LIBRARIES)
643677
set(CMAKE_REQUIRED_INCLUDES)
644678

645679
# pop off ignored paths so rest of script can find Python
646-
list(POP_BACK CMAKE_IGNORE_PATH)
647-
list(POP_BACK CMAKE_IGNORE_PATH)
648-
list(POP_BACK CMAKE_IGNORE_PATH)
680+
list(REMOVE_ITEM CMAKE_IGNORE_PATH ${h5_ignore_path})
649681

650682
include(FindPackageHandleStandardArgs)
651683
find_package_handle_standard_args(HDF5

0 commit comments

Comments
 (0)