forked from BIC-MNI/libminc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
386 lines (320 loc) · 12.4 KB
/
CMakeLists.txt
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
# CMakeFiles.txt for the libminc library
#
# Andrew Janke - [email protected]
# Vladimir S. FONOV - [email protected]
PROJECT(libminc)
SET(LIBMINC_PACKAGE_VERSION_MAJOR 2)
SET(LIBMINC_PACKAGE_VERSION_MINOR 2)
SET(LIBMINC_PACKAGE_VERSION_PATCH 00)
SET(PACKAGE "libminc")
SET(PACKAGE_BUGREPORT "[email protected]")
SET(PACKAGE_NAME "libminc")
SET(PACKAGE_VERSION "${LIBMINC_PACKAGE_VERSION_MAJOR}.${LIBMINC_PACKAGE_VERSION_MINOR}.${LIBMINC_PACKAGE_VERSION_PATCH}")
SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
ENABLE_TESTING()
INCLUDE(CTest)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
IF(MINC_TOOLKIT_BUILD)
SET(LIBMINC_EXTERNALLY_CONFIGURED ON)
ENDIF(MINC_TOOLKIT_BUILD)
IF(NOT LIBMINC_EXTERNALLY_CONFIGURED)
SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")
SET(CPACK_GENERATOR TGZ)
SET(CPACK_PACKAGE_VERSION_MAJOR ${LIBMINC_PACKAGE_VERSION_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${LIBMINC_PACKAGE_VERSION_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${LIBMINC_PACKAGE_VERSION_PATCH})
OPTION(LIBMINC_BUILD_SHARED_LIBS "Build libminc with shared libraries." OFF)
INCLUDE(CPack)
OPTION(LIBMINC_BUILD_V2 "Support minc2 file format" ON)
OPTION(LIBMINC_BUILD_EZMINC_EXAMPLES "Build EZminc examples" ON)
ENDIF(NOT LIBMINC_EXTERNALLY_CONFIGURED)
IF(LIBMINC_BUILD_V2 AND NOT LIBMINC_EXTERNALLY_CONFIGURED)
IF(ITK_FOUND AND ITK_VERSION_MAJOR VERSION_EQUAL 4) # check if using ITK HDF5 library
IF(ITKHDF5_LOADED)
SET(USE_ITK_HDF5 ON)
ELSE(ITKHDF5_LOADED)
SET(USE_ITK_HDF5 OFF)
ENDIF(ITKHDF5_LOADED)
ELSE(ITK_FOUND AND ITK_VERSION_MAJOR VERSION_EQUAL 4) # check if using ITK HDF5 library
SET(USE_ITK_HDF5 OFF)
ENDIF(ITK_FOUND AND ITK_VERSION_MAJOR VERSION_EQUAL 4) # check if using ITK HDF5 library
ENDIF(LIBMINC_BUILD_V2 AND NOT LIBMINC_EXTERNALLY_CONFIGURED)
IF(LIBMINC_BUILD_SHARED_LIBS)
SET(LIBRARY_TYPE SHARED)
SET(LIBRARY_INSTALL LIBRARY)
ELSE(LIBMINC_BUILD_SHARED_LIBS)
SET(LIBRARY_TYPE STATIC)
SET(LIBRARY_INSTALL ARCHIVE)
ENDIF(LIBMINC_BUILD_SHARED_LIBS)
# external packages
IF(NOT LIBMINC_EXTERNALLY_CONFIGURED)
FIND_PACKAGE(NETCDF REQUIRED)
ENDIF(NOT LIBMINC_EXTERNALLY_CONFIGURED)
IF(LIBMINC_BUILD_V2 AND NOT LIBMINC_EXTERNALLY_CONFIGURED)
IF(USE_ITK_HDF5)
SET(HDF5_INCLUDE_DIR "${ITKHDF5_INCLUDE_DIRS}/itkhdf5") # a hack?
SET(HDF5_LIBRARY ${ITKHDF5_LIBRARIES})
SET(ZLIB_LIBRARY ${ITKZLIB_LIBRARIES})
ELSE(USE_ITK_HDF5)
FIND_PACKAGE(ZLIB REQUIRED)
FIND_PACKAGE(HDF5 REQUIRED)
ENDIF(USE_ITK_HDF5)
IF(ZLIB_FOUND)
SET(HAVE_ZLIB 1)
ELSE(ZLIB_FOUND)
FIND_PACKAGE(ZLIB)
IF(ZLIB_FOUND)
SET(HAVE_ZLIB 1)
ENDIF(ZLIB_FOUND)
ENDIF(ZLIB_FOUND)
ENDIF(LIBMINC_BUILD_V2 AND NOT LIBMINC_EXTERNALLY_CONFIGURED)
# add for building relocatable library
IF(UNIX)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
ENDIF(UNIX)
# check for prereqs
INCLUDE(CheckFunctionExists)
CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP)
CHECK_FUNCTION_EXISTS(tmpnam HAVE_TMPNAM)
CHECK_FUNCTION_EXISTS(tempnam HAVE_TEMPNAM)
CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
CHECK_FUNCTION_EXISTS(popen HAVE_POPEN)
CHECK_FUNCTION_EXISTS(fork HAVE_WORKING_FORK)
CHECK_FUNCTION_EXISTS(vfork HAVE_WORKING_VFORK)
CHECK_FUNCTION_EXISTS(fdopen HAVE_FDOPEN)
CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP)
CHECK_FUNCTION_EXISTS(getpwnam HAVE_GETPWNAM)
CHECK_FUNCTION_EXISTS(select HAVE_SELECT)
CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
CHECK_FUNCTION_EXISTS(system HAVE_SYSTEM)
INCLUDE(CheckIncludeFiles)
CHECK_INCLUDE_FILES(float.h HAVE_FLOAT_H)
CHECK_INCLUDE_FILES(sys/dir.h HAVE_SYS_DIR_H)
CHECK_INCLUDE_FILES(sys/ndir.h HAVE_SYS_NDIR_H)
CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILES(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES(sys/wait.h HAVE_SYS_WAIT_H)
CHECK_INCLUDE_FILES(values.h HAVE_VALUES_H)
CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES(dirent.h HAVE_DIRENT_H)
CHECK_INCLUDE_FILES(memory.h HAVE_MEMORY_H)
CHECK_INCLUDE_FILES(stdlib.h HAVE_STDLIB_H)
CHECK_INCLUDE_FILES(fcntl.h HAVE_FCNTL_H)
CHECK_INCLUDE_FILES(dlfcn.h HAVE_DLFCN_H)
CHECK_INCLUDE_FILES(vfork.h HAVE_VFORK_H)
CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILES(string.h HAVE_STRING_H)
CHECK_INCLUDE_FILES(strings.h HAVE_STRINGS_H)
CHECK_INCLUDE_FILES(pwd.h HAVE_PWD_H)
ADD_DEFINITIONS(-DHAVE_CONFIG_H)
# aliases
SET(VERSION "${PACKAGE_VERSION}")
IF(LIBMINC_BUILD_EZMINC)
set(LIBMINC_INCLUDE_DIRS_CONFIG
${CMAKE_CURRENT_SOURCE_DIR}/ezminc
)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/ezminc
)
ENDIF(LIBMINC_BUILD_EZMINC)
# netcdf and HDF5
IF(LIBMINC_BUILD_V2)
FIND_PACKAGE(ZLIB REQUIRED)
SET(MINC2 "1")
ELSE(BUILD_MINC2)
SET(MINC2 "0")
ENDIF(LIBMINC_BUILD_V2)
# config files for build
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY)
# others
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/epm-header.in ${CMAKE_CURRENT_BINARY_DIR}/epm-header)
# set the master INCLUDE directories
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/libsrc
${CMAKE_CURRENT_SOURCE_DIR}/volume_io/Include
)
INCLUDE_DIRECTORIES( ${NETCDF_INCLUDE_DIR} )
IF(LIBMINC_BUILD_V2)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/libsrc2 )
ENDIF(LIBMINC_BUILD_V2)
# some variables
SET(minc1_LIB_SRCS
libsrc/ParseArgv.c
libsrc/dim_conversion.c
libsrc/image_conversion.c
libsrc/minc_convenience.c
libsrc/minc_error.c
libsrc/nd_loop.c
libsrc/netcdf_convenience.c
libsrc/time_stamp.c
libsrc/value_conversion.c
libsrc/voxel_loop.c
libsrc/hdf_convenience.c
libsrc/minc_compat.c
libsrc/minc_simple.c
libsrc/read_file_names.c
)
SET(minc1_HEADERS
libsrc/minc.h
libsrc/ParseArgv.h
libsrc/voxel_loop.h
libsrc/nd_loop.h
libsrc/time_stamp.h
libsrc/minc_compat.h
volume_io/Include/volume_io.h
libsrc/minc_simple.h
)
SET(minc2_LIB_SRCS
libsrc2/convert.c
libsrc2/datatype.c
libsrc2/dimension.c
libsrc2/free.c
libsrc2/grpattr.c
libsrc2/hyper.c
libsrc2/label.c
libsrc2/m2util.c
libsrc2/record.c
libsrc2/slice.c
libsrc2/valid.c
libsrc2/volprops.c
libsrc2/volume.c
)
SET(minc2_HEADERS
libsrc2/minc2.h
)
# volume_io2
SET(volume_io_LIB_SRCS
volume_io/Geometry/colour.c
volume_io/Geometry/colour_def.c
volume_io/Geometry/gaussian.c
volume_io/Geometry/inverse.c
volume_io/Geometry/newton.c
volume_io/Geometry/points.c
volume_io/Geometry/splines.c
volume_io/Geometry/tensors.c
volume_io/Geometry/transforms.c
volume_io/MNI_formats/gen_xf_io.c
volume_io/MNI_formats/gen_xfs.c
volume_io/MNI_formats/grid_transforms.c
volume_io/MNI_formats/mni_io.c
volume_io/MNI_formats/tag_points.c
volume_io/MNI_formats/thin_plate_spline.c
volume_io/Prog_utils/alloc.c
volume_io/Prog_utils/alloc_check.c
volume_io/Prog_utils/arrays.c
volume_io/Prog_utils/files.c
volume_io/Prog_utils/print.c
volume_io/Prog_utils/progress.c
volume_io/Prog_utils/string.c
volume_io/Prog_utils/time.c
volume_io/Volumes/evaluate.c
volume_io/Volumes/get_hyperslab.c
volume_io/Volumes/input_free.c
volume_io/Volumes/input_mnc.c
volume_io/Volumes/input_volume.c
volume_io/Volumes/multidim_arrays.c
volume_io/Volumes/output_mnc.c
volume_io/Volumes/output_volume.c
volume_io/Volumes/set_hyperslab.c
volume_io/Volumes/volume_cache.c
volume_io/Volumes/volumes.c
)
SET(volume_io_HEADERS
volume_io/Include/volume_io/alloc.h
volume_io/Include/volume_io/arrays.h
volume_io/Include/volume_io/basic.h
volume_io/Include/volume_io/def_math.h
volume_io/Include/volume_io/files.h
volume_io/Include/volume_io/geom_structs.h
volume_io/Include/volume_io/geometry.h
volume_io/Include/internal_volume_io.h
volume_io/Include/volume_io/multidim.h
volume_io/Include/volume_io/progress.h
volume_io/Include/volume_io/string_funcs.h
volume_io/Include/volume_io/system_dependent.h
volume_io/Include/volume_io/transforms.h
volume_io/Include/volume_io/vol_io_prototypes.h
volume_io/Include/volume_io/volume.h
volume_io/Include/volume_io/volume_cache.h
)
SET(LIBMINC_LIBRARY minc)
SET(VOLUME_IO_LIBRARY volume_io)
SET(LIBMINC_LIBRARIES ${LIBMINC_LIBRARY} ${NETCDF_LIBRARY})
#SET(LIBMINC_DEPENDENCIES "")
IF(LIBMINC_BUILD_V2)
INCLUDE_DIRECTORIES( ${HDF5_INCLUDE_DIR} )
SET(minc_LIB_SRCS ${minc1_LIB_SRCS} ${minc2_LIB_SRCS})
SET(minc_HEADERS ${minc1_HEADERS} ${minc2_HEADERS})
SET(LIBMINC_LIBRARY minc2)
SET(LIBMINC_LIBRARIES ${LIBMINC_LIBRARY} ${HDF5_LIBRARY} ${NETCDF_LIBRARY} ${ZLIB_LIBRARY} m )
SET(VOLUME_IO_LIBRARY volume_io2)
ELSE(LIBMINC_BUILD_V2)
SET(minc_LIB_SRCS ${minc1_LIB_SRCS} )
SET(minc_HEADERS ${minc1_HEADERS} ${minc2_HEADERS})
ENDIF(LIBMINC_BUILD_V2)
ADD_LIBRARY(${LIBMINC_LIBRARY} ${LIBRARY_TYPE} ${minc_LIB_SRCS} )
TARGET_LINK_LIBRARIES(${LIBMINC_LIBRARY} ${NETCDF_LIBRARY} ${HDF5_LIBRARY} ${ZLIB_LIBRARY} m )
ADD_LIBRARY(${VOLUME_IO_LIBRARY} ${LIBRARY_TYPE} ${volume_io_LIB_SRCS})
TARGET_LINK_LIBRARIES(${VOLUME_IO_LIBRARY} ${LIBMINC_LIBRARY})
SET_TARGET_PROPERTIES(${LIBMINC_LIBRARY} PROPERTIES VERSION ${PACKAGE_VERSION} SOVERSION ${LIBMINC_PACKAGE_VERSION_MAJOR})
SET_TARGET_PROPERTIES(${VOLUME_IO_LIBRARY} PROPERTIES VERSION ${PACKAGE_VERSION} SOVERSION ${LIBMINC_PACKAGE_VERSION_MAJOR})
ADD_DEPENDENCIES(${VOLUME_IO_LIBRARY} ${LIBMINC_LIBRARY})
INSTALL(TARGETS ${LIBMINC_LIBRARY} ${LIBRARY_INSTALL} DESTINATION lib${LIB_SUFFIX})
INSTALL(TARGETS ${VOLUME_IO_LIBRARY} ${LIBRARY_INSTALL} DESTINATION lib${LIB_SUFFIX})
INSTALL(FILES ${minc_HEADERS} DESTINATION include )
INSTALL(FILES ${volume_io_HEADERS} DESTINATION include/volume_io)
ADD_SUBDIRECTORY( ezminc )
# config for the build directory
set(LIBMINC_USE_FILE_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/UseLIBMINC.cmake)
set(LIBMINC_INCLUDE_DIRS_CONFIG
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/libsrc
${CMAKE_CURRENT_SOURCE_DIR}/volume_io/Include
${CMAKE_CURRENT_SOURCE_DIR}/ezminc
)
IF(LIBMINC_BUILD_V2)
set(LIBMINC_INCLUDE_DIRS_CONFIG
${LIBMINC_INCLUDE_DIRS_CONFIG}
${CMAKE_CURRENT_SOURCE_DIR}/libsrc2
)
ENDIF(LIBMINC_BUILD_V2)
SET(EZMINC_LIBRARIES minc_io ${LIBMINC_LIBRARIES})
set(LIBMINC_LIBRARY_DIRS_CONFIG ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/ezminc)
set(LIBMINC_LIBRARIES_CONFIG ${LIBMINC_LIBRARIES})
configure_file(LIBMINCConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/LIBMINCConfig.cmake @ONLY )
configure_file(UseLIBMINC.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/UseLIBMINC.cmake @ONLY)
# config for install dir
set(LIBMINC_USE_FILE_CONFIG "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/UseLIBMINC.cmake")
set(LIBMINC_INCLUDE_DIRS_CONFIG ${CMAKE_INSTALL_PREFIX}/include )
set(LIBMINC_LIBRARY_DIRS_CONFIG ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
#fix for superbuild install
IF(SUPERBUILD_STAGING_PREFIX)
STRING(REPLACE "${SUPERBUILD_STAGING_PREFIX}/" "" LIBMINC_INCLUDE_DIRS_CONFIG "${LIBMINC_INCLUDE_DIRS_CONFIG}")
STRING(REPLACE "${SUPERBUILD_STAGING_PREFIX}/" "" LIBMINC_LIBRARY_DIRS_CONFIG "${LIBMINC_LIBRARY_DIRS_CONFIG}")
STRING(REPLACE "${SUPERBUILD_STAGING_PREFIX}/" "" LIBMINC_LIBRARIES_CONFIG "${LIBMINC_LIBRARIES_CONFIG}")
STRING(REPLACE "${SUPERBUILD_STAGING_PREFIX}/" "" EZMINC_LIBRARIES "${EZMINC_LIBRARIES}")
STRING(REPLACE "${SUPERBUILD_STAGING_PREFIX}/" "" NETCDF_INCLUDE_DIR "${NETCDF_INCLUDE_DIR}")
STRING(REPLACE "${SUPERBUILD_STAGING_PREFIX}/" "" HDF5_INCLUDE_DIR "${HDF5_INCLUDE_DIR}")
STRING(REPLACE "${SUPERBUILD_STAGING_PREFIX}/" "" NETCDF_LIBRARY "${NETCDF_LIBRARY}")
STRING(REPLACE "${SUPERBUILD_STAGING_PREFIX}/" "" HDF5_LIBRARY "${HDF5_LIBRARY}")
STRING(REPLACE "${SUPERBUILD_STAGING_PREFIX}/" "" ZLIB_LIBRARIES "${ZLIB_LIBRARIES}")
ENDIF(SUPERBUILD_STAGING_PREFIX)
configure_file(LIBMINCConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LIBMINCConfig.cmake @ONLY )
configure_file(UseLIBMINC.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/UseLIBMINC.cmake @ONLY)
INSTALL(FILES
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/UseLIBMINC.cmake
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LIBMINCConfig.cmake
DESTINATION lib${LIB_SUFFIX}
COMPONENT Development)
# testing
IF(BUILD_TESTING)
ADD_SUBDIRECTORY(testdir)
ENDIF(BUILD_TESTING)