From 4908969f578ded9d87f244bd8ada65ba0c51cf28 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 2 Feb 2017 09:21:21 -0500 Subject: FindHDF5: Fix search with HDF5_ROOT Refactoring in commit v3.6.0-rc1~72^2 (HDF5: Rework component searching to correctly find HL for all bindings, 2016-05-12) turned off a large amount of its logic when HDF5_ROOT is set. This caused use of the hdf5 compiler wrapper to extract all needed libraries (e.g. z, dl as dependencies of hdf5 static libraries) to be skipped when using HDF5_ROOT. Fix the search logic to honor HDF5_ROOT in all code paths. Restrict the search for hdf5-specific components to this root, but allow external libraries to be found anywhere. Fixes: #16566 --- Modules/FindHDF5.cmake | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake index f07d0c7..94a8729 100644 --- a/Modules/FindHDF5.cmake +++ b/Modules/FindHDF5.cmake @@ -383,10 +383,18 @@ endmacro() 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_ROOT) - find_package(HDF5 QUIET NO_MODULE) +if(NOT HDF5_FOUND) + find_package(HDF5 QUIET NO_MODULE + HINTS ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS} + ) if( HDF5_FOUND) set(HDF5_IS_PARALLEL ${HDF5_ENABLE_PARALLEL}) set(HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR}) @@ -440,7 +448,7 @@ if(NOT HDF5_FOUND AND NOT HDF5_ROOT) endif() endif() -if(NOT HDF5_FOUND AND NOT HDF5_ROOT) +if(NOT HDF5_FOUND) set(_HDF5_NEED_TO_SEARCH False) set(HDF5_COMPILER_NO_INTERROGATE True) # Only search for languages we've enabled @@ -488,8 +496,10 @@ if(NOT HDF5_FOUND AND NOT HDF5_ROOT) # 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) @@ -516,10 +526,20 @@ if(NOT HDF5_FOUND AND NOT HDF5_ROOT) endif() foreach(L IN LISTS HDF5_${__lang}_LIBRARY_NAMES) + if(x"${L}" MATCHES "hdf5") + # hdf5 library + set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) + else() + # external library + set(_HDF5_SEARCH_OPTS_LOCAL) + endif() find_library(HDF5_${__lang}_LIBRARY_${L} NAMES ${L} HINTS ${HDF5_${__lang}_LIBRARY_DIRS} + ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS_LOCAL} ) + unset(_HDF5_SEARCH_OPTS_LOCAL) if(HDF5_${__lang}_LIBRARY_${L}) list(APPEND HDF5_${__lang}_LIBRARIES ${HDF5_${__lang}_LIBRARY_${L}}) else() @@ -529,10 +549,20 @@ if(NOT HDF5_FOUND AND NOT HDF5_ROOT) if(FIND_HL) set(HDF5_${__lang}_HL_LIBRARIES) foreach(L IN LISTS HDF5_${__lang}_HL_LIBRARY_NAMES) + if("x${L}" MATCHES "hdf5") + # hdf5 library + set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS}) + else() + # external library + set(_HDF5_SEARCH_OPTS_LOCAL) + endif() find_library(HDF5_${__lang}_LIBRARY_${L} NAMES ${L} HINTS ${HDF5_${__lang}_LIBRARY_DIRS} + ${HDF5_ROOT} + ${_HDF5_SEARCH_OPTS_LOCAL} ) + unset(_HDF5_SEARCH_OPTS_LOCAL) if(HDF5_${__lang}_LIBRARY_${L}) list(APPEND HDF5_${__lang}_HL_LIBRARIES ${HDF5_${__lang}_LIBRARY_${L}}) else() @@ -614,11 +644,6 @@ elseif(NOT HDF5_FOUND AND NOT _HDF5_NEED_TO_SEARCH) endif() endif() -if(HDF5_ROOT) - set(_HDF5_SEARCH_OPTS NO_DEFAULT_PATH) -else() - set(_HDF5_SEARCH_OPTS) -endif() find_program( HDF5_DIFF_EXECUTABLE NAMES h5diff HINTS ${HDF5_ROOT} -- cgit v0.12