FindHDF5.cmake 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # 防止重复引入
  2. if(GJDM_HDF5_ALREADY_INCLUDED)
  3. return()
  4. endif()
  5. set(GJDM_HDF5_ALREADY_INCLUDED 1)
  6. # find_path 搜索包含某个文件的路径
  7. # 如果在某个路径下发现了该文件,该结果会被存储到该变量中;如果没有找到,存储的结果将会是<VAR>-NOTFOUND
  8. find_path(HDF5_DIRS
  9. NAMES
  10. include/hdf5.h
  11. PATHS
  12. ${CMAKE_SOURCE_DIR}/extlib/HDF5
  13. NO_SYSTEM_ENVIRONMENT_PATH
  14. NO_CMAKE_SYSTEM_PATH
  15. )
  16. set(HDF5_VERSION_MAJOR 1)
  17. set(HDF5_VERSION_MINOR 13)
  18. set(HDF5_VERSION_PATCH 1)
  19. set(HDF5_VERSION "${HDF5_VERSION_MAJOR}.${HDF5_VERSION_MINOR}.${HDF5_VERSION_PATCH}")
  20. find_path(HDF5_INCLUDE_DIRS
  21. NAMES
  22. hdf5.h
  23. HINTS
  24. ${HDF5_DIRS}/include
  25. )
  26. find_path(HDF5_LIBRARY_DIRS
  27. NAMES
  28. hdf5.lib libhdf5.so
  29. HINTS
  30. ${HDF5_DIRS}/lib
  31. )
  32. set(HDF5_LIBRARIES GJDM::HDF5;GJDM::HDF5CPP;GJDM::HDF5HL;GJDM::HDF5HLCPP;GJDM::HDF5TOOLS)
  33. add_library(GJDM::HDF5 SHARED IMPORTED)
  34. add_library(GJDM::HDF5CPP SHARED IMPORTED)
  35. add_library(GJDM::HDF5HL SHARED IMPORTED)
  36. add_library(GJDM::HDF5HLCPP SHARED IMPORTED)
  37. add_library(GJDM::HDF5TOOLS SHARED IMPORTED)
  38. set_property(TARGET GJDM::HDF5 PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
  39. set_property(TARGET GJDM::HDF5 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
  40. set_property(TARGET GJDM::HDF5 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  41. set_property(TARGET GJDM::HDF5CPP PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
  42. set_property(TARGET GJDM::HDF5CPP PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
  43. set_property(TARGET GJDM::HDF5CPP APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  44. set_property(TARGET GJDM::HDF5CPP PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5)
  45. set_property(TARGET GJDM::HDF5HL PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
  46. set_property(TARGET GJDM::HDF5HL PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
  47. set_property(TARGET GJDM::HDF5HL APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  48. set_property(TARGET GJDM::HDF5HL PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5)
  49. set_property(TARGET GJDM::HDF5HLCPP PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
  50. set_property(TARGET GJDM::HDF5HLCPP PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
  51. set_property(TARGET GJDM::HDF5HLCPP APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  52. set_property(TARGET GJDM::HDF5HLCPP PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5HL)
  53. set_property(TARGET GJDM::HDF5TOOLS PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
  54. set_property(TARGET GJDM::HDF5TOOLS PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
  55. set_property(TARGET GJDM::HDF5TOOLS APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
  56. set_property(TARGET GJDM::HDF5TOOLS PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5)
  57. if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  58. set_target_properties(GJDM::HDF5 PROPERTIES
  59. IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5.so.300.1.0"
  60. IMPORTED_SONAME_RELEASE "libhdf5.so.300"
  61. )
  62. set_target_properties(GJDM::HDF5CPP PROPERTIES
  63. IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_cpp.so.300.0.1"
  64. IMPORTED_SONAME_RELEASE "libhdf5_cpp.so.300"
  65. )
  66. set_target_properties(GJDM::HDF5HL PROPERTIES
  67. IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_hl.so.300.0.1"
  68. IMPORTED_SONAME_RELEASE "libhdf5_hl.so.300"
  69. )
  70. set_target_properties(GJDM::HDF5HLCPP PROPERTIES
  71. IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_hl_cpp.so.300.0.1"
  72. IMPORTED_SONAME_RELEASE "libhdf5_hl_cpp.so.300"
  73. )
  74. set_target_properties(GJDM::HDF5TOOLS PROPERTIES
  75. IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_tools.so.300.0.1"
  76. IMPORTED_SONAME_RELEASE "libhdf5_tools.so.300"
  77. )
  78. elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  79. set_target_properties(GJDM::HDF5 PROPERTIES
  80. IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5.lib"
  81. IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5.dll"
  82. )
  83. set_target_properties(GJDM::HDF5CPP PROPERTIES
  84. IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_cpp.lib"
  85. IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_cpp.dll"
  86. )
  87. set_target_properties(GJDM::HDF5HL PROPERTIES
  88. IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_hl.lib"
  89. IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_hl.dll"
  90. )
  91. set_target_properties(GJDM::HDF5HLCPP PROPERTIES
  92. IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_hl_cpp.lib"
  93. IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_hl_cpp.dll"
  94. )
  95. set_target_properties(GJDM::HDF5TOOLS PROPERTIES
  96. IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_tools.lib"
  97. IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_tools.dll"
  98. )
  99. endif()
  100. include(FindPackageHandleStandardArgs)
  101. # 如果找到所有需要的变量,并且版本匹配,则将HDF5_FOUND变量设置为TRUE
  102. find_package_handle_standard_args(HDF5
  103. FOUND_VAR
  104. HDF5_FOUND
  105. REQUIRED_VARS
  106. HDF5_DIRS
  107. HDF5_INCLUDE_DIRS
  108. HDF5_LIBRARY_DIRS
  109. HDF5_LIBRARIES
  110. VERSION_VAR
  111. HDF5_VERSION
  112. )