FindHDF5.cmake 38 KB

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