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