FindHDF5.cmake 38 KB

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