From aca7b5cc2edc3bd02ac2fd8263ecbd97e09352f9 Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Thu, 5 Mar 2020 14:44:38 -0700 Subject: [PATCH] Better finding of the hdf5.h include path The `FIND_PATH` function has a non-intuitive order in which is searches for include paths and the original form could find a system-installed version of HDF5 even though the developer specified an explicit path via `HDF5_INCLUDE_DIR`. See https://cmake.org/cmake/help/latest/command/find_path.html for more information. The form in this patch is the recommended method from that page for changing the default search order to find the explicitly specified path *first* > The default search order is designed to be most-specific to least-specific for common use cases. Projects may override the order by simply calling the command multiple times and using the NO_* options: ``` find_path ( NAMES name PATHS paths... NO_DEFAULT_PATH) find_path ( NAMES name) ``` > Once one of the calls succeeds the result variable will be set and stored in the cache so that no call will search again. --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f766c300b..ea48c9efa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -761,7 +761,8 @@ IF(USE_HDF5 OR ENABLE_NETCDF_4) SET(H5_USE_16_API 0) ENDIF() - FIND_PATH(HAVE_HDF5_H hdf5.h PATHS ${HDF5_INCLUDE_DIR}) + FIND_PATH(HAVE_HDF5_H hdf5.h PATHS ${HDF5_INCLUDE_DIR} NO_DEFAULT_PATH) + FIND_PATH(HAVE_HDF5_H hdf5.h) IF(NOT HAVE_HDF5_H) MESSAGE(FATAL_ERROR "Compiling a test with hdf5 failed. Either hdf5.h cannot be found, or the log messages should be checked for another reason.") ELSE(NOT HAVE_HDF5_H)