| 1 |
# Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE |
| 2 |
# |
| 3 |
# This library is free software; you can redistribute it and/or |
| 4 |
# modify it under the terms of the GNU Lesser General Public |
| 5 |
# License as published by the Free Software Foundation; either |
| 6 |
# version 2.1 of the License. |
| 7 |
# |
| 8 |
# This library is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
# Lesser General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU Lesser General Public |
| 14 |
# License along with this library; if not, write to the Free Software |
| 15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 |
# |
| 17 |
# See http://www.salome-platform.org/ or email : [email protected] |
| 18 |
# |
| 19 |
# Author: Adrien Bruneton |
| 20 |
# |
| 21 |
|
| 22 |
# HDF5 detection for med-file |
| 23 |
# |
| 24 |
# --- HDF5 specificities ---- |
| 25 |
# MPI root directory used for HDF5 compilation is exposed into MPI_ROOT_DIR_EXP |
| 26 |
# |
| 27 |
|
| 28 |
# 1. Load environment or any previously detected HDF5 |
| 29 |
IF(DEFINED ENV{HDF5_ROOT_DIR}) |
| 30 |
FILE(TO_CMAKE_PATH "$ENV{HDF5_ROOT_DIR}" _HDF5_ROOT_DIR_ENV) |
| 31 |
SET(_dflt_value "${_HDF5_ROOT_DIR_ENV}") |
| 32 |
ELSE() |
| 33 |
# will be blank if no HDF5 was previously loaded |
| 34 |
SET(_dflt_value "${HDF5_ROOT_DIR_EXP}") |
| 35 |
ENDIF() |
| 36 |
|
| 37 |
# Make cache entry |
| 38 |
SET(HDF5_ROOT_DIR "${_dflt_value}" CACHE PATH "Path to HDF5 directory") |
| 39 |
|
| 40 |
# 2. Find package - config mode first (i.e. looking for XYZ-config.cmake) |
| 41 |
IF(EXISTS "${HDF5_ROOT_DIR}") |
| 42 |
# Hope to find direclty a CMake config file there |
| 43 |
IF(WIN32) |
| 44 |
SET(_CONF_DIR "${HDF5_ROOT_DIR}/cmake/hdf5") |
| 45 |
ELSE() |
| 46 |
SET(_CONF_DIR "${HDF5_ROOT_DIR}/share/cmake/hdf5") |
| 47 |
ENDIF() |
| 48 |
# Try find_package in config mode with a hard-coded guess. This |
| 49 |
# has the priority. |
| 50 |
SET(_OPT static) |
| 51 |
IF (MEDFILE_BUILD_SHARED_LIBS) |
| 52 |
SET(_OPT shared) |
| 53 |
ENDIF() |
| 54 |
# [ABN] from HDF5 1.10.1, CMake procedure has become ... complicated: |
| 55 |
FIND_PACKAGE(HDF5 CONFIG COMPONENTS C ${_opt} QUIET PATHS "${_CONF_DIR}" |
| 56 |
NO_CMAKE_BUILDS_PATH NO_CMAKE_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PACKAGE_REGISTRY) |
| 57 |
|
| 58 |
IF (NOT (HDF5_FOUND OR hdf5_FOUND)) |
| 59 |
SET(CMAKE_PREFIX_PATH "${HDF5_ROOT_DIR}") |
| 60 |
ELSE() |
| 61 |
MESSAGE(STATUS "Found HDF5 in CONFIG mode!") |
| 62 |
# Official CMake FindXXX module says HDF5_INCLUDE_DIR is deprecated |
| 63 |
# but as of HDF5-1.8.10 this is still the only thing found in the config file ... |
| 64 |
SET(HDF5_INCLUDE_DIRS "${HDF5_INCLUDE_DIR}") |
| 65 |
ENDIF() |
| 66 |
ENDIF() |
| 67 |
|
| 68 |
|
| 69 |
# Otherwise try the standard way (module mode, with the standard CMake Find*** macro): |
| 70 |
INCLUDE(medMacros) |
| 71 |
SALOME_FIND_PACKAGE(MedfileHDF5 HDF5 MODULE) |
| 72 |
SET(MEDFILEHDF5_FOUND ${HDF5_FOUND}) |
| 73 |
|
| 74 |
IF (HDF5_FOUND) |
| 75 |
MESSAGE(STATUS "Found HDF5 version " ${HDF5_VERSION} " -- parallel flag is set to " ${HDF5_ENABLE_PARALLEL}) |
| 76 |
# 3. Set the root dir which was finally retained |
| 77 |
# For HDF5 this is the parent of the |
| 78 |
# include directory: |
| 79 |
LIST(LENGTH HDF5_INCLUDE_DIRS _tmp_len) |
| 80 |
IF(_tmp_len) |
| 81 |
LIST(GET HDF5_INCLUDE_DIRS 0 _tmp_ROOT_DIR) |
| 82 |
ELSE() |
| 83 |
SET(_tmp_ROOT_DIR "${HDF5_INCLUDE_DIRS}") |
| 84 |
ENDIF() |
| 85 |
|
| 86 |
# Go up one level: |
| 87 |
GET_FILENAME_COMPONENT(_tmp_ROOT_DIR "${_tmp_ROOT_DIR}" PATH) |
| 88 |
|
| 89 |
# 4. Warn if CMake found something not located under ENV(XYZ_ROOT_DIR) |
| 90 |
IF(DEFINED ENV{HDF5_ROOT_DIR}) |
| 91 |
SALOME_CHECK_EQUAL_PATHS(_res "${_tmp_ROOT_DIR}" "${_HDF5_ROOT_DIR_ENV}") |
| 92 |
IF(NOT _res) |
| 93 |
MESSAGE(WARNING "HDF5 was found, but not at the path given by the " |
| 94 |
"environment HDF5_ROOT_DIR! Is the variable correctly set?" |
| 95 |
"The two paths are: ${_tmp_ROOT_DIR} and ${_HDF5_ROOT_DIR_ENV}") |
| 96 |
ELSE() |
| 97 |
MESSAGE(STATUS "HDF5 found directory matches what was specified in the HDF5_ROOT_DIR, all good!") |
| 98 |
ENDIF() |
| 99 |
ENDIF() |
| 100 |
|
| 101 |
# 5. Conflict detection |
| 102 |
# 5.1 From another prerequisite using HDF5 |
| 103 |
IF(HDF5_ROOT_DIR_EXP) |
| 104 |
SALOME_CHECK_EQUAL_PATHS(_res "${_tmp_ROOT_DIR}" "${HDF5_ROOT_DIR_EXP}") |
| 105 |
IF(NOT _res) |
| 106 |
MESSAGE(WARNING "Warning: HDF5: found version conflicts with a previously found HDF5!" |
| 107 |
"The two paths are " ${_tmp_ROOT_DIR} " vs " ${HDF5_ROOT_DIR_EXP}) |
| 108 |
ELSE() |
| 109 |
MESSAGE(STATUS "HDF5 directory matches what was previously exposed by another prereq, all good!") |
| 110 |
ENDIF() |
| 111 |
ENDIF() |
| 112 |
|
| 113 |
# 6. Expose MPI configuration to the rest of the world |
| 114 |
IF(HDF5_ENABLE_PARALLEL) |
| 115 |
# HDF5 was compiled with MPI support |
| 116 |
# Unfortunately HDF5 doesn't expose its MPI configuration easily ... |
| 117 |
# We sniff the properties of the HDF5 target which should also be there: |
| 118 |
GET_PROPERTY(_lib_lst TARGET hdf5 PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG) |
| 119 |
FOREACH(s ${_lib_lst}) |
| 120 |
STRING(FIND "${s}" "mpi." _res) # should cover WIN(?) and LINUX |
| 121 |
IF(_res GREATER -1) |
| 122 |
GET_FILENAME_COMPONENT(_tmp "${s}" PATH) # go up to levels |
| 123 |
GET_FILENAME_COMPONENT(MPI_ROOT_DIR_EXP "${_tmp}" PATH) |
| 124 |
BREAK() |
| 125 |
ENDIF() |
| 126 |
ENDFOREACH() |
| 127 |
ENDIF(HDF5_ENABLE_PARALLEL) |
| 128 |
|
| 129 |
# Make some advanced stuff hidden by default: |
| 130 |
MARK_AS_ADVANCED(FORCE HDF5_INCLUDE_DIR HDF5_INCLUDE_DIRS HDF5_LIB HDF5_DIR) |
| 131 |
|
| 132 |
# As of HDF5-1.8.11 the following is still not set in the exported CONFIG |
| 133 |
# of the official hdf5-config.cmake. We add it ourselves: |
| 134 |
IF(NOT DEFINED HDF5_LIBRARIES) |
| 135 |
IF(NOT TARGET hdf5 AND NOT TARGET hdf5-static AND NOT TARGET hdf5-shared) |
| 136 |
# Some HDF5 versions (e.g. 1.8.18) used hdf5::hdf5 etc |
| 137 |
SET(_target_prefix "hdf5::") |
| 138 |
ENDIF() |
| 139 |
IF(MEDFILE_BUILD_SHARED_LIBS) |
| 140 |
SET(_suffix "-shared") |
| 141 |
ELSE() |
| 142 |
SET(_suffix "-static") |
| 143 |
ENDIF() |
| 144 |
SET(HDF5_LIBRARIES "${_target_prefix}hdf5${_suffix}") |
| 145 |
ENDIF() |
| 146 |
|
| 147 |
SET(HDF5_ROOT_DIR ${_tmp_ROOT_DIR}) |
| 148 |
|
| 149 |
# Parse HDF5_VERSION to extract major, minor and release number |
| 150 |
if(NOT HDF5_VERSION) |
| 151 |
MESSAGE(STATUS "Cannot find HDF5_VERSION - maybe cmake is too old") |
| 152 |
set( HDF5_VERSION "" ) |
| 153 |
foreach( _dir IN LISTS HDF5_INCLUDE_DIRS ) |
| 154 |
foreach(_hdr "${_dir}/H5pubconf.h" "${_dir}/H5pubconf-64.h" "${_dir}/H5pubconf-32.h") |
| 155 |
if( EXISTS "${_hdr}" ) |
| 156 |
#MESSAGE(STATUS "_hdr=${_hdr}") |
| 157 |
file( STRINGS "${_hdr}" |
| 158 |
HDF5_VERSION_DEFINE |
| 159 |
REGEX "^[ \t]*#[ \t]*define[ \t]+H5_VERSION[ \t]+" ) |
| 160 |
#MESSAGE(STATUS "HDF5_VERSION_DEFINE=${HDF5_VERSION_DEFINE}") |
| 161 |
if( "${HDF5_VERSION_DEFINE}" MATCHES |
| 162 |
"H5_VERSION[ \t]+\"([0-9]+\\.[0-9]+\\.[0-9]+)(-patch([0-9]+))?\"" ) |
| 163 |
set( HDF5_VERSION "${CMAKE_MATCH_1}" ) |
| 164 |
if( CMAKE_MATCH_3 ) |
| 165 |
set( HDF5_VERSION ${HDF5_VERSION}.${CMAKE_MATCH_3}) |
| 166 |
endif() |
| 167 |
endif() |
| 168 |
#MESSAGE(STATUS "HDF5_VERSION=${HDF5_VERSION}") |
| 169 |
unset(HDF5_VERSION_DEFINE) |
| 170 |
endif() |
| 171 |
endforeach() |
| 172 |
endforeach() |
| 173 |
endif(NOT HDF5_VERSION) |
| 174 |
|
| 175 |
STRING (REGEX MATCHALL "[0-9]+" _versionComponents "${HDF5_VERSION}") |
| 176 |
MESSAGE(STATUS "_versionComponents=${_versionComponents}") |
| 177 |
MESSAGE(STATUS "HDF5_VERSION=${HDF5_VERSION}") |
| 178 |
LIST(GET _versionComponents 0 HDF_VERSION_MAJOR_REF) |
| 179 |
LIST(GET _versionComponents 1 HDF_VERSION_MINOR_REF) |
| 180 |
LIST(GET _versionComponents 2 HDF_VERSION_RELEASE_REF) |
| 181 |
SET(HDF_VERSION_REF "${HDF5_VERSION}") |
| 182 |
|
| 183 |
ELSE(HDF5_FOUND) |
| 184 |
MESSAGE(STATUS "HDF5 was not found.") |
| 185 |
ENDIF(HDF5_FOUND) |