FindHDF5.cmake 53 KB

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