1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
8 Find Hierarchical Data Format (HDF5), a library for reading and writing
9 self describing array data.
12 This module invokes the ``HDF5`` wrapper compiler that should be installed
13 alongside ``HDF5``. Depending upon the ``HDF5`` Configuration, the wrapper
14 compiler is called either ``h5cc`` or ``h5pcc``. If this succeeds, the module
15 will then call the compiler with the show argument to see what flags
16 are used when compiling an ``HDF5`` client application.
18 The module will optionally accept the ``COMPONENTS`` argument. If no
19 ``COMPONENTS`` are specified, then the find module will default to finding
20 only the ``HDF5`` C library. If one or more ``COMPONENTS`` are specified, the
21 module will attempt to find the language bindings for the specified
22 components. The valid components are ``C``, ``CXX``, ``Fortran``, ``HL``.
23 ``HL`` refers to the "high-level" HDF5 functions for C and Fortran.
24 If the ``COMPONENTS`` argument is not given, the module will
25 attempt to find only the C bindings.
26 For example, to use Fortran HDF5 and HDF5-HL functions, do:
27 ``find_package(HDF5 COMPONENTS Fortran HL)``.
29 This module will read the variable
30 ``HDF5_USE_STATIC_LIBRARIES`` to determine whether or not to prefer a
31 static link to a dynamic link for ``HDF5`` and all of it's dependencies.
32 To use this feature, make sure that the ``HDF5_USE_STATIC_LIBRARIES``
33 variable is set before the call to find_package.
35 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
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
49 This module will set the following variables in your project:
52 HDF5 was found on the system
56 Location of the HDF5 header files
58 Required compiler definitions for HDF5
60 Required libraries for all requested bindings
62 Required libraries for the HDF5 high level API for all bindings,
63 if the ``HL`` component is enabled
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:
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
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.
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
113 With all components enabled, the following targets will be defined:
118 ``hdf5::hdf5_hl_cpp``
119 ``hdf5::hdf5_fortran``
121 ``hdf5::hdf5_hl_cpp``
122 ``hdf5::hdf5_hl_fortran``
128 The following variables can be set to guide the search for HDF5 libraries and includes:
130 ``HDF5_PREFER_PARALLEL``
131 set ``true`` to prefer parallel HDF5 (by default, serial is preferred)
134 Set ``true`` to get extra debugging output.
136 ``HDF5_NO_FIND_PACKAGE_CONFIG_FILE``
137 Set ``true`` to skip trying to find ``hdf5-config.cmake``.
138 #]=======================================================================]
140 include(${CMAKE_CURRENT_LIST_DIR}/SelectLibraryConfigurations.cmake)
141 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
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.
148 # List of the valid HDF5 components
149 set(HDF5_VALID_LANGUAGE_BINDINGS C CXX Fortran)
151 # Validate the list of find components.
152 if(NOT HDF5_FIND_COMPONENTS)
153 set(HDF5_LANGUAGE_BINDINGS "C")
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")
164 elseif(_component STREQUAL "Fortran_HL") # only for compatibility
165 list(APPEND HDF5_LANGUAGE_BINDINGS Fortran)
167 set(HDF5_FIND_REQUIRED_Fortran_HL FALSE)
168 set(HDF5_FIND_REQUIRED_Fortran TRUE)
169 set(HDF5_FIND_REQUIRED_HL TRUE)
171 message(FATAL_ERROR "${_component} is not a valid HDF5 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})
184 list(REMOVE_ITEM HDF5_FIND_COMPONENTS Fortran_HL) # replaced by Fortran and HL
185 list(REMOVE_DUPLICATES HDF5_LANGUAGE_BINDINGS)
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)
194 set(HDF5_C_COMPILER_NAMES h5cc h5pcc)
195 set(HDF5_CXX_COMPILER_NAMES h5c++ h5pc++)
196 set(HDF5_Fortran_COMPILER_NAMES h5fc h5pfc)
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
207 macro(_HDF5_remove_duplicates_from_beginning _list_name)
209 list(REVERSE ${_list_name})
210 list(REMOVE_DUPLICATES ${_list_name})
211 list(REVERSE ${_list_name})
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)
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"
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"
235 " fid = H5Fcreate(\"foo.h5\",H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT);\n"
238 try_compile(${success} ${scratch_directory} ${test_file}
239 COPY_FILE ${scratch_directory}/compiler_has_h5_c
243 file(STRINGS ${scratch_directory}/compiler_has_h5_c INFO_STRINGS
246 string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?"
247 INFO_VER "${INFO_STRINGS}"
249 set(${version} ${CMAKE_MATCH_1})
251 set(${version} ${HDF5_C_VERSION}.${CMAKE_MATCH_3})
253 set(${version} ${${version}} PARENT_SCOPE)
255 if(INFO_STRINGS MATCHES "INFO:PARALLEL")
256 set(${is_parallel} TRUE PARENT_SCOPE)
258 set(${is_parallel} FALSE PARENT_SCOPE)
263 function(_HDF5_test_regular_compiler_CXX success version is_parallel)
264 set(scratch_directory ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hdf5)
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"
273 "const char* info_ver = \"INFO\" \":\" H5_VERSION;\n"
274 "#ifdef H5_HAVE_PARALLEL\n"
275 "const char* info_parallel = \"INFO\" \":\" \"PARALLEL\";\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"
283 " H5File file(\"foo.h5\", H5F_ACC_TRUNC);\n"
286 try_compile(${success} ${scratch_directory} ${test_file}
287 COPY_FILE ${scratch_directory}/compiler_has_h5_cxx
291 file(STRINGS ${scratch_directory}/compiler_has_h5_cxx INFO_STRINGS
294 string(REGEX MATCH "^INFO:([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?"
295 INFO_VER "${INFO_STRINGS}"
297 set(${version} ${CMAKE_MATCH_1})
299 set(${version} ${HDF5_CXX_VERSION}.${CMAKE_MATCH_3})
301 set(${version} ${${version}} PARENT_SCOPE)
303 if(INFO_STRINGS MATCHES "INFO:PARALLEL")
304 set(${is_parallel} TRUE PARENT_SCOPE)
306 set(${is_parallel} FALSE PARENT_SCOPE)
311 function(_HDF5_test_regular_compiler_Fortran success is_parallel)
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"
322 " call h5open_f(error)\n"
323 " call h5close_f(error)\n"
325 try_compile(${success} ${scratch_directory} ${test_file})
327 execute_process(COMMAND ${CMAKE_Fortran_COMPILER} -showconfig
328 OUTPUT_VARIABLE config_output
329 ERROR_VARIABLE config_error
330 RESULT_VARIABLE config_result
332 if(config_output MATCHES "Parallel HDF5: yes")
333 set(${is_parallel} TRUE PARENT_SCOPE)
335 set(${is_parallel} FALSE PARENT_SCOPE)
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)
348 set(lib_type_args -shlib)
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)
358 # Verify that the compiler wrapper can actually compile: sometimes the compiler
359 # wrapper exists, but not the compiler. E.g. Miniconda / Anaconda Python
361 COMMAND ${HDF5_${language}_COMPILER_EXECUTABLE} ${test_file}
362 WORKING_DIRECTORY ${scratch_dir}
363 RESULT_VARIABLE return_value
367 "HDF5 ${language} compiler wrapper is unable to compile a minimal HDF5 program.")
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
379 "Unable to determine HDF5 ${language} flags from HDF5 wrapper.")
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
390 "Unable to determine HDF5 ${language} version_var from HDF5 wrapper.")
392 string(REGEX MATCH "HDF5 Version: ([a-zA-Z0-9\\.\\-]*)" version "${config_output}")
394 string(REPLACE "HDF5 Version: " "" version "${version}")
395 string(REPLACE "-patch" "." version "${version}")
397 if(config_output MATCHES "Parallel HDF5: yes")
398 set(is_parallel TRUE)
401 foreach(var output return_value version is_parallel)
402 set(${${var}_var} ${${var}} PARENT_SCOPE)
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)
410 separate_arguments(_compile_args NATIVE_COMMAND "${${compile_line_var}}")
412 foreach(_arg IN LISTS _compile_args)
413 if("${_arg}" MATCHES "^-I(.*)$")
415 list(APPEND include_paths "${CMAKE_MATCH_1}")
416 elseif("${_arg}" MATCHES "^-D(.*)$")
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.*)$")
424 list(APPEND libraries_hl "${CMAKE_MATCH_1}")
425 elseif("${_arg}" MATCHES "^-l(.*)$")
427 list(APPEND libraries "${CMAKE_MATCH_1}")
428 elseif("${_arg}" MATCHES "^(.:)?[/\\].*\\.(a|so|dylib|sl|lib)$")
430 if(NOT EXISTS "${_arg}")
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}")
440 list(APPEND libraries "${_lname}")
444 foreach(var include_paths definitions library_paths libraries libraries_hl)
445 set(${${var}_var} ${${var}} PARENT_SCOPE)
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)
458 message(STATUS "Found imported configurations: ${_imported_conf}")
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})
467 message(STATUS "Start search through imported configurations in the following order: ${_preferred_confs}")
469 # Now find the first of these that is present in imported_conf
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})
481 message(STATUS "Selected imported configuration: ${_imported_conf}")
483 # assign value to function argument
484 set(${imported_conf} ${_imported_conf} PARENT_SCOPE)
489 set(HDF5_ROOT $ENV{HDF5_ROOT})
492 set(_HDF5_SEARCH_OPTS NO_DEFAULT_PATH)
494 set(_HDF5_SEARCH_OPTS)
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
505 message(STATUS "Found HDF5 at ${HDF5_DIR} via NO_MODULE. Now trying to extract locations etc.")
507 set(HDF5_IS_PARALLEL ${HDF5_ENABLE_PARALLEL})
508 set(HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR})
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::")
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")
524 set(_suffix "-shared")
526 foreach(_lang ${HDF5_LANGUAGE_BINDINGS})
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)
541 message(STATUS "Trying to get properties of target ${HDF5_${_lang}_TARGET}${_suffix}")
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)
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)
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)
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)
573 unset(_hdf5_lang_hl_location)
575 unset(_hdf5_imported_conf)
576 unset(_hdf5_lang_location)
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)
604 if(HDF5_${_lang}_COMPILER_NO_INTERROGATE)
606 message(STATUS "HDF5: Using hdf5 compiler wrapper for all ${_lang} compiling")
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)
617 mark_as_advanced(HDF5_${_lang}_COMPILER_EXECUTABLE_NO_INTERROGATE)
619 set(HDF5_${_lang}_FOUND TRUE)
620 set(HDF5_HL_FOUND TRUE)
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
628 PATH_SUFFIXES bin Bin
629 DOC "HDF5 ${_lang} Wrapper compiler. Used only to detect HDF5 compile flags."
632 mark_as_advanced( HDF5_${_lang}_COMPILER_EXECUTABLE )
633 unset(HDF5_${_lang}_COMPILER_NAMES)
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)
640 message(STATUS "HDF5: Using hdf5 compiler wrapper to determine ${_lang} configuration")
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
649 set(HDF5_${_lang}_LIBRARIES)
651 foreach(_lib IN LISTS HDF5_${_lang}_LIBRARY_NAMES)
652 set(_HDF5_SEARCH_NAMES_LOCAL)
653 if("x${_lib}" MATCHES "hdf5")
655 set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS})
656 if(HDF5_USE_STATIC_LIBRARIES)
658 set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib})
660 set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a)
665 set(_HDF5_SEARCH_OPTS_LOCAL)
667 find_library(HDF5_${_lang}_LIBRARY_${_lib}
668 NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR
669 HINTS ${HDF5_${_lang}_LIBRARY_DIRS}
671 ${_HDF5_SEARCH_OPTS_LOCAL}
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}})
678 list(APPEND HDF5_${_lang}_LIBRARIES ${_lib})
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")
687 set(_HDF5_SEARCH_OPTS_LOCAL ${_HDF5_SEARCH_OPTS})
688 if(HDF5_USE_STATIC_LIBRARIES)
690 set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib})
692 set(_HDF5_SEARCH_NAMES_LOCAL lib${_lib}.a)
697 set(_HDF5_SEARCH_OPTS_LOCAL)
699 find_library(HDF5_${_lang}_LIBRARY_${_lib}
700 NAMES ${_HDF5_SEARCH_NAMES_LOCAL} ${_lib} NAMES_PER_DIR
701 HINTS ${HDF5_${_lang}_LIBRARY_DIRS}
703 ${_HDF5_SEARCH_OPTS_LOCAL}
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}})
710 list(APPEND HDF5_${_lang}_HL_LIBRARIES ${_lib})
713 set(HDF5_HL_FOUND TRUE)
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)
722 set(_HDF5_NEED_TO_SEARCH TRUE)
725 set(_HDF5_NEED_TO_SEARCH TRUE)
728 if(HDF5_${_lang}_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}")
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.")
747 set(_HDF5_NEED_TO_SEARCH TRUE)
750 if(NOT HDF5_FOUND AND HDF5_COMPILER_NO_INTERROGATE)
751 # No arguments necessary, all languages can use the compiler wrappers
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)
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})
768 list(APPEND HDF5_HL_LIBRARIES ${HDF5_${_lang}_HL_LIBRARIES})
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)
778 set(HDF5_REQUIRED_VARS HDF5_LIBRARIES)
780 list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES)
784 find_program( HDF5_DIFF_EXECUTABLE
787 PATH_SUFFIXES bin Bin
789 DOC "HDF5 file differencing tool." )
790 mark_as_advanced( HDF5_DIFF_EXECUTABLE )
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} )
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})
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})
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)
808 if(HDF5_USE_STATIC_LIBRARIES)
809 set(_inc_suffixes include/static)
811 set(_inc_suffixes include/shared)
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)
821 set(HDF5_INCLUDE_FILENAME hdf5.h)
824 find_path(HDF5_${_lang}_INCLUDE_DIR ${HDF5_INCLUDE_FILENAME}
826 PATHS $ENV{HOME}/.local/include
827 PATH_SUFFIXES include Include ${_inc_suffixes} ${_lib_suffixes}
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})
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)
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)
851 list(APPEND HDF5_DEFINITIONS "-DH5_BUILT_AS_DYNAMIC_LIB")
854 find_library(HDF5_${LIB}_LIBRARY_DEBUG
855 NAMES ${THIS_LIBRARY_SEARCH_DEBUG}
856 HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes}
859 find_library(HDF5_${LIB}_LIBRARY_RELEASE
860 NAMES ${THIS_LIBRARY_SEARCH_RELEASE}
861 HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes}
865 select_library_configurations( HDF5_${LIB} )
866 list(APPEND HDF5_${_lang}_LIBRARIES ${HDF5_${LIB}_LIBRARY})
868 if(HDF5_${_lang}_LIBRARIES)
869 set(HDF5_${_lang}_FOUND TRUE)
872 # Append the libraries for this language binding to the list of all
873 # required libraries.
874 list(APPEND HDF5_LIBRARIES ${HDF5_${_lang}_LIBRARIES})
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)
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)
892 find_library(HDF5_${LIB}_LIBRARY_DEBUG
893 NAMES ${THIS_LIBRARY_SEARCH_DEBUG}
894 HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes}
897 find_library(HDF5_${LIB}_LIBRARY_RELEASE
898 NAMES ${THIS_LIBRARY_SEARCH_RELEASE}
899 HINTS ${HDF5_ROOT} PATH_SUFFIXES lib Lib ${_lib_suffixes}
903 select_library_configurations( HDF5_${LIB} )
904 list(APPEND HDF5_${_lang}_HL_LIBRARIES ${HDF5_${LIB}_LIBRARY})
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})
912 if(HDF5_FIND_HL AND HDF5_HL_LIBRARIES)
913 set(HDF5_HL_FOUND TRUE)
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)
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 )
934 unset(HDF5_HAVE_PARALLEL_DEFINE)
936 file( STRINGS "${_hdr}"
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}" )
943 set( HDF5_VERSION ${HDF5_VERSION}.${CMAKE_MATCH_3})
946 unset(HDF5_VERSION_DEFINE)
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 )
956 set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS)
958 list(APPEND HDF5_REQUIRED_VARS HDF5_HL_LIBRARIES)
962 # For backwards compatibility we set HDF5_INCLUDE_DIR to the value of
964 if( HDF5_INCLUDE_DIRS )
965 set( HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIRS}" )
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
971 if(NOT HDF5_REQUIRED_VARS)
972 set(HDF5_REQUIRED_VARS HDF5_LIBRARIES HDF5_INCLUDE_DIRS)
975 find_package_handle_standard_args(HDF5
976 REQUIRED_VARS ${HDF5_REQUIRED_VARS}
977 VERSION_VAR HDF5_VERSION
981 unset(_HDF5_SEARCH_OPTS)
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)
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})
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")
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}")
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}}")
1026 # Error if we still don't have the location.
1028 "HDF5 was found, but a different variable was set which contains "
1029 "the location of the `hdf5::${hdf5_target_name}` library.")
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})
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
1044 INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB)
1045 elseif (_hdf5_libtype STREQUAL "STATIC")
1046 set_property(TARGET "hdf5::${hdf5_target_name}" APPEND
1048 INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB)
1050 unset(_hdf5_definitions)
1051 unset(_hdf5_libtype)
1052 unset(_hdf5_location)
1056 if (NOT HDF5_FIND_HL)
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")
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}")
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}}")
1089 # Error if we still don't have the location.
1091 "HDF5 was found, but a different variable was set which contains "
1092 "the location of the `hdf5::${hdf5_target_name}` library.")
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
1104 INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_DYNAMIC_LIB)
1105 elseif (_hdf5_libtype STREQUAL "STATIC")
1106 set_property(TARGET "hdf5::${hdf5_target_name}" APPEND
1108 INTERFACE_COMPILE_DEFINITIONS H5_BUILT_AS_STATIC_LIB)
1110 unset(_hdf5_definitions)
1111 unset(_hdf5_libtype)
1112 unset(_hdf5_location)
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}")
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}")
1142 unset(_HDF5_NEED_TO_SEARCH)