123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- # FindHDF5
- # --------
- #
- # Find the HDF5 libraries(Only for HDF5 provided by FastCAE)
- #
- # Result Variables
- # ^^^^^^^^^^^^^^^^
- #
- # The following variables will be defined:
- #
- # ``HDF5_FOUND`` True if HDF5 found on the local system
- #
- # ``HDF5_VERSION`` HDF5 Version(x.x.x)
- #
- # ``HDF5_VERSION_MAJOR`` HDF5 Major Version
- #
- # ``HDF5_VERSION_MINOR`` HDF5 Minor Version
- #
- # ``HDF5_VERSION_PATCH`` HDF5 Patch Version
- #
- # ``HDF5_DIRS`` Location of HDF5(root dir)
- #
- # ``HDF5_INCLUDE_DIRS`` Location of HDF5 header files
- #
- # ``HDF5_LIBRARY_DIRS`` Location of HDF5 libraries
- #
- # ``HDF5_LIBRARIES`` List of the HDF5 libraries found
- #
- # 防止重复引入
- if(GJDM_HDF5_ALREADY_INCLUDED)
- return()
- endif()
- set(GJDM_HDF5_ALREADY_INCLUDED 1)
- # find_path 搜索包含某个文件的路径
- # 如果在某个路径下发现了该文件,该结果会被存储到该变量中;如果没有找到,存储的结果将会是<VAR>-NOTFOUND
- find_path(HDF5_DIRS
- NAMES
- include/hdf5.h
- PATHS
- ${CMAKE_SOURCE_DIR}/extlib/HDF5
- NO_SYSTEM_ENVIRONMENT_PATH
- NO_CMAKE_SYSTEM_PATH
- )
- set(HDF5_VERSION_MAJOR 1)
- set(HDF5_VERSION_MINOR 13)
- set(HDF5_VERSION_PATCH 1)
- set(HDF5_VERSION "${HDF5_VERSION_MAJOR}.${HDF5_VERSION_MINOR}.${HDF5_VERSION_PATCH}")
- find_path(HDF5_INCLUDE_DIRS
- NAMES
- hdf5.h
- HINTS
- ${HDF5_DIRS}/include
- )
- find_path(HDF5_LIBRARY_DIRS
- NAMES
- hdf5.lib libhdf5.so
- HINTS
- ${HDF5_DIRS}/lib
- )
- set(HDF5_LIBRARIES GJDM::HDF5;GJDM::HDF5CPP;GJDM::HDF5HL;GJDM::HDF5HLCPP;GJDM::HDF5TOOLS)
- add_library(GJDM::HDF5 SHARED IMPORTED)
- add_library(GJDM::HDF5CPP SHARED IMPORTED)
- add_library(GJDM::HDF5HL SHARED IMPORTED)
- add_library(GJDM::HDF5HLCPP SHARED IMPORTED)
- add_library(GJDM::HDF5TOOLS SHARED IMPORTED)
- set_property(TARGET GJDM::HDF5 PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
- set_property(TARGET GJDM::HDF5 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
- set_property(TARGET GJDM::HDF5 APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
- set_property(TARGET GJDM::HDF5CPP PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
- set_property(TARGET GJDM::HDF5CPP PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
- set_property(TARGET GJDM::HDF5CPP APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
- set_property(TARGET GJDM::HDF5CPP PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5)
- set_property(TARGET GJDM::HDF5HL PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
- set_property(TARGET GJDM::HDF5HL PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
- set_property(TARGET GJDM::HDF5HL APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
- set_property(TARGET GJDM::HDF5HL PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5)
- set_property(TARGET GJDM::HDF5HLCPP PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
- set_property(TARGET GJDM::HDF5HLCPP PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
- set_property(TARGET GJDM::HDF5HLCPP APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
- set_property(TARGET GJDM::HDF5HLCPP PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5HL)
- set_property(TARGET GJDM::HDF5TOOLS PROPERTY INTERFACE_COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB")
- set_property(TARGET GJDM::HDF5TOOLS PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS})
- set_property(TARGET GJDM::HDF5TOOLS APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
- set_property(TARGET GJDM::HDF5TOOLS PROPERTY INTERFACE_LINK_LIBRARIES GJDM::HDF5)
- if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
- set_target_properties(GJDM::HDF5 PROPERTIES
- IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5.so.300.1.0"
- IMPORTED_SONAME_RELEASE "libhdf5.so.300"
- )
- set_target_properties(GJDM::HDF5CPP PROPERTIES
- IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_cpp.so.300.0.1"
- IMPORTED_SONAME_RELEASE "libhdf5_cpp.so.300"
- )
- set_target_properties(GJDM::HDF5HL PROPERTIES
- IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_hl.so.300.0.1"
- IMPORTED_SONAME_RELEASE "libhdf5_hl.so.300"
- )
- set_target_properties(GJDM::HDF5HLCPP PROPERTIES
- IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_hl_cpp.so.300.0.1"
- IMPORTED_SONAME_RELEASE "libhdf5_hl_cpp.so.300"
- )
- set_target_properties(GJDM::HDF5TOOLS PROPERTIES
- IMPORTED_LOCATION_RELEASE "${HDF5_LIBRARY_DIRS}/libhdf5_tools.so.300.0.1"
- IMPORTED_SONAME_RELEASE "libhdf5_tools.so.300"
- )
- elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
- set_target_properties(GJDM::HDF5 PROPERTIES
- IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5.lib"
- IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5.dll"
- )
- set_target_properties(GJDM::HDF5CPP PROPERTIES
- IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_cpp.lib"
- IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_cpp.dll"
- )
- set_target_properties(GJDM::HDF5HL PROPERTIES
- IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_hl.lib"
- IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_hl.dll"
- )
- set_target_properties(GJDM::HDF5HLCPP PROPERTIES
- IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_hl_cpp.lib"
- IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_hl_cpp.dll"
- )
- set_target_properties(GJDM::HDF5TOOLS PROPERTIES
- IMPORTED_IMPLIB_RELEASE "${HDF5_LIBRARY_DIRS}/hdf5_tools.lib"
- IMPORTED_LOCATION_RELEASE "${HDF5_DIRS}/bin/hdf5_tools.dll"
- )
- endif()
- include(FindPackageHandleStandardArgs)
- # 如果找到所有需要的变量,并且版本匹配,则将HDF5_FOUND变量设置为TRUE
- find_package_handle_standard_args(HDF5
- FOUND_VAR
- HDF5_FOUND
- REQUIRED_VARS
- HDF5_DIRS
- HDF5_INCLUDE_DIRS
- HDF5_LIBRARY_DIRS
- HDF5_LIBRARIES
- VERSION_VAR
- HDF5_VERSION
- )
|