forked from lbaehren/CMakeModules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindHDF5.cmake
154 lines (125 loc) · 5.64 KB
/
FindHDF5.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#-------------------------------------------------------------------------------
# Copyright (c) 2013-2013, Lars Baehren <[email protected]>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-------------------------------------------------------------------------------
# - Check for the presence of HDF5
#
# The following variables are set when HDF5 is found:
# HDF5_FOUND = Set to true, if all components of HDF5 have been found.
# HDF5_INCLUDES = Include path for the header files of HDF5
# HDF5_LIBRARIES = Link these to use HDF5
# HDF5_LFLAGS = Linker flags (optional)
if (NOT HDF5_FOUND)
if (NOT HDF5_ROOT_DIR)
set (HDF5_ROOT_DIR ${CMAKE_INSTALL_PREFIX})
endif (NOT HDF5_ROOT_DIR)
##____________________________________________________________________________
## Check for the header files
find_path (HDF5_INCLUDES
NAMES hdf5.h hdf5_hl.h
HINTS ${HDF5_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
PATH_SUFFIXES include
)
##____________________________________________________________________________
## Check for the library
set (HDF5_LIBRARIES "")
foreach (_lib hdf5 hdf5_hl hdf5_cpp hdf5_hl_cpp)
string (TOUPPER ${_lib} _libUpper)
find_library (HDF5_${_libUpper}_LIBRARY ${_lib}
HINTS ${HDF5_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
PATH_SUFFIXES lib
DOC "HDF5 ${_lib} library."
)
if (HDF5_${_libUpper}_LIBRARY)
list (APPEND HDF5_LIBRARIES ${HDF5_${_libUpper}_LIBRARY})
endif ()
endforeach (_lib)
##____________________________________________________________________________
## Check for the executable
find_program (HDF5_C_COMPILER_EXECUTABLE h5cc h5pcc
HINTS ${HDF5_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
PATH_SUFFIXES bin
DOC "HDF5 wrapper compiler."
)
find_program (HDF5_CXX_COMPILER_EXECUTABLE h5c++ h5pc++
HINTS ${HDF5_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
PATH_SUFFIXES bin
DOC "HDF5 C++ wrapper compiler."
)
find_program (HDF5_DIFF_EXECUTABLE h5diff
HINTS ${HDF5_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
PATH_SUFFIXES bin
)
##____________________________________________________________________________
## Determine library version
if (HDF5_INCLUDES AND HDF5_LIBRARIES)
find_file (HAVE_TESTHDF5_CC TestHDF5LibraryVersion.cc
HINTS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_MODULE_PATH}
)
try_run (run_TestHDF5 compile_TestHDF5
${PROJECT_BINARY_DIR}/TestHDF5
${HAVE_TESTHDF5_CC}
CMAKE_FLAGS -DINCLUDE_DIRECTORIES=${HDF5_INCLUDES} -DLINK_LIBRARIES=${HDF5_LIBRARIES}
RUN_OUTPUT_VARIABLE HDF5_VERSION
)
if (HDF5_VERSION)
## extract partial version numbers
list (GET HDF5_VERSION 0 HDF5_VERSION_MAJOR)
list (GET HDF5_VERSION 1 HDF5_VERSION_MINOR)
list (GET HDF5_VERSION 2 HDF5_VERSION_PATH)
## assemble full version number
set (HDF5_VERSION "${HDF5_VERSION_MAJOR}.${HDF5_VERSION_MINOR}.${HDF5_VERSION_PATH}")
endif (HDF5_VERSION)
endif ()
##____________________________________________________________________________
## Actions taken when all components have been found
find_package_handle_standard_args (HDF5 DEFAULT_MSG HDF5_LIBRARIES HDF5_INCLUDES)
if (HDF5_FOUND)
if (NOT HDF5_FIND_QUIETLY)
message (STATUS "Found components for HDF5")
message (STATUS "HDF5_ROOT_DIR = ${HDF5_ROOT_DIR}")
message (STATUS "HDF5_C_COMPILER_EXECUTABLE = ${HDF5_C_COMPILER_EXECUTABLE}")
message (STATUS "HDF5_CXX_COMPILER_EXECUTABLE = ${HDF5_CXX_COMPILER_EXECUTABLE}")
message (STATUS "HDF5_INCLUDES = ${HDF5_INCLUDES}")
message (STATUS "HDF5_HDF5_LIBRARY = ${HDF5_HDF5_LIBRARY}")
message (STATUS "HDF5_HDF5_HL_LIBRARY = ${HDF5_HDF5_HL_LIBRARY}")
message (STATUS "HDF5_HDF5_CPP_LIBRARY = ${HDF5_HDF5_CPP_LIBRARY}")
message (STATUS "HDF5_HDF5_HL_CPP_LIBRARY = ${HDF5_HDF5_HL_CPP_LIBRARY}")
endif (NOT HDF5_FIND_QUIETLY)
else (HDF5_FOUND)
if (HDF5_FIND_REQUIRED)
message (FATAL_ERROR "Could not find HDF5!")
endif (HDF5_FIND_REQUIRED)
endif (HDF5_FOUND)
##____________________________________________________________________________
## Mark advanced variables
mark_as_advanced (
HDF5_ROOT_DIR
HDF5_INCLUDES
HDF5_LIBRARIES
HDF5_HDF5_LIBRARY
HDF5_HDF5_HL_LIBRARY
HDF5_HDF5_CPP_LIBRARY
HDF5_HDF5_HL_CPP_LIBRARY
)
endif (NOT HDF5_FOUND)