I'd like to offer the attached patch for consideration that fixes a number
of issues with FindHDF5.cmake. The issues are as follows:

1. Searching for libraries related to the HL and Fortran_HL components is a
bit broken at the moment; for example, if you specify the Fortran_HL
component, HDF5_INCLUDE_DIRS ends up including
HDF5_Fortran_HL_INCLUDE_DIR-NOTFOUND, which makes HDF5_INCLUDE_DIRS
evaluate to false, thus causing the overall find_package to fail. The
debian maintainers actually have included a two-line patch to fix this
going all the way back to pre-3.0 for their cmake-data package. That patch
is included here.

2. Even with the aforementioned patch, specifying the Fortran_HL component
doesn't include the hdf5_hl library, which results in a bunch of undefined
references at link time. I've added that library to the list of libraries
to be searched for Fortran_HL.

3. In issue #15527, it is reported that when a serial and parallel
installation of HDF5 are installed alongside one another, the serial
version is always preferred even if you specify the parallel version in
HDF5_ROOT. This is a result of find_program searching for h5cc and h5pcc
simulataneously, with h5cc listed first. In the attached patch, one can now
set the HDF5_PREFER_PARALLEL variable which tells FindHDF5 to search for
h5pcc first rather than h5cc.

Best regards,
Paul
From 883a9f93c892a5580369adba542c2f852332ff41 Mon Sep 17 00:00:00 2001
From: Paul Romano <paul.k.rom...@gmail.com>
Date: Mon, 31 Aug 2015 10:11:44 +0700
Subject: [PATCH] FindHDF5: Fix HL compile line and add means of preferring
 parallel

The debian cmake-data package currently includes a patch that finds the correct
include directories and libraries when the HL or Fortran_HL components are
specified. This commit brings that patch upstream. Additionally, the
HDF5_PREFER_PARALLEL variable is introduced to resolve issue 0015527 whereby
there is no way to find a parallel HDF5 installation if both h5cc and h5pcc
appear on the user's PATH. Finally, when the Fortran_HL component is specified,
the hdf5_hl library is searched for.
---
 Modules/FindHDF5.cmake | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake
index 3bd6f1e..ec8b4a1 100644
--- a/Modules/FindHDF5.cmake
+++ b/Modules/FindHDF5.cmake
@@ -104,26 +104,49 @@ else()
 endif()
 
 # try to find the HDF5 wrapper compilers
-find_program( HDF5_C_COMPILER_EXECUTABLE
+if(HDF5_PREFER_PARALLEL)
+  find_program( HDF5_C_COMPILER_EXECUTABLE
+    NAMES h5pcc h5cc
+    HINTS ENV HDF5_ROOT
+    PATH_SUFFIXES bin Bin
+    DOC "HDF5 Wrapper compiler.  Used only to detect HDF5 compile flags." )
+  mark_as_advanced( HDF5_C_COMPILER_EXECUTABLE )
+
+  find_program( HDF5_CXX_COMPILER_EXECUTABLE
+    NAMES h5pc++ h5c++
+    HINTS ENV HDF5_ROOT
+    PATH_SUFFIXES bin Bin
+    DOC "HDF5 C++ Wrapper compiler.  Used only to detect HDF5 compile flags." )
+  mark_as_advanced( HDF5_CXX_COMPILER_EXECUTABLE )
+
+  find_program( HDF5_Fortran_COMPILER_EXECUTABLE
+    NAMES h5pfc h5fc
+    HINTS ENV HDF5_ROOT
+    PATH_SUFFIXES bin Bin
+    DOC "HDF5 Fortran Wrapper compiler.  Used only to detect HDF5 compile flags." )
+  mark_as_advanced( HDF5_Fortran_COMPILER_EXECUTABLE )
+else()
+  find_program( HDF5_C_COMPILER_EXECUTABLE
     NAMES h5cc h5pcc
     HINTS ENV HDF5_ROOT
     PATH_SUFFIXES bin Bin
     DOC "HDF5 Wrapper compiler.  Used only to detect HDF5 compile flags." )
-mark_as_advanced( HDF5_C_COMPILER_EXECUTABLE )
+  mark_as_advanced( HDF5_C_COMPILER_EXECUTABLE )
 
-find_program( HDF5_CXX_COMPILER_EXECUTABLE
+  find_program( HDF5_CXX_COMPILER_EXECUTABLE
     NAMES h5c++ h5pc++
     HINTS ENV HDF5_ROOT
     PATH_SUFFIXES bin Bin
     DOC "HDF5 C++ Wrapper compiler.  Used only to detect HDF5 compile flags." )
-mark_as_advanced( HDF5_CXX_COMPILER_EXECUTABLE )
+  mark_as_advanced( HDF5_CXX_COMPILER_EXECUTABLE )
 
-find_program( HDF5_Fortran_COMPILER_EXECUTABLE
+  find_program( HDF5_Fortran_COMPILER_EXECUTABLE
     NAMES h5fc h5pfc
     HINTS ENV HDF5_ROOT
     PATH_SUFFIXES bin Bin
     DOC "HDF5 Fortran Wrapper compiler.  Used only to detect HDF5 compile flags." )
-mark_as_advanced( HDF5_Fortran_COMPILER_EXECUTABLE )
+  mark_as_advanced( HDF5_Fortran_COMPILER_EXECUTABLE )
+endif()
 
 find_program( HDF5_DIFF_EXECUTABLE
     NAMES h5diff
@@ -225,6 +248,8 @@ if( NOT HDF5_FOUND )
     _HDF5_invoke_compiler( C HDF5_C_COMPILE_LINE HDF5_C_RETURN_VALUE )
     _HDF5_invoke_compiler( CXX HDF5_CXX_COMPILE_LINE HDF5_CXX_RETURN_VALUE )
     _HDF5_invoke_compiler( Fortran HDF5_Fortran_COMPILE_LINE HDF5_Fortran_RETURN_VALUE )
+    set(HDF5_HL_COMPILE_LINE ${HDF5_C_COMPILE_LINE})
+    set(HDF5_Fortran_HL_COMPILE_LINE ${HDF5_Fortran_COMPILE_LINE})
 
     # seed the initial lists of libraries to find with items we know we need
     set( HDF5_C_LIBRARY_NAMES_INIT hdf5 )
@@ -232,7 +257,7 @@ if( NOT HDF5_FOUND )
     set( HDF5_CXX_LIBRARY_NAMES_INIT hdf5_cpp ${HDF5_C_LIBRARY_NAMES_INIT} )
     set( HDF5_Fortran_LIBRARY_NAMES_INIT hdf5_fortran
         ${HDF5_C_LIBRARY_NAMES_INIT} )
-    set( HDF5_Fortran_HL_LIBRARY_NAMES_INIT hdf5hl_fortran
+    set( HDF5_Fortran_HL_LIBRARY_NAMES_INIT hdf5hl_fortran hdf5_hl
         ${HDF5_Fortran_LIBRARY_NAMES_INIT} )
 
     foreach( LANGUAGE ${HDF5_LANGUAGE_BINDINGS} )
@@ -376,4 +401,3 @@ find_package_handle_standard_args( HDF5
     REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS
     VERSION_VAR   HDF5_VERSION
 )
-
-- 
2.1.4

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to