summaryrefslogtreecommitdiff
path: root/Modules/FindHDF5.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/FindHDF5.cmake')
-rw-r--r--Modules/FindHDF5.cmake193
1 files changed, 106 insertions, 87 deletions
diff --git a/Modules/FindHDF5.cmake b/Modules/FindHDF5.cmake
index 16764e083e..e1199a7d5b 100644
--- a/Modules/FindHDF5.cmake
+++ b/Modules/FindHDF5.cmake
@@ -340,71 +340,61 @@ macro( _HDF5_parse_compile_line
libraries
libraries_hl)
- # Match the include paths
- set( RE " -I *([^\" ]+|\"[^\"]+\")")
- string( REGEX MATCHALL "${RE}" include_path_flags "${${compile_line_var}}")
- foreach( IPATH IN LISTS include_path_flags )
- string( REGEX REPLACE "${RE}" "\\1" IPATH "${IPATH}" )
- list( APPEND ${include_paths} ${IPATH} )
- endforeach()
-
- # Match the definitions
- set( RE " -D([^ ]*)")
- string( REGEX MATCHALL "${RE}" definition_flags "${${compile_line_var}}" )
- foreach( DEF IN LISTS definition_flags )
- string( STRIP "${DEF}" DEF )
- list( APPEND ${definitions} ${DEF} )
- endforeach()
-
- # Match the library paths
- set( RE " -L *([^\" ]+|\"[^\"]+\")")
- string( REGEX MATCHALL "${RE}" library_path_flags "${${compile_line_var}}")
- foreach( LPATH IN LISTS library_path_flags )
- string( REGEX REPLACE "${RE}" "\\1" LPATH "${LPATH}" )
- list( APPEND ${library_paths} ${LPATH} )
- endforeach()
-
- # now search for the lib names specified in the compile line (match -l...)
- # match only -l's preceded by a space or comma
- set( RE " -l *([^\" ]+|\"[^\"]+\")")
- string( REGEX MATCHALL "${RE}" library_name_flags "${${compile_line_var}}")
- foreach( LNAME IN LISTS library_name_flags )
- string( REGEX REPLACE "${RE}" "\\1" LNAME "${LNAME}" )
- if(LNAME MATCHES ".*hl")
- list(APPEND ${libraries_hl} ${LNAME})
- else()
- list(APPEND ${libraries} ${LNAME})
- endif()
- endforeach()
+ if(UNIX)
+ separate_arguments(_HDF5_COMPILE_ARGS UNIX_COMMAND "${${compile_line_var}}")
+ else()
+ separate_arguments(_HDF5_COMPILE_ARGS WINDOWS_COMMAND "${${compile_line_var}}")
+ endif()
- # now search for full library paths with no flags
- set( RE " ([^\" ]+|\"[^\"]+\")")
- string( REGEX MATCHALL "${RE}" library_name_noflags "${${compile_line_var}}")
- foreach( LIB IN LISTS library_name_noflags )
- string( REGEX REPLACE "${RE}" "\\1" LIB "${LIB}" )
- get_filename_component(LIB "${LIB}" ABSOLUTE)
- if(NOT EXISTS ${LIB} OR IS_DIRECTORY ${LIB})
- continue()
- endif()
- get_filename_component(LPATH ${LIB} DIRECTORY)
- get_filename_component(LNAME ${LIB} NAME_WE)
- string( REGEX REPLACE "^lib" "" LNAME ${LNAME} )
- list( APPEND ${library_paths} ${LPATH} )
- if(LNAME MATCHES ".*hl")
- list(APPEND ${libraries_hl} ${LNAME})
- else()
- list(APPEND ${libraries} ${LNAME})
- endif()
- endforeach()
+ foreach(arg IN LISTS _HDF5_COMPILE_ARGS)
+ if("${arg}" MATCHES "^-I(.*)$")
+ # include directory
+ list(APPEND ${include_paths} "${CMAKE_MATCH_1}")
+ elseif("${arg}" MATCHES "^-D(.*)$")
+ # compile definition
+ list(APPEND ${definitions} "${CMAKE_MATCH_1}")
+ elseif("${arg}" MATCHES "^-L(.*)$")
+ # library search path
+ list(APPEND ${library_paths} "${CMAKE_MATCH_1}")
+ elseif("${arg}" MATCHES "^-l(hdf5.*hl.*)$")
+ # library name (hl)
+ list(APPEND ${libraries_hl} "${CMAKE_MATCH_1}")
+ elseif("${arg}" MATCHES "^-l(.*)$")
+ # library name
+ list(APPEND ${libraries} "${CMAKE_MATCH_1}")
+ elseif("${arg}" MATCHES "^(.:)?[/\\].*\\.(a|so|dylib|sl|lib)$")
+ # library file
+ if(NOT EXISTS "${arg}")
+ continue()
+ endif()
+ get_filename_component(_HDF5_LPATH "${arg}" DIRECTORY)
+ get_filename_component(_HDF5_LNAME "${arg}" NAME_WE)
+ string(REGEX REPLACE "^lib" "" _HDF5_LNAME "${_HDF5_LNAME}")
+ list(APPEND ${library_paths} "${_HDF5_LPATH}")
+ if(_HDF5_LNAME MATCHES "hdf5.*hl")
+ list(APPEND ${libraries_hl} "${_HDF5_LNAME}")
+ else()
+ list(APPEND ${libraries} "${_HDF5_LNAME}")
+ endif()
+ endif()
+ endforeach()
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})
@@ -439,8 +429,8 @@ if(NOT HDF5_FOUND AND NOT HDF5_ROOT)
set(HDF5_${_lang}_LIBRARY ${_lang_location} CACHE PATH
"HDF5 ${_lang} library" )
mark_as_advanced(HDF5_${_lang}_LIBRARY)
- list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARY})
- set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_LIBRARY})
+ list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix})
+ set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix})
set(HDF5_${_lang}_FOUND True)
endif()
if(FIND_HL)
@@ -449,8 +439,8 @@ if(NOT HDF5_FOUND AND NOT HDF5_ROOT)
set(HDF5_${_lang}_HL_LIBRARY ${_lang_hl_location} CACHE PATH
"HDF5 ${_lang} HL library" )
mark_as_advanced(HDF5_${_lang}_HL_LIBRARY)
- list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARY})
- set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARY})
+ list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix})
+ set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix})
set(HDF5_HL_FOUND True)
endif()
endif()
@@ -458,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
@@ -506,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)
@@ -526,15 +518,26 @@ if(NOT HDF5_FOUND AND NOT HDF5_ROOT)
)
set(HDF5_${__lang}_LIBRARIES)
- set(_HDF5_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
- if(HDF5_USE_STATIC_LIBRARIES)
- set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_STATIC_LIBRARY_SUFFIX})
- else()
- set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_SHARED_LIBRARY_SUFFIX})
- endif()
-
foreach(L IN LISTS HDF5_${__lang}_LIBRARY_NAMES)
- find_library(HDF5_${__lang}_LIBRARY_${L} ${L} ${HDF5_${__lang}_LIBRARY_DIRS})
+ set(_HDF5_SEARCH_NAMES_LOCAL)
+ if(x"${L}" MATCHES "hdf5")
+ # hdf5 library
+ set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS})
+ if(UNIX AND HDF5_USE_STATIC_LIBRARIES)
+ set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a)
+ endif()
+ else()
+ # external library
+ set(_HDF5_SEARCH_OPTS_LOCAL)
+ endif()
+ find_library(HDF5_${__lang}_LIBRARY_${L}
+ NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${L} NAMES_PER_DIR
+ HINTS ${HDF5_${__lang}_LIBRARY_DIRS}
+ ${HDF5_ROOT}
+ ${_HDF5_SEARCH_OPTS_LOCAL}
+ )
+ unset(_HDF5_SEARCH_OPTS_LOCAL)
+ unset(_HDF5_SEARCH_NAMES_LOCAL)
if(HDF5_${__lang}_LIBRARY_${L})
list(APPEND HDF5_${__lang}_LIBRARIES ${HDF5_${__lang}_LIBRARY_${L}})
else()
@@ -544,7 +547,25 @@ 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)
- find_library(HDF5_${__lang}_LIBRARY_${L} ${L} ${HDF5_${__lang}_LIBRARY_DIRS})
+ set(_HDF5_SEARCH_NAMES_LOCAL)
+ if("x${L}" MATCHES "hdf5")
+ # hdf5 library
+ set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS})
+ if(UNIX AND HDF5_USE_STATIC_LIBRARIES)
+ set(_HDF5_SEARCH_NAMES_LOCAL lib${L}.a)
+ endif()
+ else()
+ # external library
+ set(_HDF5_SEARCH_OPTS_LOCAL)
+ endif()
+ find_library(HDF5_${__lang}_LIBRARY_${L}
+ NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${L} NAMES_PER_DIR
+ HINTS ${HDF5_${__lang}_LIBRARY_DIRS}
+ ${HDF5_ROOT}
+ ${_HDF5_SEARCH_OPTS_LOCAL}
+ )
+ unset(_HDF5_SEARCH_OPTS_LOCAL)
+ unset(_HDF5_SEARCH_NAMES_LOCAL)
if(HDF5_${__lang}_LIBRARY_${L})
list(APPEND HDF5_${__lang}_HL_LIBRARIES ${HDF5_${__lang}_LIBRARY_${L}})
else()
@@ -554,8 +575,6 @@ if(NOT HDF5_FOUND AND NOT HDF5_ROOT)
set(HDF5_HL_FOUND True)
endif()
- set(CMAKE_FIND_LIBRARY_SUFFIXES ${_HDF5_CMAKE_FIND_LIBRARY_SUFFIXES})
-
set(HDF5_${__lang}_FOUND True)
mark_as_advanced(HDF5_${__lang}_DEFINITIONS)
mark_as_advanced(HDF5_${__lang}_INCLUDE_DIRS)
@@ -626,14 +645,11 @@ elseif(NOT HDF5_FOUND AND NOT _HDF5_NEED_TO_SEARCH)
endif()
endif()
-if(HDF5_ROOT)
- set(SEARCH_OPTS NO_DEFAULT_PATH)
-endif()
find_program( HDF5_DIFF_EXECUTABLE
NAMES h5diff
HINTS ${HDF5_ROOT}
PATH_SUFFIXES bin Bin
- ${SEARCH_OPTS}
+ ${_HDF5_SEARCH_OPTS}
DOC "HDF5 file differencing tool." )
mark_as_advanced( HDF5_DIFF_EXECUTABLE )
@@ -662,7 +678,7 @@ if( NOT HDF5_FOUND )
HINTS ${HDF5_ROOT}
PATHS $ENV{HOME}/.local/include
PATH_SUFFIXES include Include
- ${SEARCH_OPTS}
+ ${_HDF5_SEARCH_OPTS}
)
mark_as_advanced(HDF5_${LANGUAGE}_INCLUDE_DIR)
list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${__lang}_INCLUDE_DIR})
@@ -686,12 +702,12 @@ if( NOT HDF5_FOUND )
find_library(HDF5_${LIB}_LIBRARY_DEBUG
NAMES ${THIS_LIBRARY_SEARCH_DEBUG}
HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib
- ${SEARCH_OPTS}
+ ${_HDF5_SEARCH_OPTS}
)
find_library( HDF5_${LIB}_LIBRARY_RELEASE
NAMES ${THIS_LIBRARY_SEARCH_RELEASE}
HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib
- ${SEARCH_OPTS}
+ ${_HDF5_SEARCH_OPTS}
)
select_library_configurations( HDF5_${LIB} )
list(APPEND HDF5_${__lang}_LIBRARIES ${HDF5_${LIB}_LIBRARY})
@@ -723,12 +739,12 @@ if( NOT HDF5_FOUND )
find_library(HDF5_${LIB}_LIBRARY_DEBUG
NAMES ${THIS_LIBRARY_SEARCH_DEBUG}
HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib
- ${SEARCH_OPTS}
+ ${_HDF5_SEARCH_OPTS}
)
find_library( HDF5_${LIB}_LIBRARY_RELEASE
NAMES ${THIS_LIBRARY_SEARCH_RELEASE}
HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib
- ${SEARCH_OPTS}
+ ${_HDF5_SEARCH_OPTS}
)
select_library_configurations( HDF5_${LIB} )
list(APPEND HDF5_${__lang}_HL_LIBRARIES ${HDF5_${LIB}_LIBRARY})
@@ -780,17 +796,18 @@ if( NOT HDF5_FOUND )
"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()
set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS)
if(FIND_HL)
list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES)
endif()
endif()
+# 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()
+
# If HDF5_REQUIRED_VARS is empty at this point, then it's likely that
# something external is trying to explicitly pass already found
# locations
@@ -803,3 +820,5 @@ find_package_handle_standard_args(HDF5
VERSION_VAR HDF5_VERSION
HANDLE_COMPONENTS
)
+
+unset(_HDF5_SEARCH_OPTS)