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