FindHDF5.cmake 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # FindHDF5
  2. # --------
  3. #
  4. # Find the HDF5 libraries(Only for HDF5 provided by FastCAE)
  5. #
  6. # Result Variables
  7. # ^^^^^^^^^^^^^^^^
  8. #
  9. # The following variables will be defined:
  10. #
  11. # ``HDF5_FOUND`` True if HDF5 found on the local system
  12. #
  13. # ``HDF5_VERSION`` HDF5 Version(x.x.x)
  14. #
  15. # ``HDF5_VERSION_MAJOR`` HDF5 Major Version
  16. #
  17. # ``HDF5_VERSION_MINOR`` HDF5 Minor Version
  18. #
  19. # ``HDF5_VERSION_PATCH`` HDF5 Patch Version
  20. #
  21. # ``HDF5_DIRS`` Location of HDF5(root dir)
  22. #
  23. # ``HDF5_INCLUDE_DIRS`` Location of HDF5 header files
  24. #
  25. # ``HDF5_LIBRARY_DIRS`` Location of HDF5 libraries
  26. #
  27. # ``HDF5_LIBRARIES`` List of the HDF5 libraries found
  28. #
  29. # 防止重复引入
  30. if(GJDM_HDF5_ALREADY_INCLUDED)
  31. return()
  32. endif()
  33. set(GJDM_HDF5_ALREADY_INCLUDED 1)
  34. # find_path 搜索包含某个文件的路径
  35. # 如果在某个路径下发现了该文件,该结果会被存储到该变量中;如果没有找到,存储的结果将会是<VAR>-NOTFOUND
  36. find_path(HDF5_DIRS
  37. NAMES
  38. include/hdf5.h
  39. PATHS
  40. ${CMAKE_SOURCE_DIR}/extlib/HDF5
  41. NO_SYSTEM_ENVIRONMENT_PATH
  42. NO_CMAKE_SYSTEM_PATH
  43. )
  44. set(HDF5_VERSION_MAJOR 1)
  45. set(HDF5_VERSION_MINOR 13)
  46. set(HDF5_VERSION_PATCH 1)
  47. set(HDF5_VERSION "${HDF5_VERSION_MAJOR}.${HDF5_VERSION_MINOR}.${HDF5_VERSION_PATCH}")
  48. find_path(HDF5_INCLUDE_DIRS
  49. NAMES
  50. hdf5.h
  51. HINTS
  52. ${HDF5_DIRS}/include
  53. )
  54. find_path(HDF5_LIBRARY_DIRS
  55. NAMES
  56. hdf5.lib libhdf5.so
  57. HINTS
  58. ${HDF5_DIRS}/lib
  59. )
  60. set(HDF5_LIBRARIES GJDM::HDF5;GJDM::HDF5CPP;GJDM::HDF5HL;GJDM::HDF5HLCPP;GJDM::HDF5TOOLS)
  61. add_library(GJDM::HDF5 SHARED IMPORTED)
  62. add_library(GJDM::HDF5CPP SHARED IMPORTED)
  63. add_library(GJDM::HDF5HL SHARED IMPORTED)
  64. add_library(GJDM::HDF5HLCPP SHARED IMPORTED)
  65. add_library(GJDM::HDF5TOOLS SHARED IMPORTED)
  66. set_property(TARGET GJDM::HDF5 PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
  67. set_property(TARGET GJDM::HDF5 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
  68. set_property(TARGET GJDM::HDF5 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  69. set_property(TARGET GJDM::HDF5CPP PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
  70. set_property(TARGET GJDM::HDF5CPP PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
  71. set_property(TARGET GJDM::HDF5CPP APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  72. set_property(TARGET GJDM::HDF5CPP PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5)
  73. set_property(TARGET GJDM::HDF5HL PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
  74. set_property(TARGET GJDM::HDF5HL PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
  75. set_property(TARGET GJDM::HDF5HL APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  76. set_property(TARGET GJDM::HDF5HL PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5)
  77. set_property(TARGET GJDM::HDF5HLCPP PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
  78. set_property(TARGET GJDM::HDF5HLCPP PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
  79. set_property(TARGET GJDM::HDF5HLCPP APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  80. set_property(TARGET GJDM::HDF5HLCPP PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5HL)
  81. set_property(TARGET GJDM::HDF5TOOLS PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
  82. set_property(TARGET GJDM::HDF5TOOLS PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
  83. set_property(TARGET GJDM::HDF5TOOLS APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  84. set_property(TARGET GJDM::HDF5TOOLS PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5)
  85. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  86. set_target_properties(GJDM::HDF5 PROPERTIES
  87. IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5.so.300.1.0"
  88. IMPORTED_SONAME_RELEASE "libhdf5.so.300"
  89. )
  90. set_target_properties(GJDM::HDF5CPP PROPERTIES
  91. IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_cpp.so.300.0.1"
  92. IMPORTED_SONAME_RELEASE "libhdf5_cpp.so.300"
  93. )
  94. set_target_properties(GJDM::HDF5HL PROPERTIES
  95. IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_hl.so.300.0.1"
  96. IMPORTED_SONAME_RELEASE "libhdf5_hl.so.300"
  97. )
  98. set_target_properties(GJDM::HDF5HLCPP PROPERTIES
  99. IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_hl_cpp.so.300.0.1"
  100. IMPORTED_SONAME_RELEASE "libhdf5_hl_cpp.so.300"
  101. )
  102. set_target_properties(GJDM::HDF5TOOLS PROPERTIES
  103. IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_tools.so.300.0.1"
  104. IMPORTED_SONAME_RELEASE "libhdf5_tools.so.300"
  105. )
  106. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  107. set_target_properties(GJDM::HDF5 PROPERTIES
  108. IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5.lib"
  109. IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5.dll"
  110. )
  111. set_target_properties(GJDM::HDF5CPP PROPERTIES
  112. IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_cpp.lib"
  113. IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_cpp.dll"
  114. )
  115. set_target_properties(GJDM::HDF5HL PROPERTIES
  116. IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_hl.lib"
  117. IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_hl.dll"
  118. )
  119. set_target_properties(GJDM::HDF5HLCPP PROPERTIES
  120. IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_hl_cpp.lib"
  121. IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_hl_cpp.dll"
  122. )
  123. set_target_properties(GJDM::HDF5TOOLS PROPERTIES
  124. IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_tools.lib"
  125. IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_tools.dll"
  126. )
  127. endif()
  128. include(FindPackageHandleStandardArgs)
  129. # 如果找到所有需要的变量,并且版本匹配,则将HDF5_FOUND变量设置为TRUE
  130. find_package_handle_standard_args(HDF5
  131. FOUND_VAR
  132. HDF5_FOUND
  133. REQUIRED_VARS
  134. HDF5_DIRS
  135. HDF5_INCLUDE_DIRS
  136. HDF5_LIBRARY_DIRS
  137. HDF5_LIBRARIES
  138. VERSION_VAR
  139. HDF5_VERSION
  140. )