|
|
@@ -9,10 +9,9 @@
|
|
|
# The module will optionally accept the COMPONENTS argument. If no COMPONENTS
|
|
|
# are specified, then the find module will default to finding only the HDF5 C
|
|
|
# library. If one or more COMPONENTS are specified, the module will attempt to
|
|
|
-# find the language bindings for the specified components. Currently, the only
|
|
|
-# valid components are C and CXX. The module does not yet support finding the
|
|
|
-# Fortran bindings. If the COMPONENTS argument is not given, the module will
|
|
|
-# attempt to find only the C bindings.
|
|
|
+# find the language bindings for the specified components. The only valid
|
|
|
+# components are C, CXX, Fortran, and HL. If the COMPONENTS argument is not
|
|
|
+# given, the module will attempt to find only the C bindings.
|
|
|
#
|
|
|
# On UNIX systems, this module will read the variable HDF5_USE_STATIC_LIBRARIES
|
|
|
# to determine whether or not to prefer a static link to a dynamic link for HDF5
|
|
|
@@ -33,12 +32,15 @@
|
|
|
# HDF5_DEFINITIONS - Required compiler definitions for HDF5
|
|
|
# HDF5_C_LIBRARIES - Required libraries for the HDF5 C bindings.
|
|
|
# HDF5_CXX_LIBRARIES - Required libraries for the HDF5 C++ bindings
|
|
|
+# HDF5_Fortran_LIBRARIES - Required libraries for the HDF5 Fortran bindings
|
|
|
+# HDF5_HL_LIBRARIES - Required libraries for the HDF5 high level API
|
|
|
# HDF5_LIBRARIES - Required libraries for all requested bindings
|
|
|
# HDF5_FOUND - true if HDF5 was found on the system
|
|
|
# HDF5_LIBRARY_DIRS - the full set of library directories
|
|
|
# HDF5_IS_PARALLEL - Whether or not HDF5 was found with parallel IO support
|
|
|
# HDF5_C_COMPILER_EXECUTABLE - the path to the HDF5 C wrapper compiler
|
|
|
# HDF5_CXX_COMPILER_EXECUTABLE - the path to the HDF5 C++ wrapper compiler
|
|
|
+# HDF5_Fortran_COMPILER_EXECUTABLE - the path to the HDF5 Fortran wrapper compiler
|
|
|
# HDF5_DIFF_EXECUTABLE - the path to the HDF5 dataset comparison tool
|
|
|
|
|
|
#=============================================================================
|
|
|
@@ -63,8 +65,26 @@ include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
|
|
|
set( HDF5_VALID_COMPONENTS
|
|
|
C
|
|
|
CXX
|
|
|
+ Fortran
|
|
|
+ HL
|
|
|
)
|
|
|
|
|
|
+# Validate the list of find components.
|
|
|
+if( NOT HDF5_FIND_COMPONENTS )
|
|
|
+ set( HDF5_LANGUAGE_BINDINGS "C" )
|
|
|
+else()
|
|
|
+ # add the extra specified components, ensuring that they are valid.
|
|
|
+ foreach( component ${HDF5_FIND_COMPONENTS} )
|
|
|
+ list( FIND HDF5_VALID_COMPONENTS ${component} component_location )
|
|
|
+ if( ${component_location} EQUAL -1 )
|
|
|
+ message( FATAL_ERROR
|
|
|
+ "\"${component}\" is not a valid HDF5 component." )
|
|
|
+ else()
|
|
|
+ list( APPEND HDF5_LANGUAGE_BINDINGS ${component} )
|
|
|
+ endif()
|
|
|
+ endforeach()
|
|
|
+endif()
|
|
|
+
|
|
|
# try to find the HDF5 wrapper compilers
|
|
|
find_program( HDF5_C_COMPILER_EXECUTABLE
|
|
|
NAMES h5cc h5pcc
|
|
|
@@ -80,6 +100,13 @@ find_program( HDF5_CXX_COMPILER_EXECUTABLE
|
|
|
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 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 )
|
|
|
+
|
|
|
find_program( HDF5_DIFF_EXECUTABLE
|
|
|
NAMES h5diff
|
|
|
HINTS ENV HDF5_ROOT
|
|
|
@@ -152,31 +179,39 @@ macro( _HDF5_parse_compile_line
|
|
|
endforeach()
|
|
|
endmacro()
|
|
|
|
|
|
-if( HDF5_INCLUDE_DIRS AND HDF5_LIBRARIES )
|
|
|
- # Do nothing: we already have HDF5_INCLUDE_PATH and HDF5_LIBRARIES in the
|
|
|
- # cache, it would be a shame to override them
|
|
|
-else()
|
|
|
- _HDF5_invoke_compiler( C HDF5_C_COMPILE_LINE HDF5_C_RETURN_VALUE )
|
|
|
- _HDF5_invoke_compiler( CXX HDF5_CXX_COMPILE_LINE HDF5_CXX_RETURN_VALUE )
|
|
|
-
|
|
|
- if( NOT HDF5_FIND_COMPONENTS )
|
|
|
- set( HDF5_LANGUAGE_BINDINGS "C" )
|
|
|
- else()
|
|
|
- # add the extra specified components, ensuring that they are valid.
|
|
|
- foreach( component ${HDF5_FIND_COMPONENTS} )
|
|
|
- list( FIND HDF5_VALID_COMPONENTS ${component} component_location )
|
|
|
- if( ${component_location} EQUAL -1 )
|
|
|
- message( FATAL_ERROR
|
|
|
- "\"${component}\" is not a valid HDF5 component." )
|
|
|
- else()
|
|
|
- list( APPEND HDF5_LANGUAGE_BINDINGS ${component} )
|
|
|
+# Try to find HDF5 using an installed hdf5-config.cmake
|
|
|
+if( NOT HDF5_FOUND )
|
|
|
+ find_package( HDF5 QUIET NO_MODULE )
|
|
|
+ if( HDF5_FOUND )
|
|
|
+ set( HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR} )
|
|
|
+ set( HDF5_LIBRARIES )
|
|
|
+ set( HDF5_C_TARGET hdf5 )
|
|
|
+ set( HDF5_CXX_TARGET hdf5_cpp )
|
|
|
+ set( HDF5_HL_TARGET hdf5_hl )
|
|
|
+ set( HDF5_Fortran_TARGET hdf5_fortran )
|
|
|
+ foreach( _component ${HDF5_LANGUAGE_BINDINGS} )
|
|
|
+ list( FIND HDF5_VALID_COMPONENTS ${_component} _component_location )
|
|
|
+ get_target_property( _comp_location ${HDF5_${_component}_TARGET} LOCATION )
|
|
|
+ if( _comp_location )
|
|
|
+ set( HDF5_${_component}_LIBRARY ${_comp_location} CACHE PATH
|
|
|
+ "HDF5 ${_component} library" )
|
|
|
+ mark_as_advanced( HDF5_${_component}_LIBRARY )
|
|
|
+ list( APPEND HDF5_LIBRARIES ${HDF5_${_component}_LIBRARY} )
|
|
|
endif()
|
|
|
endforeach()
|
|
|
endif()
|
|
|
-
|
|
|
+endif()
|
|
|
+
|
|
|
+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 )
|
|
|
+
|
|
|
# seed the initial lists of libraries to find with items we know we need
|
|
|
- set( HDF5_C_LIBRARY_NAMES_INIT hdf5_hl hdf5 )
|
|
|
+ set( HDF5_C_LIBRARY_NAMES_INIT hdf5 )
|
|
|
+ set( HDF5_HL_LIBRARY_NAMES_INIT hdf5_hl ${HDF5_C_LIBRARY_NAMES_INIT} )
|
|
|
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} )
|
|
|
|
|
|
foreach( LANGUAGE ${HDF5_LANGUAGE_BINDINGS} )
|
|
|
if( HDF5_${LANGUAGE}_COMPILE_LINE )
|
|
|
@@ -198,7 +233,13 @@ else()
|
|
|
list( APPEND HDF5_DEFINITIONS ${HDF5_${LANGUAGE}_DEFINITIONS} )
|
|
|
|
|
|
# find the HDF5 include directories
|
|
|
- find_path( HDF5_${LANGUAGE}_INCLUDE_DIR hdf5.h
|
|
|
+ if(${LANGUAGE} STREQUAL "Fortran")
|
|
|
+ set(HDF5_INCLUDE_FILENAME hdf5.mod)
|
|
|
+ else()
|
|
|
+ set(HDF5_INCLUDE_FILENAME hdf5.h)
|
|
|
+ endif()
|
|
|
+
|
|
|
+ find_path( HDF5_${LANGUAGE}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME}
|
|
|
HINTS
|
|
|
${HDF5_${LANGUAGE}_INCLUDE_FLAGS}
|
|
|
ENV
|
|
|
@@ -266,26 +307,41 @@ else()
|
|
|
|
|
|
# We may have picked up some duplicates in various lists during the above
|
|
|
# process for the language bindings (both the C and C++ bindings depend on
|
|
|
- # libz for example). Remove the duplicates.
|
|
|
+ # libz for example). Remove the duplicates. It appears that the default
|
|
|
+ # CMake behavior is to remove duplicates from the end of a list. However,
|
|
|
+ # for link lines, this is incorrect since unresolved symbols are searched
|
|
|
+ # for down the link line. Therefore, we reverse the list, remove the
|
|
|
+ # duplicates, and then reverse it again to get the duplicates removed from
|
|
|
+ # the beginning.
|
|
|
+ macro( _remove_duplicates_from_beginning _list_name )
|
|
|
+ list( REVERSE ${_list_name} )
|
|
|
+ list( REMOVE_DUPLICATES ${_list_name} )
|
|
|
+ list( REVERSE ${_list_name} )
|
|
|
+ endmacro()
|
|
|
+
|
|
|
if( HDF5_INCLUDE_DIRS )
|
|
|
- list( REMOVE_DUPLICATES HDF5_INCLUDE_DIRS )
|
|
|
+ _remove_duplicates_from_beginning( HDF5_INCLUDE_DIRS )
|
|
|
endif()
|
|
|
if( HDF5_LIBRARIES_DEBUG )
|
|
|
- list( REMOVE_DUPLICATES HDF5_LIBRARIES_DEBUG )
|
|
|
+ _remove_duplicates_from_beginning( HDF5_LIBRARIES_DEBUG )
|
|
|
endif()
|
|
|
if( HDF5_LIBRARIES_RELEASE )
|
|
|
- list( REMOVE_DUPLICATES HDF5_LIBRARIES_RELEASE )
|
|
|
+ _remove_duplicates_from_beginning( HDF5_LIBRARIES_RELEASE )
|
|
|
endif()
|
|
|
if( HDF5_LIBRARY_DIRS )
|
|
|
- list( REMOVE_DUPLICATES HDF5_LIBRARY_DIRS )
|
|
|
+ _remove_duplicates_from_beginning( HDF5_LIBRARY_DIRS )
|
|
|
endif()
|
|
|
|
|
|
# Construct the complete list of HDF5 libraries with debug and optimized
|
|
|
# variants when the generator supports them.
|
|
|
if( CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE )
|
|
|
- set( HDF5_LIBRARIES
|
|
|
- debug ${HDF5_LIBRARIES_DEBUG}
|
|
|
- optimized ${HDF5_LIBRARIES_RELEASE} )
|
|
|
+ set( HDF5_LIBRARIES )
|
|
|
+ foreach( _lib ${HDF5_LIBRARIES_DEBUG} )
|
|
|
+ list( APPEND HDF5_LIBRARIES debug ${_lib} )
|
|
|
+ endforeach()
|
|
|
+ foreach( _lib ${HDF5_LIBRARIES_RELEASE} )
|
|
|
+ list( APPEND HDF5_LIBRARIES optimized ${_lib} )
|
|
|
+ endforeach()
|
|
|
else()
|
|
|
set( HDF5_LIBRARIES ${HDF5_LIBRARIES_RELEASE} )
|
|
|
endif()
|
|
|
@@ -307,6 +363,12 @@ else()
|
|
|
"HDF5 library compiled with parallel IO support" )
|
|
|
mark_as_advanced( HDF5_IS_PARALLEL )
|
|
|
|
|
|
+ # For backwards compatibility we set HDF5_INCLUDE_DIR to the value of
|
|
|
+ # HDF5_INCLUDE_DIRS
|
|
|
+ if( HDF5_INCLUDE_DIRS )
|
|
|
+ set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" )
|
|
|
+ endif()
|
|
|
+
|
|
|
endif()
|
|
|
|
|
|
find_package_handle_standard_args( HDF5 DEFAULT_MSG
|
|
|
@@ -314,15 +376,3 @@ find_package_handle_standard_args( HDF5 DEFAULT_MSG
|
|
|
HDF5_INCLUDE_DIRS
|
|
|
)
|
|
|
|
|
|
-mark_as_advanced(
|
|
|
- HDF5_INCLUDE_DIRS
|
|
|
- HDF5_LIBRARIES
|
|
|
- HDF5_DEFINTIONS
|
|
|
- HDF5_LIBRARY_DIRS
|
|
|
- HDF5_C_COMPILER_EXECUTABLE
|
|
|
- HDF5_CXX_COMPILER_EXECUTABLE )
|
|
|
-
|
|
|
-# For backwards compatibility we set HDF5_INCLUDE_DIR to the value of
|
|
|
-# HDF5_INCLUDE_DIRS
|
|
|
-set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" )
|
|
|
-
|