blob: d9bf67fa4803584e5dc3b34a68405a8b933d3774 (
plain)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
#-------------------------------------------------------------------------------
macro (BASIC_SETTINGS varname)
string (TOUPPER ${varname} EXAMPLE_PACKAGE_VARNAME)
string (TOLOWER ${varname} EXAMPLE_VARNAME)
set (H5${EXAMPLE_PACKAGE_VARNAME}_PACKAGE "h5${EXAMPLE_VARNAME}")
set (H5${EXAMPLE_PACKAGE_VARNAME}_PACKAGE_NAME "h5${EXAMPLE_VARNAME}")
string (TOUPPER ${H5${EXAMPLE_PACKAGE_VARNAME}_PACKAGE_NAME} EXAMPLE_PACKAGE_NAME)
string (TOLOWER ${H5${EXAMPLE_PACKAGE_VARNAME}_PACKAGE_NAME} EXAMPLE_NAME)
set (CMAKE_NO_SYSTEM_FROM_IMPORTED 1)
#-----------------------------------------------------------------------------
# Define some CMake variables for use later in the project
#-----------------------------------------------------------------------------
set (${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR ${${EXAMPLE_PACKAGE_NAME}_SOURCE_DIR}/config/cmake)
set (${EXAMPLE_PACKAGE_NAME}_SRC_DIR ${${EXAMPLE_PACKAGE_NAME}_SOURCE_DIR}/src)
#-----------------------------------------------------------------------------
# Setup output Directories
#-----------------------------------------------------------------------------
if (NOT ${EXAMPLE_PACKAGE_NAME}_EXTERNALLY_CONFIGURED)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all Executables."
)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all Libraries"
)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all static libraries."
)
set (CMAKE_Fortran_MODULE_DIRECTORY
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all fortran modules."
)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
set (CMAKE_TEST_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE})
set (CMAKE_PDB_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all pdb files."
)
else ()
set (CMAKE_TEST_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif ()
else ()
# if we are externally configured, but the project uses old cmake scripts
# this may not be set
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
endif ()
endif ()
#-----------------------------------------------------------------------------
# Option to use Shared/Static libs, default is static
#-----------------------------------------------------------------------------
set (LIB_TYPE STATIC)
if (BUILD_SHARED_LIBS)
set (LIB_TYPE SHARED)
endif ()
set (CMAKE_POSITION_INDEPENDENT_CODE ON)
if (MSVC)
set (CMAKE_MFC_FLAG 0)
endif ()
set (CMAKE_C_STANDARD 99)
set (CMAKE_C_STANDARD_REQUIRED TRUE)
set (CMAKE_CXX_STANDARD 98)
set (CMAKE_CXX_STANDARD_REQUIRED TRUE)
set (CMAKE_CXX_EXTENSIONS OFF)
#-----------------------------------------------------------------------------
# Compiler specific flags : Shouldn't there be compiler tests for these
#-----------------------------------------------------------------------------
if (CMAKE_COMPILER_IS_GNUCC)
set (CMAKE_C_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_C_FLAGS}")
endif ()
if (CMAKE_COMPILER_IS_GNUCXX)
set (CMAKE_CXX_FLAGS "${CMAKE_ANSI_CFLAGS} ${CMAKE_CXX_FLAGS}")
endif ()
#-----------------------------------------------------------------------------
# This is in here to help some of the GCC based IDES like Eclipse
# and code blocks parse the compiler errors and warnings better.
#-----------------------------------------------------------------------------
if (CMAKE_COMPILER_IS_GNUCC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fmessage-length=0")
endif ()
if (CMAKE_COMPILER_IS_GNUCXX)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmessage-length=0")
endif ()
#-----------------------------------------------------------------------------
# Option to allow the user to disable compiler warnings
#-----------------------------------------------------------------------------
option (HDF_DISABLE_COMPILER_WARNINGS "Disable compiler warnings" OFF)
if (HDF_DISABLE_COMPILER_WARNINGS)
# MSVC uses /w to suppress warnings. It also complains if another
# warning level is given, so remove it.
if (MSVC)
set (HDF_WARNINGS_BLOCKED 1)
string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /w")
string (REGEX REPLACE "(^| )([/-])W[0-9]( |$)" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w")
endif ()
if (WIN32)
add_definitions (-D_CRT_SECURE_NO_WARNINGS)
endif ()
# Borland uses -w- to suppress warnings.
if (BORLAND)
set (HDF_WARNINGS_BLOCKED 1)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
endif ()
# Most compilers use -w to suppress warnings.
if (NOT HDF_WARNINGS_BLOCKED)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
endif ()
endif ()
#-----------------------------------------------------------------------------
# Set includes needed for build
#-----------------------------------------------------------------------------
set (${EXAMPLE_PACKAGE_NAME}_INCLUDES_BUILD_TIME
${${EXAMPLE_PACKAGE_NAME}_SRC_DIR} ${${EXAMPLE_PACKAGE_NAME}_BINARY_DIR}
)
#-----------------------------------------------------------------------------
# Option to build JAVA examples
#-----------------------------------------------------------------------------
option (HDF_BUILD_JAVA "Build JAVA support" OFF)
if (HDF_BUILD_JAVA)
find_package (Java)
INCLUDE_DIRECTORIES (
${JAVA_INCLUDE_PATH}
${JAVA_INCLUDE_PATH2}
)
include (${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR}/UseJava.cmake)
endif ()
endmacro ()
macro (HDF5_SUPPORT)
set (CMAKE_MODULE_PATH ${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR} ${CMAKE_MODULE_PATH})
option (USE_SHARED_LIBS "Use Shared Libraries" ON)
if (NOT H5EX_HDF5_HEADER)
if (USE_SHARED_LIBS)
set (FIND_HDF_COMPONENTS C shared)
else ()
set (FIND_HDF_COMPONENTS C static)
set (HDF_BUILD_JAVA OFF CACHE BOOL "Build Java support" FORCE)
message (STATUS "Using static HDF5 - disable build of Java examples")
endif ()
if (HDF_BUILD_FORTRAN)
set (FIND_HDF_COMPONENTS ${FIND_HDF_COMPONENTS} Fortran)
endif ()
if (HDF_BUILD_JAVA)
set (FIND_HDF_COMPONENTS ${FIND_HDF_COMPONENTS} Java)
set (HDF5_Java_FOUND 1) #default setting for 1.10.1 and earlier
endif ()
message (STATUS "HDF5 find comps: ${FIND_HDF_COMPONENTS}")
set (SEARCH_PACKAGE_NAME ${HDF5_PACKAGE_NAME})
find_package (HDF5 NAMES ${SEARCH_PACKAGE_NAME} COMPONENTS ${FIND_HDF_COMPONENTS})
message (STATUS "HDF5 C libs:${HDF5_FOUND} static:${HDF5_static_C_FOUND} and shared:${HDF5_shared_C_FOUND}")
message (STATUS "HDF5 Fortran libs: static:${HDF5_static_Fortran_FOUND} and shared:${HDF5_shared_Fortran_FOUND}")
message (STATUS "HDF5 Java libs: ${HDF5_Java_FOUND}")
if (HDF5_FOUND)
if (USE_SHARED_LIBS)
if (NOT TARGET ${HDF5_NAMESPACE}h5dump-shared)
add_executable (${HDF5_NAMESPACE}h5dump-shared IMPORTED)
endif ()
set (H5EX_HDF5_DUMP_EXECUTABLE $<TARGET_FILE:${HDF5_NAMESPACE}h5dump-shared>)
else ()
if (NOT TARGET ${HDF5_NAMESPACE}h5dump)
add_executable (${HDF5_NAMESPACE}h5dump IMPORTED)
endif()
set (H5EX_HDF5_DUMP_EXECUTABLE $<TARGET_FILE:${HDF5_NAMESPACE}h5dump>)
endif()
if (NOT HDF5_static_C_FOUND AND NOT HDF5_shared_C_FOUND)
#find library from non-dual-binary package
set (FIND_HDF_COMPONENTS C)
if (HDF_BUILD_FORTRAN)
set (FIND_HDF_COMPONENTS ${FIND_HDF_COMPONENTS} Fortran)
endif ()
if (HDF_BUILD_JAVA)
set (FIND_HDF_COMPONENTS ${FIND_HDF_COMPONENTS} Java)
endif ()
message (STATUS "HDF5 find comps: ${FIND_HDF_COMPONENTS}")
find_package (HDF5 NAMES ${SEARCH_PACKAGE_NAME} COMPONENTS ${FIND_HDF_COMPONENTS})
message (STATUS "HDF5 libs:${HDF5_FOUND} C:${HDF5_C_FOUND} Fortran:${HDF5_Fortran_FOUND} Java:${HDF5_Java_FOUND}")
set (H5EX_HDF5_LINK_LIBS ${H5EX_HDF5_LINK_LIBS} ${HDF5_LIBRARIES})
if (HDF5_BUILD_SHARED_LIBS)
add_definitions (-DH5_BUILT_AS_DYNAMIC_LIB)
else ()
add_definitions (-DH5_BUILT_AS_STATIC_LIB)
endif ()
if (USE_SHARED_LIBS AND WIN32)
set_property (TARGET ${HDF5_NAMESPACE}h5dump PROPERTY IMPORTED_LOCATION "${HDF5_TOOLS_DIR}/h5dumpdll")
else ()
set_property (TARGET ${HDF5_NAMESPACE}h5dump PROPERTY IMPORTED_LOCATION "${HDF5_TOOLS_DIR}/h5dump")
endif ()
if (HDF_BUILD_JAVA)
set (CMAKE_JAVA_INCLUDE_PATH "${CMAKE_JAVA_INCLUDE_PATH};${HDF5_JAVA_INCLUDE_DIRS}")
message (STATUS "HDF5 jars:${HDF5_JAVA_INCLUDE_DIRS}")
endif ()
set (H5EX_HDF5_DUMP_EXECUTABLE $<TARGET_FILE:${HDF5_NAMESPACE}h5dump>)
else ()
if (USE_SHARED_LIBS AND HDF5_shared_C_FOUND)
set (H5EX_HDF5_LINK_LIBS ${H5EX_HDF5_LINK_LIBS} ${HDF5_C_SHARED_LIBRARY})
set (HDF5_LIBRARY_PATH ${PACKAGE_PREFIX_DIR}/lib)
set_property (TARGET ${HDF5_NAMESPACE}h5dump-shared PROPERTY IMPORTED_LOCATION "${HDF5_TOOLS_DIR}/h5dump-shared")
else ()
set (H5EX_HDF5_LINK_LIBS ${H5EX_HDF5_LINK_LIBS} ${HDF5_C_STATIC_LIBRARY})
set_property (TARGET ${HDF5_NAMESPACE}h5dump PROPERTY IMPORTED_LOCATION "${HDF5_TOOLS_DIR}/h5dump")
endif ()
if (HDF_BUILD_FORTRAN AND ${HDF5_BUILD_FORTRAN})
if (BUILD_SHARED_LIBS AND HDF5_shared_Fortran_FOUND)
set (H5EX_HDF5_LINK_LIBS ${H5EX_HDF5_LINK_LIBS} ${HDF5_FORTRAN_SHARED_LIBRARY})
elseif (HDF5_static_Fortran_FOUND)
set (H5EX_HDF5_LINK_LIBS ${H5EX_HDF5_LINK_LIBS} ${HDF5_FORTRAN_STATIC_LIBRARY})
else ()
set (HDF_BUILD_FORTRAN OFF CACHE BOOL "Build FORTRAN support" FORCE)
message (STATUS "HDF5 Fortran libs not found - disable build of Fortran examples")
endif ()
else ()
set (HDF_BUILD_FORTRAN OFF CACHE BOOL "Build FORTRAN support" FORCE)
message (STATUS "HDF5 Fortran libs not found - disable build of Fortran examples")
endif ()
if (HDF_BUILD_JAVA)
if (${HDF5_BUILD_JAVA} AND HDF5_Java_FOUND)
set (CMAKE_JAVA_INCLUDE_PATH "${CMAKE_JAVA_INCLUDE_PATH};${HDF5_JAVA_INCLUDE_DIRS}")
message (STATUS "HDF5 jars:${HDF5_JAVA_INCLUDE_DIRS}}")
else ()
set (HDF_BUILD_JAVA OFF CACHE BOOL "Build Java support" FORCE)
message (STATUS "HDF5 Java libs not found - disable build of Java examples")
endif ()
else ()
set (HDF_BUILD_JAVA OFF CACHE BOOL "Build Java support" FORCE)
endif ()
endif ()
else ()
find_package (HDF5) # Legacy find
#Legacy find_package does not set HDF5_TOOLS_DIR, so we set it here
set (HDF5_TOOLS_DIR ${HDF5_LIBRARY_DIRS}/../bin)
#Legacy find_package does not set HDF5_BUILD_SHARED_LIBS, so we set it here
if (USE_SHARED_LIBS AND EXISTS "${HDF5_LIBRARY_DIRS}/libhdf5.so")
set (HDF5_BUILD_SHARED_LIBS 1)
else ()
set (HDF5_BUILD_SHARED_LIBS 0)
endif ()
set (H5EX_HDF5_LINK_LIBS ${H5EX_HDF5_LINK_LIBS} ${HDF5_LIBRARIES})
add_executable (${HDF5_NAMESPACE}h5dump IMPORTED)
set_property (TARGET ${HDF5_NAMESPACE}h5dump PROPERTY IMPORTED_LOCATION "${HDF5_TOOLS_DIR}/h5dump")
set (H5EX_HDF5_DUMP_EXECUTABLE $<TARGET_FILE:${HDF5_NAMESPACE}h5dump>)
endif ()
set (HDF5_PACKAGE_NAME ${SEARCH_PACKAGE_NAME})
if (HDF5_FOUND)
set (H5EX_HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR})
set (H5EX_HDF5_HAVE_H5PUBCONF_H 1)
set (H5EX_HDF5_HAVE_HDF5 1)
set (H5EX_HDF5_HEADER "h5pubconf.h")
message (STATUS "HDF5-${HDF5_VERSION_STRING} found: INC=${HDF5_INCLUDE_DIR} TOOLS=${HDF5_TOOLS_DIR}")
else ()
message (FATAL_ERROR " HDF5 is Required for HDF5 Examples")
endif ()
else ()
# This project is being called from within another and HDF5 is already configured
set (H5EX_HDF5_HAVE_H5PUBCONF_H 1)
set (H5EX_HDF5_HAVE_HDF5 1)
message (STATUS "HDF5-${HDF5_VERSION_STRING} used")
endif ()
if (HDF_BUILD_FORTRAN)
list (APPEND H5EX_HDF5_INCLUDE_DIRS ${HDF5_INCLUDE_DIR_FORTRAN})
endif ()
message (STATUS "HDF5 link libs: ${H5EX_HDF5_LINK_LIBS} Includes: ${H5EX_HDF5_INCLUDE_DIRS}")
if (USE_SHARED_LIBS)
set (H5_LIB_TYPE SHARED)
else ()
set (H5_LIB_TYPE STATIC)
endif ()
#-----------------------------------------------------------------------------
# Option to build filter examples
#-----------------------------------------------------------------------------
option (HDF_BUILD_FILTERS "Test filter support" OFF)
endmacro ()
#-------------------------------------------------------------------------------
# Purpose:
# Breaking down three numbered versions (x.y.z) into their components, and
# returning a major and minor version (xy).
#
# Parameters:
# version [in] The version string.
# xyapi [out] A "majorminor" API version.
#
macro (APIVersion version xyapi)
string (REGEX REPLACE "(\-[0-9]+)" "" xyz ${version})
message (VERBOSE "version=${version}")
string (REGEX REPLACE "([0-9]+).[0-9]+.[0-9]+" "\\1" major ${xyz})
string (REGEX REPLACE "[0-9]+.([0-9]+).[0-9]+" "\\1" minor ${xyz})
string (REGEX REPLACE "[0-9]+.[0-9]+.([0-9]+)" "\\1" patch ${xyz})
message (VERBOSE "major=${major} minor=${minor}")
# Round up to the next major release if minor is odd-numbered
math (EXPR rem "${minor}%2")
if (NOT ${rem} STREQUAL "0")
math (EXPR minor "${minor} + 1")
endif ()
set (${xyapi} "${major}${minor}")
#-----------------------------------------------------------------------------
# Option to use 1.6.x API
#-----------------------------------------------------------------------------
option (${EXAMPLE_VARNAME}_USE_16_API "Use the HDF5 1.6.x API" OFF)
if (${EXAMPLE_VARNAME}_USE_16_API AND ${xyapi} GREATER 16)
set (${xyapi} "16")
endif ()
#-----------------------------------------------------------------------------
# Option to use 1.8.x API
#-----------------------------------------------------------------------------
option (${EXAMPLE_VARNAME}_USE_18_API "Use the HDF5 1.8.x API" OFF)
if (${EXAMPLE_VARNAME}_USE_18_API AND ${xyapi} GREATER 18)
set (${xyapi} "18")
endif ()
#-----------------------------------------------------------------------------
# Option to use 1.10.x API
#-----------------------------------------------------------------------------
option (${EXAMPLE_VARNAME}_USE_110_API "Use the HDF5 1.10.x API" OFF)
if (${EXAMPLE_VARNAME}_USE_110_API AND ${xyapi} GREATER 110)
set (${xyapi} "110")
endif ()
#-----------------------------------------------------------------------------
# Option to use 1.12.x API
#-----------------------------------------------------------------------------
option (${EXAMPLE_VARNAME}_USE_112_API "Use the HDF5 1.12.x API" OFF)
if (${EXAMPLE_VARNAME}_USE_112_API AND ${xyapi} GREATER 112)
set (${xyapi} "112")
endif ()
#-----------------------------------------------------------------------------
# Option to use 1.14.x API
#-----------------------------------------------------------------------------
option (${EXAMPLE_VARNAME}_USE_114_API "Use the HDF5 1.14.x API" OFF)
if (${EXAMPLE_VARNAME}_USE_114_API AND ${xyapi} GREATER 114)
set (${xyapi} "114")
endif ()
#-----------------------------------------------------------------------------
# Option to use 1.16.x API
#-----------------------------------------------------------------------------
option (${EXAMPLE_VARNAME}_USE_116_API "Use the HDF5 1.16.x API" OFF)
if (${EXAMPLE_VARNAME}_USE_116_API AND ${xyapi} GREATER 116)
set (${xyapi} "116")
endif ()
endmacro ()
|