-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
332 lines (265 loc) · 9.96 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
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
if(COMMAND cmake_policy)
CMAKE_POLICY(VERSION 2.8.8)
endif(COMMAND cmake_policy)
project(DMRITOOL)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/CMake)
include(PreventInSourceBuilds)
include(PreventInBuildInstalls)
include(ProjectCMakeFunctions)
set(DMRITOOL_VERSION_MAJOR "0")
set(DMRITOOL_VERSION_MINOR "1")
set(DMRITOOL_VERSION_PATCH "1")
option(BUILD_STATIC_EXECUTABLES "Build static executables" OFF)
if(BUILD_STATIC_EXECUTABLES)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
set(BLA_STATIC TRUE)
else(BUILD_STATIC_EXECUTABLES)
option(BUILD_SHARED_LIBS "Build shared libs" ON)
endif(BUILD_STATIC_EXECUTABLES)
set(DMRITOOL_SETTINGS_DIRECTORY "$ENV{HOME}/.dmritool")
if(NOT VERBOSITY_LEVEL)
set(VERBOSITY_LEVEL 0 CACHE STRING
"VERBOSITY Level for DEBUG."
FORCE)
endif(NOT VERBOSITY_LEVEL)
add_definitions(-DUTL_VERBOSITY=${VERBOSITY_LEVEL})
# Support for C++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
endif()
option(BUILD_DOXYGEN_DOCUMENTATION "Build doxygen documentation" OFF)
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release 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()
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
set(VTK_LIBRARIES_back ${VTK_LIBRARIES})
find_package(ITK 4 REQUIRED)
include(${ITK_USE_FILE})
set(ITK_LIBRARIES_back ${ITK_LIBRARIES})
find_package(GenerateCLP REQUIRED)
include(${GenerateCLP_USE_FILE})
set(VTK_LIBRARIES ${VTK_LIBRARIES_back})
set(ITK_LIBRARIES ${ITK_LIBRARIES_back})
find_path(MKL_INCLUDE_DIR mkl_cblas.h
/opt/intel/mkl/include
$ENV{HOME}/intel/mkl/include
/usr/include
/usr/local/include
)
mark_as_advanced(MKL_INCLUDE_DIR)
if (IS_DIRECTORY ${MKL_INCLUDE_DIR})
option(DMRITOOL_USE_MKL "Use MKL for numerical algebra" ON)
else()
option(DMRITOOL_USE_MKL "Use MKL for numerical algebra" OFF)
endif()
if (DMRITOOL_USE_MKL)
find_package(MKL REQUIRED)
message("MKL_LIBRARIES=${MKL_LIBRARIES}")
add_definitions(-DUTL_USE_MKL)
set(LAPACK_LIBRARIES ${MKL_LIBRARIES})
set(BLAS_LIBRARIES ${MKL_LIBRARIES})
else()
## BLAS - required by utl::NDArray, spams
find_package(OpenBLAS REQUIRED)
## LAPACK - required by utl::NDArray, spams
find_package(LAPACK REQUIRED)
set(LAPACK_LIBRARIES "${LAPACK_LIBRARIES}")
set(BLAS_LIBRARIES ${OpenBLAS_LIBRARY} ${LAPACK_LIBRARIES})
endif()
set(LAPACK_FOUND TRUE)
set(BLAS_FOUND TRUE)
if (BUILD_STATIC_EXECUTABLES)
set(BLAS_LIBRARIES "${BLAS_LIBRARIES};-lgfortran")
endif()
message("BLAS_LIBRARIES=${BLAS_LIBRARIES}")
message("LAPACK_LIBRARIES=${LAPACK_LIBRARIES}")
# message("ITK_LIBRARIES=${ITK_LIBRARIES}")
# message("VTK_LIBRARIES=${VTK_LIBRARIES}")
option(DMRITOOL_USE_FASTLAPACK "Use fast version of LAPACK routines, it needs to build openblas manually, or use MKL." OFF)
if (DMRITOOL_USE_FASTLAPACK)
set(DMRITOOL_USE_FASTLAPACK ON)
add_definitions(-DUTL_USE_FASTLAPACK)
endif()
## for spams
add_definitions(-DUSE_BLAS_LIB=1)
## Required Packages
find_package(GSL REQUIRED)
include_directories(${GSL_INCLUDE_DIRS})
message("GSL_LIBRARIES=${GSL_LIBRARIES}")
## OpenMP
option(DMRITOOL_USE_OPENMP "Use double precision OpenMP if found" OFF)
if(DMRITOOL_USE_OPENMP)
find_package(OpenMP REQUIRED)
add_definitions(-DUTL_USE_OPENMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
# Copy Data
configure_files(${DMRITOOL_SOURCE_DIR}/Data ${DMRITOOL_SETTINGS_DIRECTORY}/Data)
# Configuration files with build settings
configure_file(${DMRITOOL_SOURCE_DIR}/CMake/DMRITOOLConfigure.h.in ${DMRITOOL_BINARY_DIR}/DMRITOOLConfigure.h)
## BUILD_TESTING
option(BUILD_TESTING "Build tests" ON)
if (BUILD_TESTING)
set(buildalltests "alltests")
add_custom_target(${buildalltests})
enable_testing()
include(CTest)
endif()
# Google Test
if (BUILD_TESTING)
add_subdirectory(ThirdParty/gtest)
message("GTEST_INCLUDE_DIRS=${GTEST_INCLUDE_DIRS}")
message("GTEST_LIBS_DIR=${GTEST_LIBS_DIR}")
include_directories(${GTEST_INCLUDE_DIRS})
endif ()
## Modules
subdirlist(DMRITOOL_MODULE_DIRECTORIES ${DMRITOOL_SOURCE_DIR}/Modules)
set(THIRDPARTY_DIRECTORIES
gtest
Spams
exprtk
VariableLengthVectorImage
)
add_subdirectory(ThirdParty/exprtk)
include_directories(${EXPRTK_INCLUDE_DIRS})
set(EXPRTK_LIBRARY exprtk_lib)
set(DMRITOOL_ITK_MODULE_DIRECTORIES
ThirdParty/SpatiallyDenseSparseVectorImage
)
set(DMRITOOL_INCLUDE_DIRECTORIES ${DMRITOOL_BINARY_DIR} ${DMRITOOL_SOURCE_DIR})
foreach(dir ${DMRITOOL_MODULE_DIRECTORIES})
set(DMRITOOL_INCLUDE_DIRECTORIES ${DMRITOOL_INCLUDE_DIRECTORIES} ${DMRITOOL_SOURCE_DIR}/Modules/${dir}/include)
endforeach(dir)
foreach(dir ${DMRITOOL_ITK_MODULE_DIRECTORIES})
set(DMRITOOL_INCLUDE_DIRECTORIES ${DMRITOOL_INCLUDE_DIRECTORIES} ${DMRITOOL_SOURCE_DIR}/${dir}/include)
endforeach(dir)
foreach(dir ${THIRDPARTY_DIRECTORIES})
set(DMRITOOL_INCLUDE_DIRECTORIES ${DMRITOOL_INCLUDE_DIRECTORIES} ${DMRITOOL_SOURCE_DIR}/ThirdParty/${dir}/include)
endforeach(dir)
include_directories(${DMRITOOL_INCLUDE_DIRECTORIES})
foreach(dir ${DMRITOOL_MODULE_DIRECTORIES})
set(dir_abs ${PROJECT_SOURCE_DIR}/Modules/${dir})
if (EXISTS "${dir_abs}/src" AND EXISTS "${dir_abs}/src/CMakeLists.txt")
add_subdirectory(${dir_abs}/src)
endif()
if (BUILD_TESTING AND EXISTS "${dir_abs}/test" AND EXISTS "${dir_abs}/test/CMakeLists.txt")
add_subdirectory(${dir_abs}/test)
endif()
endforeach(dir)
foreach(dir ${DMRITOOL_ITK_MODULE_DIRECTORIES})
set(dir_abs ${PROJECT_SOURCE_DIR}/ThirdParty/${dir})
if (EXISTS "${dir_abs}/src" AND EXISTS "${dir_abs}/src/CMakeLists.txt")
add_subdirectory(${dir}/src)
endif()
endforeach(dir)
foreach(dir ${THIRDPARTY_DIRECTORIES})
set(dir_abs ${PROJECT_SOURCE_DIR}/ThirdParty/${dir})
if (EXISTS "${dir_abs}/src" AND EXISTS "${dir_abs}/src/CMakeLists.txt")
add_subdirectory(${dir_abs}/src)
endif()
if(BUILD_TESTING AND EXISTS "${dir_abs}/test" AND EXISTS "${dir_abs}/test/CMakeLists.txt")
add_subdirectory(${dir_abs}/test)
endif ()
endforeach(dir)
##
# Ensure inclusion of files in Xcode/Qt project file.
#
if(APPLE)
file(GLOB_RECURSE HEADER_FILES ${DMRITOOL_SOURCE_DIR}/Modules/*.h)
file(GLOB_RECURSE IMPLEMENTATION_FILES ${DMRITOOL_SOURCE_DIR}/Modules/*.hxx)
add_library(MODULES MODULE ${HEADER_FILES} ${IMPLEMENTATION_FILES})
target_link_libraries(MODULES ${ITK_LIBRARIES} ${VTK_LIBRARIES} ${GSL_LIBRARIES})
endif(APPLE)
##
# Applications
#
add_subdirectory(Applications)
add_subdirectory(ThirdPartyApplications)
add_subdirectory(Utilities)
if (BUILD_QT_APPLICATIONS)
find_package(Qt4 REQUIRED)
else()
find_package(Qt4)
endif()
if (NOT QT4_FOUND AND NOT QT_FOUND)
option(BUILD_QT_APPLICATIONS "Build QT Applications" OFF)
else()
option(BUILD_QT_APPLICATIONS "Build QT Applications" ON)
# Widgets finds its own dependencies.
# find_package(Qt5Widgets REQUIRED)
set(QT_USE_QTSVG TRUE)
set(QT_USE_QTXML TRUE)
include(${QT_USE_FILE})
if (BUILD_QT_APPLICATIONS)
add_subdirectory(QTApplications)
endif()
endif()
##
# Wrapping
#
add_subdirectory(Wrapping)
## Testing
IF (BUILD_TESTING)
add_subdirectory(Testing)
endif()
##
# Output Directories for Executable, Library, and Archive Targets
#
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${DMRITOOL_BINARY_DIR}/bin CACHE INTERNAL
"Executable output directory")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
${DMRITOOL_BINARY_DIR}/lib CACHE INTERNAL
"Library output directory")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${DMRITOOL_BINARY_DIR}/lib CACHE INTERNAL
"Archive output directory")
set(DMRITOOL_LIBRARY_DIRECTORIES ${DMRITOOL_BINARY_DIR}/lib)
set(DMRITOOL_USE_FILE ${DMRITOOL_BINARY_DIR}/UseDMRITOOL.cmake)
configure_file(CMake/DMRITOOLConfig.cmake.in ${DMRITOOL_BINARY_DIR}/DMRITOOLConfig.cmake)
configure_file(CMake/UseDMRITOOL.cmake.in ${DMRITOOL_BINARY_DIR}/UseDMRITOOL.cmake COPYONLY IMMEDIATE)
##
# Doxygen Documentation
#
if(BUILD_DOXYGEN_DOCUMENTATION)
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DMRITOOL_DOXYGEN_OUTPUT_DIR ${DMRITOOL_BINARY_DIR}/Documentation/Doxygen)
configure_file(${DMRITOOL_SOURCE_DIR}/Documentation/Doxygen/doxygen.in ${DMRITOOL_DOXYGEN_OUTPUT_DIR}/doxygen.config)
option(LINK_EXTERNAL_DOXYGEN "Build doxygen document with external tags" OFF)
if(LINK_EXTERNAL_DOXYGEN)
include(ExternalDoxygenTAG)
add_custom_target(doxygen
COMMAND sed -e 's/PROJECT_NUMBER.*=.*\\>/PROJECT_NUMBER = '$$\( cd ${DMRITOOL_SOURCE_DIR} && git describe --abbrev=8 --always\)'/' ${DMRITOOL_DOXYGEN_OUTPUT_DIR}/doxygen.config | doxygen -
# COMMAND ${DOXYGEN} ${DMRITOOL_DOXYGEN_OUTPUT_DIR}/doxygen.config
DEPENDS ${DMRITOOL_DOXYGEN_OUTPUT_DIR}/InsightDoxygen.tag ${DMRITOOL_DOXYGEN_OUTPUT_DIR}/vtkNightlyDoc.tag
)
else()
add_custom_target(doxygen
COMMAND sed -e 's/PROJECT_NUMBER.*=.*\\>/PROJECT_NUMBER = '$$\( cd ${DMRITOOL_SOURCE_DIR} && git describe --abbrev=8 --always\)'/' ${DMRITOOL_DOXYGEN_OUTPUT_DIR}/doxygen.config | doxygen -
# COMMAND ${DOXYGEN} ${DMRITOOL_DOXYGEN_OUTPUT_DIR}/doxygen.config
)
endif()
endif(DOXYGEN_FOUND)
endif(BUILD_DOXYGEN_DOCUMENTATION)
##
# Packaging
#
include(InstallRequiredSystemLibraries)
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
set(CPACK_PACKAGE_VERSION_MAJOR "${DMRITOOL_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${DMRITOOL_VERSION_MINOR}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "DMRITOOL")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "dmritool-${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")
include(CPack)