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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
#
# Copyright by The HDF Group.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the COPYING file, which can be found at the root of the source code
# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.
# If you do not have access to either file, you may request a copy from
# help@hdfgroup.org.
#
#-------------------------------------------------------------------------------
macro (SET_HDF_BUILD_TYPE)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
set(HDF_CFG_NAME ${CTEST_CONFIGURATION_TYPE})
set(HDF_BUILD_TYPE ${CMAKE_CFG_INTDIR})
set(HDF_CFG_BUILD_TYPE \${CMAKE_INSTALL_CONFIG_NAME})
else()
set(HDF_CFG_BUILD_TYPE ".")
if(CMAKE_BUILD_TYPE)
set(HDF_CFG_NAME ${CMAKE_BUILD_TYPE})
set(HDF_BUILD_TYPE ${CMAKE_BUILD_TYPE})
else()
set(HDF_CFG_NAME "Release")
set(HDF_BUILD_TYPE "Release")
endif()
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
endmacro ()
#-------------------------------------------------------------------------------
macro (SET_GLOBAL_VARIABLE name value)
set (${name} ${value} CACHE INTERNAL "Used to pass variables between directories" FORCE)
endmacro ()
#-------------------------------------------------------------------------------
macro (IDE_GENERATED_PROPERTIES SOURCE_PATH HEADERS SOURCES)
#set(source_group_path "Source/AIM/${NAME}")
string (REPLACE "/" "\\\\" source_group_path ${SOURCE_PATH})
source_group (${source_group_path} FILES ${HEADERS} ${SOURCES})
#-- The following is needed if we ever start to use OS X Frameworks but only
#-- works on CMake 2.6 and greater
#set_property (SOURCE ${HEADERS}
# PROPERTY MACOSX_PACKAGE_LOCATION Headers/${NAME}
#)
endmacro ()
#-------------------------------------------------------------------------------
macro (IDE_SOURCE_PROPERTIES SOURCE_PATH HEADERS SOURCES)
# install (FILES ${HEADERS}
# DESTINATION include/R3D/${NAME}
# COMPONENT Headers
# )
string (REPLACE "/" "\\\\" source_group_path ${SOURCE_PATH} )
source_group (${source_group_path} FILES ${HEADERS} ${SOURCES})
#-- The following is needed if we ever start to use OS X Frameworks but only
#-- works on CMake 2.6 and greater
#set_property (SOURCE ${HEADERS}
# PROPERTY MACOSX_PACKAGE_LOCATION Headers/${NAME}
#)
endmacro ()
#-------------------------------------------------------------------------------
macro (INSTALL_TARGET_PDB libtarget targetdestination targetcomponent)
if (WIN32 AND MSVC)
get_target_property (target_type ${libtarget} TYPE)
if (${libtype} MATCHES "SHARED")
set (targetfilename $<TARGET_PDB_FILE:${libtarget}>)
else ()
get_property (target_name TARGET ${libtarget} PROPERTY OUTPUT_NAME_RELWITHDEBINFO)
set (targetfilename $<TARGET_FILE_DIR:${libtarget}>/${target_name}.pdb)
endif ()
install (
FILES
${targetfilename}
DESTINATION
${targetdestination}
CONFIGURATIONS RelWithDebInfo
COMPONENT ${targetcomponent}
)
endif ()
endmacro ()
#-------------------------------------------------------------------------------
macro (INSTALL_PROGRAM_PDB progtarget targetdestination targetcomponent)
if (WIN32 AND MSVC)
install (
FILES
$<TARGET_PDB_FILE:${progtarget}>
DESTINATION
${targetdestination}
CONFIGURATIONS RelWithDebInfo
COMPONENT ${targetcomponent}
)
endif ()
endmacro ()
#-------------------------------------------------------------------------------
macro (HDF_SET_LIB_OPTIONS libtarget libname libtype)
if (WIN32)
set (LIB_DEBUG_SUFFIX "_D")
else ()
set (LIB_DEBUG_SUFFIX "_debug")
endif ()
if (${libtype} MATCHES "SHARED")
set (LIB_RELEASE_NAME "${libname}")
set (LIB_DEBUG_NAME "${libname}${LIB_DEBUG_SUFFIX}")
else ()
if (WIN32)
set (LIB_RELEASE_NAME "lib${libname}")
set (LIB_DEBUG_NAME "lib${libname}${LIB_DEBUG_SUFFIX}")
else ()
set (LIB_RELEASE_NAME "${libname}")
set (LIB_DEBUG_NAME "${libname}${LIB_DEBUG_SUFFIX}")
endif ()
endif ()
set_target_properties (${libtarget}
PROPERTIES
OUTPUT_NAME
${LIB_RELEASE_NAME}
OUTPUT_NAME_DEBUG
${LIB_DEBUG_NAME}
OUTPUT_NAME_RELEASE
${LIB_RELEASE_NAME}
OUTPUT_NAME_MINSIZEREL
${LIB_RELEASE_NAME}
OUTPUT_NAME_RELWITHDEBINFO
${LIB_RELEASE_NAME}
)
if (${libtype} MATCHES "STATIC")
if (WIN32)
set_target_properties (${libtarget}
PROPERTIES
COMPILE_PDB_NAME_DEBUG ${LIB_DEBUG_NAME}
COMPILE_PDB_NAME_RELEASE ${LIB_RELEASE_NAME}
COMPILE_PDB_NAME_MINSIZEREL ${LIB_RELEASE_NAME}
COMPILE_PDB_NAME_RELWITHDEBINFO ${LIB_RELEASE_NAME}
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"
)
endif ()
endif ()
#----- Use MSVC Naming conventions for Shared Libraries
if (MINGW AND ${libtype} MATCHES "SHARED")
set_target_properties (${libtarget}
PROPERTIES
IMPORT_SUFFIX ".lib"
IMPORT_PREFIX ""
PREFIX ""
)
endif ()
endmacro ()
#-------------------------------------------------------------------------------
macro (HDF_IMPORT_SET_LIB_OPTIONS libtarget libname libtype libversion)
HDF_SET_LIB_OPTIONS (${libtarget} ${libname} ${libtype})
if (${importtype} MATCHES "IMPORT")
set (importprefix "${CMAKE_STATIC_LIBRARY_PREFIX}")
endif ()
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
set (IMPORT_LIB_NAME ${LIB_DEBUG_NAME})
else ()
set (IMPORT_LIB_NAME ${LIB_RELEASE_NAME})
endif ()
if (${libtype} MATCHES "SHARED")
if (WIN32)
if (MINGW)
set_target_properties (${libtarget} PROPERTIES
IMPORTED_IMPLIB "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${IMPORT_LIB_NAME}.lib"
IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${IMPORT_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
else ()
set_target_properties (${libtarget} PROPERTIES
IMPORTED_IMPLIB "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${HDF_BUILD_TYPE}/${CMAKE_IMPORT_LIBRARY_PREFIX}${IMPORT_LIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX}"
IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${HDF_BUILD_TYPE}/${CMAKE_IMPORT_LIBRARY_PREFIX}${IMPORT_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
endif ()
else ()
if (CYGWIN)
set_target_properties (${libtarget} PROPERTIES
IMPORTED_IMPLIB "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_IMPORT_LIBRARY_PREFIX}${IMPORT_LIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX}"
IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_IMPORT_LIBRARY_PREFIX}${IMPORT_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}"
)
else ()
set_target_properties (${libtarget} PROPERTIES
IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_SHARED_LIBRARY_PREFIX}${IMPORT_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}"
IMPORTED_SONAME "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_SHARED_LIBRARY_PREFIX}${IMPORT_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}.${libversion}"
SOVERSION "${libversion}"
)
endif ()
endif ()
else ()
if (WIN32 AND NOT MINGW)
set_target_properties (${libtarget} PROPERTIES
IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${HDF_BUILD_TYPE}/${IMPORT_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
)
else ()
set_target_properties (${libtarget} PROPERTIES
IMPORTED_LOCATION "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_STATIC_LIBRARY_PREFIX}${IMPORT_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
)
endif ()
endif ()
endmacro ()
#-------------------------------------------------------------------------------
macro (TARGET_C_PROPERTIES wintarget libtype)
target_compile_options(${wintarget} PRIVATE
$<$<C_COMPILER_ID:MSVC>:${WIN_COMPILE_FLAGS}>
$<$<CXX_COMPILER_ID:MSVC>:${WIN_COMPILE_FLAGS}>
)
target_link_libraries(${wintarget} INTERFACE
$<$<C_COMPILER_ID:MSVC>:${WIN_LINK_FLAGS}>
$<$<CXX_COMPILER_ID:MSVC>:${WIN_LINK_FLAGS}>
)
endmacro ()
#-----------------------------------------------------------------------------
# Configure the README.txt file for the binary package
#-----------------------------------------------------------------------------
macro (HDF_README_PROPERTIES target_fortran)
set (BINARY_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
set (BINARY_PLATFORM "${CMAKE_SYSTEM_NAME}")
if (WIN32)
set (BINARY_EXAMPLE_ENDING "zip")
set (BINARY_INSTALL_ENDING "msi")
if (CMAKE_CL_64)
set (BINARY_SYSTEM_NAME "win64")
else ()
set (BINARY_SYSTEM_NAME "win32")
endif ()
if (${CMAKE_SYSTEM_VERSION} MATCHES "6.1")
set (BINARY_PLATFORM "${BINARY_PLATFORM} 7")
elseif (${CMAKE_SYSTEM_VERSION} MATCHES "6.2")
set (BINARY_PLATFORM "${BINARY_PLATFORM} 8")
elseif (${CMAKE_SYSTEM_VERSION} MATCHES "6.3")
set (BINARY_PLATFORM "${BINARY_PLATFORM} 10")
endif ()
if (CMAKE_C_COMPILER_ID MATCHES "Intel")
set (BINARY_PLATFORM "${BINARY_PLATFORM} Intel")
if (${CMAKE_C_COMPILER_VERSION} MATCHES "^17.*")
set (BINARY_PLATFORM "${BINARY_PLATFORM}, using Intel 17")
else ()
set (BINARY_PLATFORM "${BINARY_PLATFORM}, using Intel ${CMAKE_C_COMPILER_VERSION}")
endif ()
elseif (CMAKE_C_COMPILER_ID MATCHES "MSVC")
set (BINARY_PLATFORM "${BINARY_PLATFORM} ${MSVC_C_ARCHITECTURE_ID}")
if (${CMAKE_C_COMPILER_VERSION} MATCHES "^16.*")
set (BINARY_PLATFORM "${BINARY_PLATFORM}, using VISUAL STUDIO 2010")
elseif (${CMAKE_C_COMPILER_VERSION} MATCHES "^15.*")
set (BINARY_PLATFORM "${BINARY_PLATFORM}, using VISUAL STUDIO 2008")
elseif (${CMAKE_C_COMPILER_VERSION} MATCHES "^17.*")
set (BINARY_PLATFORM "${BINARY_PLATFORM}, using VISUAL STUDIO 2012")
elseif (${CMAKE_C_COMPILER_VERSION} MATCHES "^18.*")
set (BINARY_PLATFORM "${BINARY_PLATFORM}, using VISUAL STUDIO 2013")
elseif (${CMAKE_C_COMPILER_VERSION} MATCHES "^19.*")
if (${CMAKE_C_COMPILER_VERSION} MATCHES "^19.0.*")
set (BINARY_PLATFORM "${BINARY_PLATFORM}, using VISUAL STUDIO 2015")
else ()
set (BINARY_PLATFORM "${BINARY_PLATFORM}, using VISUAL STUDIO 2017")
endif ()
else ()
set (BINARY_PLATFORM "${BINARY_PLATFORM}, using VISUAL STUDIO ${CMAKE_C_COMPILER_VERSION}")
endif ()
endif ()
elseif (APPLE)
set (BINARY_EXAMPLE_ENDING "tar.gz")
set (BINARY_INSTALL_ENDING "sh") # if packaging changes - use dmg
set (BINARY_PLATFORM "${BINARY_PLATFORM} ${CMAKE_SYSTEM_VERSION} ${CMAKE_SYSTEM_PROCESSOR}")
set (BINARY_PLATFORM "${BINARY_PLATFORM}, using ${CMAKE_C_COMPILER_ID} C ${CMAKE_C_COMPILER_VERSION}")
else ()
set (BINARY_EXAMPLE_ENDING "tar.gz")
set (BINARY_INSTALL_ENDING "sh")
set (BINARY_PLATFORM "${BINARY_PLATFORM} ${CMAKE_SYSTEM_VERSION} ${CMAKE_SYSTEM_PROCESSOR}")
set (BINARY_PLATFORM "${BINARY_PLATFORM}, using ${CMAKE_C_COMPILER_ID} C ${CMAKE_C_COMPILER_VERSION}")
endif ()
if (target_fortran)
set (BINARY_PLATFORM "${BINARY_PLATFORM} / ${CMAKE_Fortran_COMPILER_ID} Fortran")
endif ()
if (BUILD_SHARED_LIBS)
set (LIB_TYPE "Static and Shared")
else ()
set (LIB_TYPE "Static")
endif ()
configure_file (
${HDF_RESOURCES_DIR}/README.txt.cmake.in
${CMAKE_BINARY_DIR}/README.txt @ONLY
)
endmacro ()
macro (HDFTEST_COPY_FILE src dest target)
add_custom_command(
OUTPUT "${dest}"
COMMAND "${CMAKE_COMMAND}"
ARGS -E copy_if_different "${src}" "${dest}"
DEPENDS "${src}"
)
list (APPEND ${target}_list "${dest}")
endmacro ()
macro (HDF_DIR_PATHS package_prefix)
if (APPLE)
option (${package_prefix}_BUILD_FRAMEWORKS "TRUE to build as frameworks libraries, FALSE to build according to BUILD_SHARED_LIBS" FALSE)
endif ()
if (NOT ${package_prefix}_INSTALL_BIN_DIR)
set (${package_prefix}_INSTALL_BIN_DIR bin)
endif ()
if (NOT ${package_prefix}_INSTALL_LIB_DIR)
if (APPLE)
if (${package_prefix}_BUILD_FRAMEWORKS)
set (${package_prefix}_INSTALL_JAR_DIR ../Java)
else ()
set (${package_prefix}_INSTALL_JAR_DIR lib)
endif ()
set (${package_prefix}_INSTALL_FMWK_DIR ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
else ()
set (${package_prefix}_INSTALL_JAR_DIR lib)
endif ()
set (${package_prefix}_INSTALL_LIB_DIR lib)
endif ()
if (NOT ${package_prefix}_INSTALL_INCLUDE_DIR)
set (${package_prefix}_INSTALL_INCLUDE_DIR include)
endif ()
if (NOT ${package_prefix}_INSTALL_DATA_DIR)
if (NOT WIN32)
if (APPLE)
if (${package_prefix}_BUILD_FRAMEWORKS)
set (${package_prefix}_INSTALL_EXTRA_DIR ../SharedSupport)
else ()
set (${package_prefix}_INSTALL_EXTRA_DIR share)
endif ()
set (${package_prefix}_INSTALL_FWRK_DIR ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
endif ()
set (${package_prefix}_INSTALL_DATA_DIR share)
set (${package_prefix}_INSTALL_CMAKE_DIR share/cmake)
else ()
set (${package_prefix}_INSTALL_DATA_DIR ".")
set (${package_prefix}_INSTALL_CMAKE_DIR cmake)
endif ()
endif ()
set (CMAKE_SKIP_BUILD_RPATH FALSE)
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
set (CMAKE_BUILD_WITH_INSTALL_RPATH ON)
if (APPLE)
set (CMAKE_INSTALL_NAME_DIR "@rpath")
set (CMAKE_INSTALL_RPATH "@executable_path/../${${package_prefix}_INSTALL_LIB_DIR}")
else ()
set (CMAKE_INSTALL_RPATH "\$ORIGIN/../${${package_prefix}_INSTALL_LIB_DIR}")
endif ()
if (DEFINED ADDITIONAL_CMAKE_PREFIX_PATH AND EXISTS "${ADDITIONAL_CMAKE_PREFIX_PATH}")
set (CMAKE_PREFIX_PATH ${ADDITIONAL_CMAKE_PREFIX_PATH} ${CMAKE_PREFIX_PATH})
endif ()
SET_HDF_BUILD_TYPE()
#-----------------------------------------------------------------------------
# Setup output Directories
#-----------------------------------------------------------------------------
if (NOT ${package_prefix}_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 and utilities like H5detect will fail
if (NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
endif ()
endif ()
endmacro ()
|