Merge topic 'cpack-innosetup-linux'
[kiteware-cmake.git] / Modules / FindHDF5.cmake
blob1df33a815f6326151ec47f0edd08344747c9d419
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
5 FindHDF5
6 --------
8 Find Hierarchical Data Format (HDF5), a library for reading and writing
9 self describing array data.
12 This module invokes the ``HDF5`` wrapper compiler that should be installed
13 alongside ``HDF5``.  Depending upon the ``HDF5`` Configuration, the wrapper
14 compiler is called either ``h5cc`` or ``h5pcc``.  If this succeeds, the module
15 will then call the compiler with the show argument to see what flags
16 are used when compiling an ``HDF5`` client application.
18 The module will optionally accept the ``COMPONENTS`` argument.  If no
19 ``COMPONENTS`` are specified, then the find module will default to finding
20 only the ``HDF5`` C library.  If one or more ``COMPONENTS`` are specified, the
21 module will attempt to find the language bindings for the specified
22 components.  The valid components are ``C``, ``CXX``, ``Fortran``, ``HL``.
23 ``HL`` refers to the "high-level" HDF5 functions for C and Fortran.
24 If the ``COMPONENTS`` argument is not given, the module will
25 attempt to find only the C bindings.
26 For example, to use Fortran HDF5 and HDF5-HL functions, do:
27 ``find_package(HDF5 COMPONENTS Fortran HL)``.
29 This module will read the variable
30 ``HDF5_USE_STATIC_LIBRARIES`` to determine whether or not to prefer a
31 static link to a dynamic link for ``HDF5`` and all of it's dependencies.
32 To use this feature, make sure that the ``HDF5_USE_STATIC_LIBRARIES``
33 variable is set before the call to find_package.
35 .. versionadded:: 3.10
36   Support for ``HDF5_USE_STATIC_LIBRARIES`` on Windows.
38 Both the serial and parallel ``HDF5`` wrappers are considered and the first
39 directory to contain either one will be used.  In the event that both appear
40 in the same directory the serial version is preferentially selected. This
41 behavior can be reversed by setting the variable ``HDF5_PREFER_PARALLEL`` to
42 ``TRUE``.
44 In addition to finding the includes and libraries required to compile
45 an ``HDF5`` client application, this module also makes an effort to find
46 tools that come with the ``HDF5`` distribution that may be useful for
47 regression testing.
49 Result Variables
50 ^^^^^^^^^^^^^^^^
52 This module will set the following variables in your project:
54 ``HDF5_FOUND``
55   HDF5 was found on the system
56 ``HDF5_VERSION``
57   .. versionadded:: 3.3
58     HDF5 library version
59 ``HDF5_INCLUDE_DIRS``
60   Location of the HDF5 header files
61 ``HDF5_DEFINITIONS``
62   Required compiler definitions for HDF5
63 ``HDF5_LIBRARIES``
64   Required libraries for all requested bindings
65 ``HDF5_HL_LIBRARIES``
66   Required libraries for the HDF5 high level API for all bindings,
67   if the ``HL`` component is enabled
69 Available components are: ``C`` ``CXX`` ``Fortran`` and ``HL``.
70 For each enabled language binding, a corresponding ``HDF5_${LANG}_LIBRARIES``
71 variable, and potentially ``HDF5_${LANG}_DEFINITIONS``, will be defined.
72 If the ``HL`` component is enabled, then an ``HDF5_${LANG}_HL_LIBRARIES`` will
73 also be defined.  With all components enabled, the following variables will be defined:
75 ``HDF5_C_DEFINITIONS``
76   Required compiler definitions for HDF5 C bindings
77 ``HDF5_CXX_DEFINITIONS``
78   Required compiler definitions for HDF5 C++ bindings
79 ``HDF5_Fortran_DEFINITIONS``
80   Required compiler definitions for HDF5 Fortran bindings
81 ``HDF5_C_INCLUDE_DIRS``
82   Required include directories for HDF5 C bindings
83 ``HDF5_CXX_INCLUDE_DIRS``
84   Required include directories for HDF5 C++ bindings
85 ``HDF5_Fortran_INCLUDE_DIRS``
86   Required include directories for HDF5 Fortran bindings
87 ``HDF5_C_LIBRARIES``
88   Required libraries for the HDF5 C bindings
89 ``HDF5_CXX_LIBRARIES``
90   Required libraries for the HDF5 C++ bindings
91 ``HDF5_Fortran_LIBRARIES``
92   Required libraries for the HDF5 Fortran bindings
93 ``HDF5_C_HL_LIBRARIES``
94   Required libraries for the high level C bindings
95 ``HDF5_CXX_HL_LIBRARIES``
96   Required libraries for the high level C++ bindings
97 ``HDF5_Fortran_HL_LIBRARIES``
98   Required libraries for the high level Fortran bindings.
100 ``HDF5_IS_PARALLEL``
101   HDF5 library has parallel IO support
102 ``HDF5_C_COMPILER_EXECUTABLE``
103   path to the HDF5 C wrapper compiler
104 ``HDF5_CXX_COMPILER_EXECUTABLE``
105   path to the HDF5 C++ wrapper compiler
106 ``HDF5_Fortran_COMPILER_EXECUTABLE``
107   path to the HDF5 Fortran wrapper compiler
108 ``HDF5_C_COMPILER_EXECUTABLE_NO_INTERROGATE``
109   path to the primary C compiler which is also the HDF5 wrapper
110 ``HDF5_CXX_COMPILER_EXECUTABLE_NO_INTERROGATE``
111   path to the primary C++ compiler which is also the HDF5 wrapper
112 ``HDF5_Fortran_COMPILER_EXECUTABLE_NO_INTERROGATE``
113   path to the primary Fortran compiler which is also the HDF5 wrapper
114 ``HDF5_DIFF_EXECUTABLE``
115   path to the HDF5 dataset comparison tool
117 With all components enabled, the following targets will be defined:
119 ``HDF5::HDF5``
120   All detected ``HDF5_LIBRARIES``.
121 ``hdf5::hdf5``
122   C library.
123 ``hdf5::hdf5_cpp``
124   C++ library.
125 ``hdf5::hdf5_fortran``
126   Fortran library.
127 ``hdf5::hdf5_hl``
128   High-level C library.
129 ``hdf5::hdf5_hl_cpp``
130   High-level C++ library.
131 ``hdf5::hdf5_hl_fortran``
132   High-level Fortran library.
133 ``hdf5::h5diff``
134   ``h5diff`` executable.
136 Hints
137 ^^^^^
139 The following variables can be set to guide the search for HDF5 libraries and includes:
141 ``HDF5_PREFER_PARALLEL``
142   .. versionadded:: 3.4
144   set ``true`` to prefer parallel HDF5 (by default, serial is preferred)
146 ``HDF5_FIND_DEBUG``
147   .. versionadded:: 3.9
149   Set ``true`` to get extra debugging output.
151 ``HDF5_NO_FIND_PACKAGE_CONFIG_FILE``
152   .. versionadded:: 3.8
154   Set ``true`` to skip trying to find ``hdf5-config.cmake``.
155 #]=======================================================================]
157 include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
158 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
160 cmake_policy(PUSH)
161 cmake_policy(SET CMP0159 NEW) # file(STRINGS) with REGEX updates CMAKE_MATCH_<n>
163 # We haven't found HDF5 yet. Clear its state in case it is set in the parent
164 # scope somewhere else. We can't rely on it because different components may
165 # have been requested for this call.
166 set(HDF5_FOUND OFF)
167 set(HDF5_LIBRARIES)
168 set(HDF5_HL_LIBRARIES)
170 # List of the valid HDF5 components
171 set(HDF5_VALID_LANGUAGE_BINDINGS C CXX Fortran)
173 # Validate the list of find components.
174 if(NOT HDF5_FIND_COMPONENTS)
175   set(HDF5_LANGUAGE_BINDINGS "C")
176 else()
177   set(HDF5_LANGUAGE_BINDINGS)
178   # add the extra specified components, ensuring that they are valid.
179   set(HDF5_FIND_HL OFF)
180   foreach(_component IN LISTS HDF5_FIND_COMPONENTS)
181     list(FIND HDF5_VALID_LANGUAGE_BINDINGS ${_component} _component_location)
182     if(NOT _component_location EQUAL -1)
183       list(APPEND HDF5_LANGUAGE_BINDINGS ${_component})
184     elseif(_component STREQUAL "HL")
185       set(HDF5_FIND_HL ON)
186     elseif(_component STREQUAL "Fortran_HL") # only for compatibility
187       list(APPEND HDF5_LANGUAGE_BINDINGS Fortran)
188       set(HDF5_FIND_HL ON)
189       set(HDF5_FIND_REQUIRED_Fortran_HL FALSE)
190       set(HDF5_FIND_REQUIRED_Fortran TRUE)
191       set(HDF5_FIND_REQUIRED_HL TRUE)
192     else()
193       message(FATAL_ERROR "${_component} is not a valid HDF5 component.")
194     endif()
195   endforeach()
196   unset(_component)
197   unset(_component_location)
198   if(NOT HDF5_LANGUAGE_BINDINGS)
199     get_property(_langs GLOBAL PROPERTY ENABLED_LANGUAGES)
200     foreach(_lang IN LISTS _langs)
201       if(_lang MATCHES "^(C|CXX|Fortran)$")
202         list(APPEND HDF5_LANGUAGE_BINDINGS ${_lang})
203       endif()
204     endforeach()
205   endif()
206   list(REMOVE_ITEM HDF5_FIND_COMPONENTS Fortran_HL) # replaced by Fortran and HL
207   list(REMOVE_DUPLICATES HDF5_LANGUAGE_BINDINGS)
208 endif()
210 # Determine whether to search for serial or parallel executable first
211 if(HDF5_PREFER_PARALLEL)
212   set(HDF5_C_COMPILER_NAMES h5pcc h5cc)
213   set(HDF5_CXX_COMPILER_NAMES h5pc++ h5c++)
214   set(HDF5_Fortran_COMPILER_NAMES h5pfc h5fc)
215 else()
216   set(HDF5_C_COMPILER_NAMES h5cc h5pcc)
217   set(HDF5_CXX_COMPILER_NAMES h5c++ h5pc++)
218   set(HDF5_Fortran_COMPILER_NAMES h5fc h5pfc)
219 endif()
221 # Test first if the current compilers automatically wrap HDF5
222 function(_HDF5_test_regular_compiler_C success version is_parallel)
223   if(NOT ${success} OR
224      NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c)
225     file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}"
226       "#include <hdf5.h>\n"
227       "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n"
228       "#ifdef H5_HAVE_PARALLEL\n"
229       "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n"
230       "#endif\n"
231       "int main(int argc, char **argv) {\n"
232       "  int require = 0;\n"
233       "  require += info_ver[argc];\n"
234       "#ifdef H5_HAVE_PARALLEL\n"
235       "  require += info_parallel[argc];\n"
236       "#endif\n"
237       "  hid_t fid;\n"
238       "  fid = H5Fcreate(\"foo.h5\",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);\n"
239       "  return 0;\n"
240       "}")
241     try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}"
242       COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_c
243     )
244   endif()
245   if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_c)
246     file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_c INFO_STRINGS
247       REGEX "^INFO:"
248     )
249     string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?"
250       INFO_VER "${INFO_STRINGS}"
251     )
252     set(${version} ${CMAKE_MATCH_1})
253     if(CMAKE_MATCH_3)
254       set(${version} ${HDF5_C_VERSION}.${CMAKE_MATCH_3})
255     endif()
256     set(${version} ${${version}} PARENT_SCOPE)
258     if(INFO_STRINGS MATCHES "INFO:PARALLEL")
259       set(${is_parallel} TRUE PARENT_SCOPE)
260     else()
261       set(${is_parallel} FALSE PARENT_SCOPE)
262     endif()
263   endif()
264 endfunction()
266 function(_HDF5_test_regular_compiler_CXX success version is_parallel)
267   if(NOT ${success} OR
268      NOT EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx)
269     file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}"
270       "#include <H5Cpp.h>\n"
271       "#ifndef H5_NO_NAMESPACE\n"
272       "using namespace H5;\n"
273       "#endif\n"
274       "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n"
275       "#ifdef H5_HAVE_PARALLEL\n"
276       "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\n"
277       "#endif\n"
278       "int main(int argc, char **argv) {\n"
279       "  int require = 0;\n"
280       "  require += info_ver[argc];\n"
281       "#ifdef H5_HAVE_PARALLEL\n"
282       "  require += info_parallel[argc];\n"
283       "#endif\n"
284       "  H5File file(\"foo.h5\", H5F_ACC_TRUNC);\n"
285       "  return 0;\n"
286       "}")
287     try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}"
288       COPY_FILE ${_HDF5_TEST_DIR}/compiler_has_h5_cxx
289     )
290   endif()
291   if(${success} AND EXISTS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx)
292     file(STRINGS ${_HDF5_TEST_DIR}/compiler_has_h5_cxx INFO_STRINGS
293       REGEX "^INFO:"
294     )
295     string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?"
296       INFO_VER "${INFO_STRINGS}"
297     )
298     set(${version} ${CMAKE_MATCH_1})
299     if(CMAKE_MATCH_3)
300       set(${version} ${HDF5_CXX_VERSION}.${CMAKE_MATCH_3})
301     endif()
302     set(${version} ${${version}} PARENT_SCOPE)
304     if(INFO_STRINGS MATCHES "INFO:PARALLEL")
305       set(${is_parallel} TRUE PARENT_SCOPE)
306     else()
307       set(${is_parallel} FALSE PARENT_SCOPE)
308     endif()
309   endif()
310 endfunction()
312 function(_HDF5_test_regular_compiler_Fortran success is_parallel)
313   if(NOT ${success})
314     file(WRITE "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}"
315       "program hdf5_hello\n"
316       "  use hdf5\n"
317       "  integer error\n"
318       "  call h5open_f(error)\n"
319       "  call h5close_f(error)\n"
320       "end\n")
321     try_compile(${success} SOURCES "${_HDF5_TEST_DIR}/${_HDF5_TEST_SRC}")
322     if(${success})
323       execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -showconfig
324         OUTPUT_VARIABLE config_output
325         ERROR_VARIABLE config_error
326         RESULT_VARIABLE config_result
327         )
328       if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)")
329         # The value may be anything used when HDF5 was configured,
330         # so see if CMake interprets it as "true".
331         set(parallelHDF5 "${CMAKE_MATCH_1}")
332         if(parallelHDF5)
333           set(${is_parallel} TRUE PARENT_SCOPE)
334         else()
335           set(${is_parallel} FALSE PARENT_SCOPE)
336         endif()
337       else()
338         set(${is_parallel} FALSE PARENT_SCOPE)
339       endif()
340     endif()
341   endif()
342 endfunction()
344 # Invoke the HDF5 wrapper compiler.  The compiler return value is stored to the
345 # return_value argument, the text output is stored to the output variable.
346 function( _HDF5_invoke_compiler language output_var return_value_var version_var is_parallel_var)
347   set(is_parallel FALSE)
348   if(HDF5_USE_STATIC_LIBRARIES)
349     set(lib_type_args -noshlib)
350   else()
351     set(lib_type_args -shlib)
352   endif()
353   # Verify that the compiler wrapper can actually compile: sometimes the compiler
354   # wrapper exists, but not the compiler.  E.g. Miniconda / Anaconda Python
355   execute_process(
356     COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} "${_HDF5_TEST_SRC}"
357     WORKING_DIRECTORY ${_HDF5_TEST_DIR}
358     OUTPUT_VARIABLE output
359     ERROR_VARIABLE output
360     RESULT_VARIABLE return_value
361     )
362   if(NOT return_value EQUAL 0)
363     message(CONFIGURE_LOG
364       "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.\n\n${output}")
365     if(NOT HDF5_FIND_QUIETLY)
366       message(STATUS
367         "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.")
368     endif()
369   else()
370     execute_process(
371       COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -show ${lib_type_args} "${_HDF5_TEST_SRC}"
372       WORKING_DIRECTORY ${_HDF5_TEST_DIR}
373       OUTPUT_VARIABLE output
374       ERROR_VARIABLE output
375       RESULT_VARIABLE return_value
376       OUTPUT_STRIP_TRAILING_WHITESPACE
377       )
378     if(NOT return_value EQUAL 0)
379       message(CONFIGURE_LOG
380         "Unable to determine HDF5 ${language} flags from HDF5 wrapper.\n\n${output}")
381       if(NOT HDF5_FIND_QUIETLY)
382         message(STATUS
383           "Unable to determine HDF5 ${language} flags from HDF5 wrapper.")
384       endif()
385     endif()
386     execute_process(
387       COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} -showconfig
388       OUTPUT_VARIABLE config_output
389       ERROR_VARIABLE config_output
390       RESULT_VARIABLE return_value
391       OUTPUT_STRIP_TRAILING_WHITESPACE
392       )
393     if(NOT return_value EQUAL 0)
394       message(CONFIGURE_LOG
395         "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.\n\n${output}")
396       if(NOT HDF5_FIND_QUIETLY)
397         message(STATUS
398           "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.")
399       endif()
400     endif()
401     string(REGEX MATCH "HDF5 Version: ([a-zA-Z0-9\\.\\-]*)" version "${config_output}")
402     if(version)
403       string(REPLACE "HDF5 Version: " "" version "${version}")
404       string(REPLACE "-patch" "." version "${version}")
405     endif()
406     if(config_output MATCHES "Parallel HDF5: ([A-Za-z0-9]+)")
407       # The value may be anything used when HDF5 was configured,
408       # so see if CMake interprets it as "true".
409       set(parallelHDF5 "${CMAKE_MATCH_1}")
410       if(parallelHDF5)
411         set(is_parallel TRUE)
412       endif()
413     endif()
414   endif()
415   foreach(var output return_value version is_parallel)
416     set(${${var}_var} ${${var}} PARENT_SCOPE)
417   endforeach()
418 endfunction()
420 # Parse a compile line for definitions, includes, library paths, and libraries.
421 function(_HDF5_parse_compile_line compile_line_var include_paths definitions
422     library_paths libraries libraries_hl)
424   separate_arguments(_compile_args NATIVE_COMMAND "${${compile_line_var}}")
426   foreach(_arg IN LISTS _compile_args)
427     if("${_arg}" MATCHES "^-I(.*)$")
428       # include directory
429       list(APPEND include_paths "${CMAKE_MATCH_1}")
430     elseif("${_arg}" MATCHES "^-D(.*)$")
431       # compile definition
432       list(APPEND definitions "-D${CMAKE_MATCH_1}")
433     elseif("${_arg}" MATCHES "^-L(.*)$")
434       # library search path
435       list(APPEND library_paths "${CMAKE_MATCH_1}")
436     elseif("${_arg}" MATCHES "^-l(hdf5.*hl.*)$")
437       # library name (hl)
438       list(APPEND libraries_hl "${CMAKE_MATCH_1}")
439     elseif("${_arg}" MATCHES "^-l(.*)$")
440       # library name
441       list(APPEND libraries "${CMAKE_MATCH_1}")
442     elseif("${_arg}" MATCHES "^(.:)?[/\\].*\\.(a|so|dylib|sl|lib)$")
443       # library file
444       if(NOT EXISTS "${_arg}")
445         continue()
446       endif()
447       get_filename_component(_lpath "${_arg}" DIRECTORY)
448       get_filename_component(_lname "${_arg}" NAME_WE)
449       string(REGEX REPLACE "^lib" "" _lname "${_lname}")
450       list(APPEND library_paths "${_lpath}")
451       if(_lname MATCHES "hdf5.*hl")
452         list(APPEND libraries_hl "${_lname}")
453       else()
454         list(APPEND libraries "${_lname}")
455       endif()
456     endif()
457   endforeach()
458   foreach(var include_paths definitions library_paths libraries libraries_hl)
459     set(${${var}_var} ${${var}} PARENT_SCOPE)
460   endforeach()
461 endfunction()
463 # Select a preferred imported configuration from a target
464 function(_HDF5_select_imported_config target imported_conf)
465     # We will first assign the value to a local variable _imported_conf, then assign
466     # it to the function argument at the end.
467     get_target_property(_imported_conf ${target} MAP_IMPORTED_CONFIG_${CMAKE_BUILD_TYPE})
468     if (NOT _imported_conf)
469         # Get available imported configurations by examining target properties
470         get_target_property(_imported_conf ${target} IMPORTED_CONFIGURATIONS)
471         if(HDF5_FIND_DEBUG)
472             message(STATUS "Found imported configurations: ${_imported_conf}")
473         endif()
474         # Find the imported configuration that we prefer.
475         # We do this by making list of configurations in order of preference,
476         # starting with ${CMAKE_BUILD_TYPE} and ending with the first imported_conf
477         set(_preferred_confs ${CMAKE_BUILD_TYPE})
478         list(GET _imported_conf 0 _fallback_conf)
479         list(APPEND _preferred_confs RELWITHDEBINFO RELEASE DEBUG ${_fallback_conf})
480         if(HDF5_FIND_DEBUG)
481             message(STATUS "Start search through imported configurations in the following order: ${_preferred_confs}")
482         endif()
483         # Now find the first of these that is present in imported_conf
484         cmake_policy(PUSH)
485         cmake_policy(SET CMP0057 NEW) # support IN_LISTS
486         foreach (_conf IN LISTS _preferred_confs)
487             if (${_conf} IN_LIST _imported_conf)
488                set(_imported_conf ${_conf})
489                break()
490             endif()
491         endforeach()
492         cmake_policy(POP)
493     endif()
494     if(HDF5_FIND_DEBUG)
495         message(STATUS "Selected imported configuration: ${_imported_conf}")
496     endif()
497     # assign value to function argument
498     set(${imported_conf} ${_imported_conf} PARENT_SCOPE)
499 endfunction()
502 if(NOT HDF5_ROOT)
503     set(HDF5_ROOT $ENV{HDF5_ROOT})
504 endif()
505 if(HDF5_ROOT)
506     set(_HDF5_SEARCH_OPTS NO_DEFAULT_PATH)
507 else()
508     set(_HDF5_SEARCH_OPTS)
509 endif()
511 # Try to find HDF5 using an installed hdf5-config.cmake
512 if(NOT HDF5_FOUND AND NOT HDF5_NO_FIND_PACKAGE_CONFIG_FILE)
513     find_package(HDF5 QUIET NO_MODULE
514       HINTS ${HDF5_ROOT}
515       ${_HDF5_SEARCH_OPTS}
516       )
517     if( HDF5_FOUND)
518         if(HDF5_FIND_DEBUG)
519             message(STATUS "Found HDF5 at ${HDF5_DIR} via NO_MODULE. Now trying to extract locations etc.")
520         endif()
521         set(HDF5_IS_PARALLEL ${HDF5_ENABLE_PARALLEL})
522         set(HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR})
523         set(HDF5_LIBRARIES)
524         if (NOT TARGET hdf5 AND NOT TARGET hdf5-static AND NOT TARGET hdf5-shared)
525             # Some HDF5 versions (e.g. 1.8.18) used hdf5::hdf5 etc
526             set(_target_prefix "hdf5::")
527         endif()
528         set(HDF5_C_TARGET ${_target_prefix}hdf5)
529         set(HDF5_C_HL_TARGET ${_target_prefix}hdf5_hl)
530         set(HDF5_CXX_TARGET ${_target_prefix}hdf5_cpp)
531         set(HDF5_CXX_HL_TARGET ${_target_prefix}hdf5_hl_cpp)
532         set(HDF5_Fortran_TARGET ${_target_prefix}hdf5_fortran)
533         set(HDF5_Fortran_HL_TARGET ${_target_prefix}hdf5_hl_fortran)
534         set(HDF5_DEFINITIONS "")
535         if(HDF5_USE_STATIC_LIBRARIES)
536             set(_suffix "-static")
537         else()
538             set(_suffix "-shared")
539         endif()
540         foreach(_lang ${HDF5_LANGUAGE_BINDINGS})
542             #Older versions of hdf5 don't have a static/shared suffix so
543             #if we detect that occurrence clear the suffix
544             if(_suffix AND NOT TARGET ${HDF5_${_lang}_TARGET}${_suffix})
545               if(NOT TARGET ${HDF5_${_lang}_TARGET})
546                 #can't find this component with or without the suffix
547                 #so bail out, and let the following locate HDF5
548                 set(HDF5_FOUND FALSE)
549                 break()
550               endif()
551               set(_suffix "")
552             endif()
554             if(HDF5_FIND_DEBUG)
555                 message(STATUS "Trying to get properties of target ${HDF5_${_lang}_TARGET}${_suffix}")
556             endif()
557             # Find library for this target. Complicated as on Windows with a DLL, we need to search for the import-lib.
558             _HDF5_select_imported_config(${HDF5_${_lang}_TARGET}${_suffix} _hdf5_imported_conf)
559             get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} )
560             if (NOT _hdf5_lang_location)
561                 # no import lib, just try LOCATION
562                 get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf})
563                 if (NOT _hdf5_lang_location)
564                     get_target_property(_hdf5_lang_location ${HDF5_${_lang}_TARGET}${_suffix} LOCATION)
565                 endif()
566             endif()
567             if( _hdf5_lang_location )
568                 set(HDF5_${_lang}_LIBRARY ${_hdf5_lang_location})
569                 list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix})
570                 set(HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_TARGET}${_suffix})
571                 set(HDF5_${_lang}_FOUND TRUE)
572             endif()
573             if(HDF5_FIND_HL)
574                 get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} IMPORTED_IMPLIB_${_hdf5_imported_conf} )
575                 if (NOT _hdf5_lang_hl_location)
576                     get_target_property(_hdf5_lang_hl_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION_${_hdf5_imported_conf})
577                     if (NOT _hdf5_hl_lang_location)
578                         get_target_property(_hdf5_hl_lang_location ${HDF5_${_lang}_HL_TARGET}${_suffix} LOCATION)
579                     endif()
580                 endif()
581                 if( _hdf5_lang_hl_location )
582                     set(HDF5_${_lang}_HL_LIBRARY ${_hdf5_lang_hl_location})
583                     list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix})
584                     set(HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_HL_TARGET}${_suffix})
585                     set(HDF5_HL_FOUND TRUE)
586                 endif()
587                 unset(_hdf5_lang_hl_location)
588             endif()
589             unset(_hdf5_imported_conf)
590             unset(_hdf5_lang_location)
591         endforeach()
592     endif()
593 endif()
595 if(NOT HDF5_FOUND)
596   set(_HDF5_NEED_TO_SEARCH FALSE)
597   set(_HDF5_TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5)
598   set(HDF5_COMPILER_NO_INTERROGATE TRUE)
599   # Only search for languages we've enabled
600   foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS)
601     set(HDF5_${_lang}_LIBRARIES)
602     set(HDF5_${_lang}_HL_LIBRARIES)
604     # First check to see if our regular compiler is one of wrappers
605     if(_lang STREQUAL "C")
606       set(_HDF5_TEST_SRC cmake_hdf5_test.c)
607       if(CMAKE_CXX_COMPILER_LOADED AND NOT CMAKE_C_COMPILER_LOADED)
608         # CXX project without C enabled
609         set(_HDF5_TEST_SRC cmake_hdf5_test.cxx)
610       endif()
611       _HDF5_test_regular_compiler_C(
612         HDF5_${_lang}_COMPILER_NO_INTERROGATE
613         HDF5_${_lang}_VERSION
614         HDF5_${_lang}_IS_PARALLEL)
615     elseif(_lang STREQUAL "CXX")
616       set(_HDF5_TEST_SRC cmake_hdf5_test.cxx)
617       _HDF5_test_regular_compiler_CXX(
618         HDF5_${_lang}_COMPILER_NO_INTERROGATE
619         HDF5_${_lang}_VERSION
620         HDF5_${_lang}_IS_PARALLEL)
621     elseif(_lang STREQUAL "Fortran")
622       set(_HDF5_TEST_SRC cmake_hdf5_test.f90)
623       _HDF5_test_regular_compiler_Fortran(
624         HDF5_${_lang}_COMPILER_NO_INTERROGATE
625         HDF5_${_lang}_IS_PARALLEL)
626     else()
627       continue()
628     endif()
629     if(HDF5_${_lang}_COMPILER_NO_INTERROGATE)
630       if(HDF5_FIND_DEBUG)
631         message(STATUS "HDF5: Using hdf5 compiler wrapper for all ${_lang} compiling")
632       endif()
633       set(HDF5_${_lang}_FOUND TRUE)
634       set(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE
635           "${CMAKE_${_lang}_COMPILER}"
636           CACHE FILEPATH "HDF5 ${_lang} compiler wrapper")
637       set(HDF5_${_lang}_DEFINITIONS)
638       set(HDF5_${_lang}_INCLUDE_DIRS)
639       set(HDF5_${_lang}_LIBRARIES)
640       set(HDF5_${_lang}_HL_LIBRARIES)
642       mark_as_advanced(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE)
644       set(HDF5_${_lang}_FOUND TRUE)
645       set(HDF5_HL_FOUND TRUE)
646     else()
647       set(HDF5_COMPILER_NO_INTERROGATE FALSE)
648       # If this language isn't using the wrapper, then try to seed the
649       # search options with the wrapper
650       find_program(HDF5_${_lang}_COMPILER_EXECUTABLE
651         NAMES ${HDF5_${_lang}_COMPILER_NAMES} NAMES_PER_DIR
652         HINTS ${HDF5_ROOT}
653         PATH_SUFFIXES bin Bin
654         DOC "HDF5 ${_lang} Wrapper compiler.  Used only to detect HDF5 compile flags."
655         ${_HDF5_SEARCH_OPTS}
656       )
657       mark_as_advanced( HDF5_${_lang}_COMPILER_EXECUTABLE )
658       unset(HDF5_${_lang}_COMPILER_NAMES)
660       if(HDF5_${_lang}_COMPILER_EXECUTABLE)
661         _HDF5_invoke_compiler(${_lang} HDF5_${_lang}_COMPILE_LINE
662           HDF5_${_lang}_RETURN_VALUE HDF5_${_lang}_VERSION HDF5_${_lang}_IS_PARALLEL)
663         if(HDF5_${_lang}_RETURN_VALUE EQUAL 0)
664           if(HDF5_FIND_DEBUG)
665             message(STATUS "HDF5: Using hdf5 compiler wrapper to determine ${_lang} configuration")
666           endif()
667           _HDF5_parse_compile_line( HDF5_${_lang}_COMPILE_LINE
668             HDF5_${_lang}_INCLUDE_DIRS
669             HDF5_${_lang}_DEFINITIONS
670             HDF5_${_lang}_LIBRARY_DIRS
671             HDF5_${_lang}_LIBRARY_NAMES
672             HDF5_${_lang}_HL_LIBRARY_NAMES
673           )
674           set(HDF5_${_lang}_LIBRARIES)
676           foreach(_lib IN LISTS HDF5_${_lang}_LIBRARY_NAMES)
677             set(_HDF5_SEARCH_NAMES_LOCAL)
678             if("x${_lib}" MATCHES "hdf5")
679               # hdf5 library
680               set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS})
681               if(HDF5_USE_STATIC_LIBRARIES)
682                 if(WIN32)
683                   set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib})
684                 else()
685                   set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a)
686                 endif()
687               endif()
688             else()
689               # external library
690               set(_HDF5_SEARCH_OPTS_LOCAL)
691             endif()
692             find_library(HDF5_${_lang}_LIBRARY_${_lib}
693               NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR
694               HINTS ${HDF5_${_lang}_LIBRARY_DIRS}
695                     ${HDF5_ROOT}
696               ${_HDF5_SEARCH_OPTS_LOCAL}
697               )
698             unset(_HDF5_SEARCH_OPTS_LOCAL)
699             unset(_HDF5_SEARCH_NAMES_LOCAL)
700             if(HDF5_${_lang}_LIBRARY_${_lib})
701               list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}})
702             else()
703               list(APPEND HDF5_${_lang}_LIBRARIES ${_lib})
704             endif()
705           endforeach()
706           if(HDF5_FIND_HL)
707             set(HDF5_${_lang}_HL_LIBRARIES)
708             foreach(_lib IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES)
709               set(_HDF5_SEARCH_NAMES_LOCAL)
710               if("x${_lib}" MATCHES "hdf5")
711                 # hdf5 library
712                 set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS})
713                 if(HDF5_USE_STATIC_LIBRARIES)
714                   if(WIN32)
715                     set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib})
716                   else()
717                     set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a)
718                   endif()
719                 endif()
720               else()
721                 # external library
722                 set(_HDF5_SEARCH_OPTS_LOCAL)
723               endif()
724               find_library(HDF5_${_lang}_LIBRARY_${_lib}
725                 NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR
726                 HINTS ${HDF5_${_lang}_LIBRARY_DIRS}
727                       ${HDF5_ROOT}
728                 ${_HDF5_SEARCH_OPTS_LOCAL}
729                 )
730               unset(_HDF5_SEARCH_OPTS_LOCAL)
731               unset(_HDF5_SEARCH_NAMES_LOCAL)
732               if(HDF5_${_lang}_LIBRARY_${_lib})
733                 list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${_lang}_LIBRARY_${_lib}})
734               else()
735                 list(APPEND HDF5_${_lang}_HL_LIBRARIES ${_lib})
736               endif()
737             endforeach()
738             set(HDF5_HL_FOUND TRUE)
739           endif()
741           set(HDF5_${_lang}_FOUND TRUE)
742           list(REMOVE_DUPLICATES HDF5_${_lang}_DEFINITIONS)
743           list(REMOVE_DUPLICATES HDF5_${_lang}_INCLUDE_DIRS)
744         else()
745           set(_HDF5_NEED_TO_SEARCH TRUE)
746         endif()
747       else()
748         set(_HDF5_NEED_TO_SEARCH TRUE)
749       endif()
750     endif()
751     if(HDF5_${_lang}_VERSION)
752       if(NOT HDF5_VERSION)
753         set(HDF5_VERSION ${HDF5_${_lang}_VERSION})
754       elseif(NOT HDF5_VERSION VERSION_EQUAL HDF5_${_lang}_VERSION)
755         message(WARNING "HDF5 Version found for language ${_lang}, ${HDF5_${_lang}_VERSION} is different than previously found version ${HDF5_VERSION}")
756       endif()
757     endif()
758     if(DEFINED HDF5_${_lang}_IS_PARALLEL)
759       if(NOT DEFINED HDF5_IS_PARALLEL)
760         set(HDF5_IS_PARALLEL ${HDF5_${_lang}_IS_PARALLEL})
761       elseif(NOT HDF5_IS_PARALLEL AND HDF5_${_lang}_IS_PARALLEL)
762         message(WARNING "HDF5 found for language ${_lang} is parallel but previously found language is not parallel.")
763       elseif(HDF5_IS_PARALLEL AND NOT HDF5_${_lang}_IS_PARALLEL)
764         message(WARNING "HDF5 found for language ${_lang} is not parallel but previously found language is parallel.")
765       endif()
766     endif()
767   endforeach()
768   unset(_HDF5_TEST_DIR)
769   unset(_HDF5_TEST_SRC)
770   unset(_lib)
771 else()
772   set(_HDF5_NEED_TO_SEARCH TRUE)
773 endif()
775 if(NOT HDF5_FOUND AND HDF5_COMPILER_NO_INTERROGATE)
776   # No arguments necessary, all languages can use the compiler wrappers
777   set(HDF5_FOUND TRUE)
778   set(HDF5_METHOD "Included by compiler wrappers")
779   set(HDF5_REQUIRED_VARS HDF5_METHOD)
780 elseif(NOT HDF5_FOUND AND NOT _HDF5_NEED_TO_SEARCH)
781   # Compiler wrappers aren't being used by the build but were found and used
782   # to determine necessary include and library flags
783   set(HDF5_INCLUDE_DIRS)
784   set(HDF5_LIBRARIES)
785   set(HDF5_HL_LIBRARIES)
786   foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS)
787     if(HDF5_${_lang}_FOUND)
788       if(NOT HDF5_${_lang}_COMPILER_NO_INTERROGATE)
789         list(APPEND HDF5_DEFINITIONS ${HDF5_${_lang}_DEFINITIONS})
790         list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIRS})
791         list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES})
792         if(HDF5_FIND_HL)
793           list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES})
794         endif()
795       endif()
796     endif()
797   endforeach()
798   list(REMOVE_DUPLICATES HDF5_DEFINITIONS)
799   list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS)
800   set(HDF5_FOUND TRUE)
801   set(HDF5_REQUIRED_VARS HDF5_LIBRARIES)
802   if(HDF5_FIND_HL)
803     list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES)
804   endif()
805 endif()
807 find_program( HDF5_DIFF_EXECUTABLE
808     NAMES h5diff
809     HINTS ${HDF5_ROOT}
810     PATH_SUFFIXES bin Bin
811     ${_HDF5_SEARCH_OPTS}
812     DOC "HDF5 file differencing tool." )
813 mark_as_advanced( HDF5_DIFF_EXECUTABLE )
815 if( NOT HDF5_FOUND )
816     # seed the initial lists of libraries to find with items we know we need
817     set(HDF5_C_LIBRARY_NAMES          hdf5)
818     set(HDF5_C_HL_LIBRARY_NAMES       hdf5_hl ${HDF5_C_LIBRARY_NAMES} )
820     set(HDF5_CXX_LIBRARY_NAMES        hdf5_cpp    ${HDF5_C_LIBRARY_NAMES})
821     set(HDF5_CXX_HL_LIBRARY_NAMES     hdf5_hl_cpp ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_CXX_LIBRARY_NAMES})
823     set(HDF5_Fortran_LIBRARY_NAMES    hdf5_fortran   ${HDF5_C_LIBRARY_NAMES})
824     set(HDF5_Fortran_HL_LIBRARY_NAMES hdf5_hl_fortran hdf5hl_fortran ${HDF5_C_HL_LIBRARY_NAMES} ${HDF5_Fortran_LIBRARY_NAMES})
826     # suffixes as seen on Linux, MSYS2, ...
827     set(_lib_suffixes hdf5)
828     if(NOT HDF5_PREFER_PARALLEL)
829       list(APPEND _lib_suffixes hdf5/serial)
830     endif()
831     if(HDF5_USE_STATIC_LIBRARIES)
832       set(_inc_suffixes include/static)
833     else()
834       set(_inc_suffixes include/shared)
835     endif()
837     foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS)
838         set(HDF5_${_lang}_LIBRARIES)
839         set(HDF5_${_lang}_HL_LIBRARIES)
841         # The "main" library.
842         set(_hdf5_main_library "")
844         # find the HDF5 libraries
845         foreach(LIB IN LISTS HDF5_${_lang}_LIBRARY_NAMES)
846             if(HDF5_USE_STATIC_LIBRARIES)
847                 # According to bug 1643 on the CMake bug tracker, this is the
848                 # preferred method for searching for a static library.
849                 # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643.  We search
850                 # first for the full static library name, but fall back to a
851                 # generic search on the name if the static search fails.
852                 set( THIS_LIBRARY_SEARCH_DEBUG
853                     lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug
854                     lib${LIB}d-static.a lib${LIB}_debug-static.a ${LIB}d-static ${LIB}_D-static ${LIB}_debug-static )
855                 set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a ${LIB}-static)
856             else()
857                 set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared)
858                 set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared)
859                 if(WIN32)
860                   list(APPEND HDF5_DEFINITIONS "-DH5_BUILT_AS_DYNAMIC_LIB")
861                 endif()
862             endif()
863             find_library(HDF5_${LIB}_LIBRARY_DEBUG
864                 NAMES ${THIS_LIBRARY_SEARCH_DEBUG}
865                 HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes}
866                 ${_HDF5_SEARCH_OPTS}
867             )
868             find_library(HDF5_${LIB}_LIBRARY_RELEASE
869                 NAMES ${THIS_LIBRARY_SEARCH_RELEASE}
870                 HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes}
871                 ${_HDF5_SEARCH_OPTS}
872             )
874             # Set the "main" library if not already set.
875             if (NOT _hdf5_main_library)
876               if (HDF5_${LIB}_LIBRARY_RELEASE)
877                 set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_RELEASE}")
878               elseif (HDF5_${LIB}_LIBRARY_DEBUG)
879                 set(_hdf5_main_library "${HDF5_${LIB}_LIBRARY_DEBUG}")
880               endif ()
881             endif ()
883             select_library_configurations( HDF5_${LIB} )
884             list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${LIB}_LIBRARY})
885         endforeach()
886         if(HDF5_${_lang}_LIBRARIES)
887             set(HDF5_${_lang}_FOUND TRUE)
888         endif()
890         # Append the libraries for this language binding to the list of all
891         # required libraries.
892         list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES})
894         # find the HDF5 include directories
895         set(_hdf5_inc_extra_paths)
896         set(_hdf5_inc_extra_suffixes)
897         if("${_lang}" STREQUAL "Fortran")
898             set(HDF5_INCLUDE_FILENAME hdf5.mod HDF5.mod)
900             # Add library-based search paths for Fortran modules.
901             if (NOT _hdf5_main_library STREQUAL "")
902               # gfortran module directory
903               if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "LCC")
904                 get_filename_component(_hdf5_library_dir "${_hdf5_main_library}" DIRECTORY)
905                 list(APPEND _hdf5_inc_extra_paths "${_hdf5_library_dir}")
906                 unset(_hdf5_library_dir)
907                 list(APPEND _hdf5_inc_extra_suffixes gfortran/modules)
908               endif ()
909             endif ()
910         elseif("${_lang}" STREQUAL "CXX")
911             set(HDF5_INCLUDE_FILENAME H5Cpp.h)
912         else()
913             set(HDF5_INCLUDE_FILENAME hdf5.h)
914         endif()
916         unset(_hdf5_main_library)
918         find_path(HDF5_${_lang}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME}
919             HINTS ${HDF5_ROOT}
920             PATHS $ENV{HOME}/.local/include ${_hdf5_inc_extra_paths}
921             PATH_SUFFIXES include Include ${_inc_suffixes} ${_lib_suffixes} ${_hdf5_inc_extra_suffixes}
922             ${_HDF5_SEARCH_OPTS}
923         )
924         mark_as_advanced(HDF5_${_lang}_INCLUDE_DIR)
925         unset(_hdf5_inc_extra_paths)
926         unset(_hdf5_inc_extra_suffixes)
927         # set the _DIRS variable as this is what the user will normally use
928         set(HDF5_${_lang}_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR})
929         list(APPEND HDF5_INCLUDE_DIRS ${HDF5_${_lang}_INCLUDE_DIR})
931         if(HDF5_FIND_HL)
932             foreach(LIB IN LISTS HDF5_${_lang}_HL_LIBRARY_NAMES)
933                 if(HDF5_USE_STATIC_LIBRARIES)
934                     # According to bug 1643 on the CMake bug tracker, this is the
935                     # preferred method for searching for a static library.
936                     # See https://gitlab.kitware.com/cmake/cmake/-/issues/1643.  We search
937                     # first for the full static library name, but fall back to a
938                     # generic search on the name if the static search fails.
939                     set( THIS_LIBRARY_SEARCH_DEBUG
940                         lib${LIB}d.a lib${LIB}_debug.a lib${LIB}d lib${LIB}_D lib${LIB}_debug
941                         lib${LIB}d-static.a lib${LIB}_debug-static.a lib${LIB}d-static lib${LIB}_D-static lib${LIB}_debug-static )
942                     set( THIS_LIBRARY_SEARCH_RELEASE lib${LIB}.a lib${LIB} lib${LIB}-static.a lib${LIB}-static)
943                 else()
944                     set( THIS_LIBRARY_SEARCH_DEBUG ${LIB}d ${LIB}_D ${LIB}_debug ${LIB}d-shared ${LIB}_D-shared ${LIB}_debug-shared)
945                     set( THIS_LIBRARY_SEARCH_RELEASE ${LIB} ${LIB}-shared)
946                 endif()
947                 find_library(HDF5_${LIB}_LIBRARY_DEBUG
948                     NAMES ${THIS_LIBRARY_SEARCH_DEBUG}
949                     HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes}
950                     ${_HDF5_SEARCH_OPTS}
951                 )
952                 find_library(HDF5_${LIB}_LIBRARY_RELEASE
953                     NAMES ${THIS_LIBRARY_SEARCH_RELEASE}
954                     HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes}
955                     ${_HDF5_SEARCH_OPTS}
956                 )
958                 select_library_configurations( HDF5_${LIB} )
959                 list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${LIB}_LIBRARY})
960             endforeach()
962             # Append the libraries for this language binding to the list of all
963             # required libraries.
964             list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES})
965         endif()
966     endforeach()
967     if(HDF5_FIND_HL AND HDF5_HL_LIBRARIES)
968         set(HDF5_HL_FOUND TRUE)
969     endif()
971     list(REMOVE_DUPLICATES HDF5_DEFINITIONS)
972     list(REMOVE_DUPLICATES HDF5_INCLUDE_DIRS)
974     # If the HDF5 include directory was found, open H5pubconf.h to determine if
975     # HDF5 was compiled with parallel IO support
976     set( HDF5_IS_PARALLEL FALSE )
977     set( HDF5_VERSION "" )
978     foreach( _dir IN LISTS HDF5_INCLUDE_DIRS )
979       foreach(_hdr "${_dir}/H5pubconf.h" "${_dir}/H5pubconf-64.h" "${_dir}/H5pubconf-32.h")
980         if( EXISTS "${_hdr}" )
981             file( STRINGS "${_hdr}"
982                 HDF5_HAVE_PARALLEL_DEFINE
983                 REGEX "HAVE_PARALLEL 1" )
984             if( HDF5_HAVE_PARALLEL_DEFINE )
985                 set( HDF5_IS_PARALLEL TRUE )
986             endif()
987             unset(HDF5_HAVE_PARALLEL_DEFINE)
989             file( STRINGS "${_hdr}"
990                 HDF5_VERSION_DEFINE
991                 REGEX "^[ \t]*#[ \t]*define[ \t]+H5_VERSION[ \t]+" )
992             if( "${HDF5_VERSION_DEFINE}" MATCHES
993                 "H5_VERSION[ \t]+\"([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?\"" )
994                 set( HDF5_VERSION "${CMAKE_MATCH_1}" )
995                 if( CMAKE_MATCH_3 )
996                   set( HDF5_VERSION ${HDF5_VERSION}.${CMAKE_MATCH_3})
997                 endif()
998             endif()
999             unset(HDF5_VERSION_DEFINE)
1000         endif()
1001       endforeach()
1002     endforeach()
1003     unset(_hdr)
1004     unset(_dir)
1005     set( HDF5_IS_PARALLEL ${HDF5_IS_PARALLEL} CACHE BOOL
1006         "HDF5 library compiled with parallel IO support" )
1007     mark_as_advanced( HDF5_IS_PARALLEL )
1009     set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS)
1010     if(HDF5_FIND_HL)
1011         list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES)
1012     endif()
1013 endif()
1015 # For backwards compatibility we set HDF5_INCLUDE_DIR to the value of
1016 # HDF5_INCLUDE_DIRS
1017 if( HDF5_INCLUDE_DIRS )
1018   set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" )
1019 endif()
1021 # If HDF5_REQUIRED_VARS is empty at this point, then it's likely that
1022 # something external is trying to explicitly pass already found
1023 # locations
1024 if(NOT HDF5_REQUIRED_VARS)
1025     set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS)
1026 endif()
1028 find_package_handle_standard_args(HDF5
1029     REQUIRED_VARS ${HDF5_REQUIRED_VARS}
1030     VERSION_VAR   HDF5_VERSION
1031     HANDLE_COMPONENTS
1034 unset(_HDF5_SEARCH_OPTS)
1036 if( HDF5_FOUND AND NOT HDF5_DIR)
1037   # hide HDF5_DIR for the non-advanced user to avoid confusion with
1038   # HDF5_DIR-NOT_FOUND while HDF5 was found.
1039   mark_as_advanced(HDF5_DIR)
1040 endif()
1042 if (HDF5_FOUND)
1043   if (NOT TARGET HDF5::HDF5)
1044     add_library(HDF5::HDF5 INTERFACE IMPORTED)
1045     string(REPLACE "-D" "" _hdf5_definitions "${HDF5_DEFINITIONS}")
1046     set_target_properties(HDF5::HDF5 PROPERTIES
1047       INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS}"
1048       INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}")
1049     unset(_hdf5_definitions)
1050     target_link_libraries(HDF5::HDF5 INTERFACE ${HDF5_LIBRARIES})
1051   endif ()
1053   foreach (hdf5_lang IN LISTS HDF5_LANGUAGE_BINDINGS)
1054     if (hdf5_lang STREQUAL "C")
1055       set(hdf5_target_name "hdf5")
1056     elseif (hdf5_lang STREQUAL "CXX")
1057       set(hdf5_target_name "hdf5_cpp")
1058     elseif (hdf5_lang STREQUAL "Fortran")
1059       set(hdf5_target_name "hdf5_fortran")
1060     else ()
1061       continue ()
1062     endif ()
1064     if (NOT TARGET "hdf5::${hdf5_target_name}")
1065       if (HDF5_COMPILER_NO_INTERROGATE)
1066         add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED)
1067         string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}")
1068         set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES
1069           INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}"
1070           INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}")
1071       else()
1072         if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY")
1073           set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}")
1074           set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}")
1075           set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}")
1076         elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY")
1077           set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY}")
1078           set(_hdf5_location_release "${HDF5_${hdf5_lang}_LIBRARY_RELEASE}")
1079           set(_hdf5_location_debug "${HDF5_${hdf5_lang}_LIBRARY_DEBUG}")
1080         elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}")
1081           set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}")
1082         else ()
1083           # Error if we still don't have the location.
1084           message(SEND_ERROR
1085             "HDF5 was found, but a different variable was set which contains "
1086             "the location of the `hdf5::${hdf5_target_name}` library.")
1087         endif ()
1088         add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED)
1089         string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_DEFINITIONS}")
1090         if (NOT HDF5_${hdf5_lang}_INCLUDE_DIRS)
1091          set(HDF5_${hdf5_lang}_INCLUDE_DIRS ${HDF5_INCLUDE_DIRS})
1092         endif ()
1093         set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES
1094           INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_INCLUDE_DIRS}"
1095           INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}")
1096         if (_hdf5_location_release)
1097           set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY
1098             IMPORTED_CONFIGURATIONS RELEASE)
1099           set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY
1100             IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}")
1101         endif()
1102         if (_hdf5_location_debug)
1103           set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY
1104             IMPORTED_CONFIGURATIONS DEBUG)
1105           set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY
1106             IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}")
1107         endif()
1108         if (NOT _hdf5_location_release AND NOT _hdf5_location_debug)
1109           set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY
1110             IMPORTED_LOCATION "${_hdf5_location}")
1111         endif()
1112         if (_hdf5_libtype STREQUAL "SHARED")
1113           set_property(TARGET "hdf5::${hdf5_target_name}" APPEND
1114             PROPERTY
1115               INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB)
1116         elseif (_hdf5_libtype STREQUAL "STATIC")
1117           set_property(TARGET "hdf5::${hdf5_target_name}" APPEND
1118             PROPERTY
1119               INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB)
1120         endif ()
1121         unset(_hdf5_definitions)
1122         unset(_hdf5_libtype)
1123         unset(_hdf5_location)
1124         unset(_hdf5_location_release)
1125         unset(_hdf5_location_debug)
1126       endif ()
1127     endif ()
1129     if (NOT HDF5_FIND_HL)
1130       continue ()
1131     endif ()
1133     set(hdf5_alt_target_name "")
1134     if (hdf5_lang STREQUAL "C")
1135       set(hdf5_target_name "hdf5_hl")
1136     elseif (hdf5_lang STREQUAL "CXX")
1137       set(hdf5_target_name "hdf5_hl_cpp")
1138     elseif (hdf5_lang STREQUAL "Fortran")
1139       set(hdf5_target_name "hdf5_hl_fortran")
1140       set(hdf5_alt_target_name "hdf5hl_fortran")
1141     else ()
1142       continue ()
1143     endif ()
1145     if (NOT TARGET "hdf5::${hdf5_target_name}")
1146       if (HDF5_COMPILER_NO_INTERROGATE)
1147         add_library("hdf5::${hdf5_target_name}" INTERFACE IMPORTED)
1148         string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}")
1149         set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES
1150           INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}"
1151           INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}")
1152       else()
1153         if (DEFINED "HDF5_${hdf5_target_name}_LIBRARY")
1154           set(_hdf5_location "${HDF5_${hdf5_target_name}_LIBRARY}")
1155           set(_hdf5_location_release "${HDF5_${hdf5_target_name}_LIBRARY_RELEASE}")
1156           set(_hdf5_location_debug "${HDF5_${hdf5_target_name}_LIBRARY_DEBUG}")
1157         elseif (DEFINED "HDF5_${hdf5_lang}_HL_LIBRARY")
1158           set(_hdf5_location "${HDF5_${hdf5_lang}_HL_LIBRARY}")
1159           set(_hdf5_location_release "${HDF5_${hdf5_lang}_HL_LIBRARY_RELEASE}")
1160           set(_hdf5_location_debug "${HDF5_${hdf5_lang}_HL_LIBRARY_DEBUG}")
1161         elseif (DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}")
1162           set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_target_name}}")
1163         elseif (hdf5_alt_target_name AND DEFINED "HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}")
1164           set(_hdf5_location "${HDF5_${hdf5_lang}_LIBRARY_${hdf5_alt_target_name}}")
1165         else ()
1166           # Error if we still don't have the location.
1167           message(SEND_ERROR
1168             "HDF5 was found, but a different variable was set which contains "
1169             "the location of the `hdf5::${hdf5_target_name}` library.")
1170         endif ()
1171         add_library("hdf5::${hdf5_target_name}" UNKNOWN IMPORTED)
1172         string(REPLACE "-D" "" _hdf5_definitions "${HDF5_${hdf5_lang}_HL_DEFINITIONS}")
1173         set_target_properties("hdf5::${hdf5_target_name}" PROPERTIES
1174           INTERFACE_INCLUDE_DIRECTORIES "${HDF5_${hdf5_lang}_HL_INCLUDE_DIRS}"
1175           INTERFACE_COMPILE_DEFINITIONS "${_hdf5_definitions}")
1176         if (_hdf5_location_release)
1177           set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY
1178             IMPORTED_CONFIGURATIONS RELEASE)
1179           set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY
1180             IMPORTED_LOCATION_RELEASE "${_hdf5_location_release}")
1181         endif()
1182         if (_hdf5_location_debug)
1183           set_property(TARGET "hdf5::${hdf5_target_name}" APPEND PROPERTY
1184             IMPORTED_CONFIGURATIONS DEBUG)
1185           set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY
1186             IMPORTED_LOCATION_DEBUG "${_hdf5_location_debug}")
1187         endif()
1188         if (NOT _hdf5_location_release AND NOT _hdf5_location_debug)
1189           set_property(TARGET "hdf5::${hdf5_target_name}" PROPERTY
1190             IMPORTED_LOCATION "${_hdf5_location}")
1191         endif()
1192         if (_hdf5_libtype STREQUAL "SHARED")
1193           set_property(TARGET "hdf5::${hdf5_target_name}" APPEND
1194             PROPERTY
1195               INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB)
1196         elseif (_hdf5_libtype STREQUAL "STATIC")
1197           set_property(TARGET "hdf5::${hdf5_target_name}" APPEND
1198             PROPERTY
1199               INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB)
1200         endif ()
1201         unset(_hdf5_definitions)
1202         unset(_hdf5_libtype)
1203         unset(_hdf5_location)
1204       endif ()
1205     endif ()
1206   endforeach ()
1207   unset(hdf5_lang)
1209   if (HDF5_DIFF_EXECUTABLE AND NOT TARGET hdf5::h5diff)
1210     add_executable(hdf5::h5diff IMPORTED)
1211     set_target_properties(hdf5::h5diff PROPERTIES
1212       IMPORTED_LOCATION "${HDF5_DIFF_EXECUTABLE}")
1213   endif ()
1214 endif ()
1216 if (HDF5_FIND_DEBUG)
1217   message(STATUS "HDF5_DIR: ${HDF5_DIR}")
1218   message(STATUS "HDF5_DEFINITIONS: ${HDF5_DEFINITIONS}")
1219   message(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}")
1220   message(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}")
1221   message(STATUS "HDF5_HL_LIBRARIES: ${HDF5_HL_LIBRARIES}")
1222   foreach(_lang IN LISTS HDF5_LANGUAGE_BINDINGS)
1223     message(STATUS "HDF5_${_lang}_DEFINITIONS: ${HDF5_${_lang}_DEFINITIONS}")
1224     message(STATUS "HDF5_${_lang}_INCLUDE_DIR: ${HDF5_${_lang}_INCLUDE_DIR}")
1225     message(STATUS "HDF5_${_lang}_INCLUDE_DIRS: ${HDF5_${_lang}_INCLUDE_DIRS}")
1226     message(STATUS "HDF5_${_lang}_LIBRARY: ${HDF5_${_lang}_LIBRARY}")
1227     message(STATUS "HDF5_${_lang}_LIBRARIES: ${HDF5_${_lang}_LIBRARIES}")
1228     message(STATUS "HDF5_${_lang}_HL_LIBRARY: ${HDF5_${_lang}_HL_LIBRARY}")
1229     message(STATUS "HDF5_${_lang}_HL_LIBRARIES: ${HDF5_${_lang}_HL_LIBRARIES}")
1230   endforeach()
1231   message(STATUS "Defined targets (if any):")
1232   foreach(_lang IN  ITEMS "" "_cpp" "_fortran")
1233     foreach(_hl IN  ITEMS "" "_hl")
1234       foreach(_prefix IN ITEMS "hdf5::" "")
1235         foreach(_suffix IN ITEMS "-static" "-shared" "")
1236           set (_target ${_prefix}hdf5${_hl}${_lang}${_suffix})
1237           if (TARGET  ${_target})
1238             message(STATUS "... ${_target}")
1239           else()
1240             #message(STATUS "... ${_target} does not exist")
1241           endif()
1242         endforeach()
1243       endforeach()
1244     endforeach()
1245   endforeach()
1246 endif()
1247 unset(_lang)
1248 unset(_HDF5_NEED_TO_SEARCH)
1250 cmake_policy(POP)