FindHDF5.cmake 38 KB

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