Salome HOME
ac0ffe766bc0202d4496cb781745414279aca5e6
[modules/kernel.git] / salome_adm / cmake_files / FindSalomeHDF5.cmake
1 # Copyright (C) 2013-2014  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, or (at your option) any later version.
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 : webmaster.salome@opencascade.com
18 #
19 # Author: Adrien Bruneton
20 #
21
22 # HDF5 detection for Salome
23 #
24 #  !! Please read the generic detection procedure in SalomeMacros.cmake !!
25
26 # --- HDF5 specificities ----
27 #  MPI root directory used for HDF5 compilation is exposed into MPI_ROOT_DIR_EXP
28 #
29
30 SET(HDF5_ROOT_DIR $ENV{HDF5_ROOT_DIR} CACHE PATH "Path to the HDF5.")
31
32 if(WIN32)
33   set(PREV_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
34   set(CMAKE_FIND_LIBRARY_SUFFIXES dll${CMAKE_IMPORT_LIBRARY_SUFFIX})
35   set(CMAKE_LIBRARY_PATH ${HDF5_ROOT_DIR}/dll)
36 endif()
37
38 SALOME_FIND_PACKAGE_AND_DETECT_CONFLICTS(HDF5 HDF5_INCLUDE_DIR 1)
39 MARK_AS_ADVANCED(FORCE HDF5_INCLUDE_DIR HDF5_LIB HDF5_DIR)
40
41 # Stupidly enough, CONFIG mode and MODULE mode for HDF5 do not return the same thing ...!
42 SET(HDF5_INCLUDE_DIRS "${HDF5_INCLUDE_DIRS};${HDF5_INCLUDE_DIR}")
43 # Same story with libraries - if in CONFIG mode, HDF5_LIBRARIES is not defined:
44 IF(NOT DEFINED HDF5_LIBRARIES)
45   SET(HDF5_LIBRARIES hdf5)
46 ENDIF()
47
48 ##
49 ## 7. Specific to HDF5 only:
50 ## Expose MPI configuration to the rest of the world
51 ##
52 IF(HDF5_ENABLE_PARALLEL OR HDF5_IS_PARALLEL)
53   # Set only one reference boolean variable:
54   # (unfortunately what is found in /usr/share/cmake/Modules/FindHDF5.cmake
55   #  and in the native HDF5-config.cmake differ!)
56   SET(HDF5_IS_PARALLEL TRUE)
57
58   # HDF5 was compiled with MPI support
59   # Unfortunately HDF5 doesn't expose its MPI configuration easily ...
60   # We sniff the properties of the HDF5 target which should also be there:
61   GET_PROPERTY(_lib_lst TARGET hdf5 PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG)
62   FOREACH(s ${_lib_lst})
63     STRING(FIND "${s}" "mpi." _res)   # should cover WIN(?) and LINUX
64     IF(_res GREATER -1)
65       GET_FILENAME_COMPONENT(_tmp "${s}" PATH)     # go up to levels
66       GET_FILENAME_COMPONENT(MPI_ROOT_DIR_EXP "${_tmp}" PATH)
67       BREAK()
68     ENDIF()
69   ENDFOREACH()
70   IF(NOT SalomeHDF5_FIND_QUIETLY)
71     MESSAGE(STATUS "HDF5 was compiled with MPI: ${MPI_ROOT_DIR_EXP}")
72   ENDIF()  
73 ENDIF()
74
75 ## Add definitions
76 ADD_DEFINITIONS(-DH5_USE_16_API)
77 IF(WIN32)
78   ADD_DEFINITIONS(-D_HDF5USEDLL_)
79 ENDIF()
80
81 ## Ensure SALOME uses MPI if HDF5 was parallel:
82 IF(HDF5_IS_PARALLEL AND NOT SALOME_USE_MPI)
83    MESSAGE(FATAL_ERROR "HDF5 is compiled with MPI, you have to set SALOME_USE_MPI to ON")
84 ENDIF()
85
86 if(WIN32)
87   set(CMAKE_FIND_LIBRARY_SUFFIXES ${PREV_CMAKE_FIND_LIBRARY_SUFFIXES})
88 endif()
89
90 IF(HDF5_FOUND) 
91   SALOME_ACCUMULATE_HEADERS(HDF5_INCLUDE_DIRS)
92   SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH ${HDF5_LIBRARIES})
93 ENDIF()