forked from gadgetron/gadgetron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
332 lines (298 loc) · 12.1 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
cmake_minimum_required(VERSION 2.8.7) #Currently targeting to TRAVIS CI cmake version from 2011
foreach(p
CMP0025 # CMake 3.0 Compiler id for Apple Clang is now ``AppleClang``.
CMP0042 # CMake 3.0 ``MACOSX_RPATH`` is enabled by default.
CMP0046 # CMake 3.0 Error on non-existent dependency in add_dependencies.
CMP0054 # CMake 3.1 Only interpret ``if()`` arguments as variables or keywords when unquoted.
CMP0056 # CMake 3.2 Honor link flags in ``try_compile()`` source-file signature.
CMP0058 # CMake 3.3 Ninja requires custom command byproducts to be explicit.
)
if(POLICY ${p})
cmake_policy(SET ${p} NEW)
endif()
endforeach()
project(GADGETRON)
# --- Provide good defaults for searching for packages (i.e. ismrmrd)
set(CMAKE_PREFIX_PATH "")
if(CMAKE_PREFIX_PATH)
list(APPEND CMAKE_PREFIX_PATH "/usr/local")
endif()
if(EXISTS $ENV{CMAKE_PREFIX_PATH})
list(APPEND CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
endif()
if(EXISTS $ENV{ISMRMRD_HOME})
list(APPEND CMAKE_PREFIX_PATH $ENV{ISMRMRD_HOME})
endif()
list(REMOVE_DUPLICATES CMAKE_PREFIX_PATH)
message(STATUS "Looking for packages in : ${CMAKE_PREFIX_PATH}")
# ---
# check the compiler version
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (NOT CMAKE_CXX_COMPILER_VERSION) #Compiler version is not set on Ubuntu 12.02 (gcc 4.6)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION)
endif()
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.8)
message("CXX COMPILER VERSION: ${CMAKE_CXX_COMPILER_ID} : ${CMAKE_CXX_COMPILER_VERSION}")
message(FATAL_ERROR "Gadgetron requires GCC version >= 4.8")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)
message(FATAL_ERROR "Gadgetron requires Clang version >= 3.5")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
message(FATAL_ERROR "Gadgetron requires MSVC 2013 or above ")
endif()
else()
message(WARNING "Unsupported compiler!")
endif()
#VERSIONING AND INSTALL PATHS
set(GADGETRON_VERSION_MAJOR 3)
set(GADGETRON_VERSION_MINOR 14)
set(GADGETRON_VERSION_PATCH 1)
set(GADGETRON_VERSION_STRING ${GADGETRON_VERSION_MAJOR}.${GADGETRON_VERSION_MINOR}.${GADGETRON_VERSION_PATCH})
set(GADGETRON_SOVERSION ${GADGETRON_VERSION_MAJOR}.${GADGETRON_VERSION_MINOR})
find_package(Git)
if (GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD WORKING_DIRECTORY
${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE GADGETRON_GIT_SHA1 ERROR_VARIABLE GADGETRON_GIT_STDERR)
string(STRIP "${GADGETRON_GIT_SHA1}" GADGETRON_GIT_SHA1)
string(LENGTH "${GADGETRON_GIT_SHA1}" GADGETRON_GIT_SHA1_LEN)
if(${GADGETRON_GIT_SHA1_LEN} LESS 40)
message(WARNING "Could not determine SHA-1 hash: ${GADGETRON_GIT_STDERR}")
set(GADGETRON_GIT_SHA1 "NA")
endif()
else()
set(GADGETRON_GIT_SHA1 "NA")
endif()
set(GADGETRON_INSTALL_CMAKE_PATH share/gadgetron/cmake)
set(GADGETRON_INSTALL_CONFIG_PATH share/gadgetron/config)
set(GADGETRON_INSTALL_MATLAB_PATH share/gadgetron/matlab)
set(GADGETRON_INSTALL_PYTHON_MODULE_PATH share/gadgetron/python)
set(GADGETRON_INSTALL_SCHEMA_PATH share/gadgetron/schema)
set(GADGETRON_INSTALL_INCLUDE_PATH include/gadgetron)
set(GADGETRON_INSTALL_CHROOT_SCRIPTS_PATH share/gadgetron/chroot)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
#Set the build type to Release if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
# build options for 64 bits system
if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
message("64bit system is found")
set( HAS_64_BIT On CACHE BOOL "64bit build")
else()
message("32bit system is found")
set( HAS_64_BIT Off CACHE BOOL "64bit build")
endif()
# whether to install dependencies
option(GADGETRON_INSTALL_DEPENDENCIES "Install gadgetron dependencies" Off)
# build options for OpenMP support
find_package(OpenMP)
option(USE_OPENMP "Use OpenMP" On)
if (OPENMP_FOUND)
if(USE_OPENMP)
message("OpenMP multithreading enabled")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
add_definitions(-DUSE_OMP)
else ()
message("OpenMP multithreading is supported, but disabled")
endif()
else ()
message("OpenMP multithreading not supported")
endif ()
if (WIN32)
add_definitions(-DWIN32 -D_WIN32 -D_WINDOWS)
# add_definitions(-DUNICODE -D_UNICODE)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_VARIADIC_MAX=10) #to fix compiler limitations in Visual Studio Express
add_definitions("/wd4251") #disable warnings, 4251: needs to have dll-interface to be used by clients
add_definitions("/wd4344") #disable warnings, 4344: behavior change: use of explicit template arguments
add_definitions("/wd4996") #disable warnings, 4996: the POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name
if ( HAS_64_BIT )
add_definitions(-DWIN64 -D_WIN64)
endif ()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /bigobj")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
set (CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} /INCREMENTAL:NO")
set (CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} /INCREMENTAL:NO")
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
set (CMAKE_SHARED_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
set (CMAKE_STATIC_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
set (CMAKE_MODULE_LINKER_FLAGS_DEBUG "/debug /INCREMENTAL:NO")
# The two flags below is to fix Windows problems in relation to multiple defined operators new/delete and some constructors that are defined in our headers
# set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /FORCE:MULTIPLE")
# set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /FORCE:MULTIPLE")
else ()
if (UNIX)
if (APPLE)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -stdlib=libc++")
else ()
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++11")
else()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++14")
endif()
endif ()
endif ()
endif ()
include_directories(${CMAKE_SOURCE_DIR}/toolboxes/log)
# whether to suppress compilation warnings
option(BUILD_SUPPRESS_WARNINGS "Build package while suppressing warnings" Off)
if (BUILD_SUPPRESS_WARNINGS)
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W0")
elseif (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -w")
endif ()
endif ()
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
# necessary for Windows and RHEL <=6 systems
set(Boost_NO_BOOST_CMAKE ON)
if(WIN32)
add_definitions( -DBOOST_ALL_NO_LIB )
add_definitions( -DBOOST_ALL_DYN_LINK )
endif()
if(WIN32)
add_definitions( -DBOOST_ALL_NO_LIB )
add_definitions( -DBOOST_ALL_DYN_LINK )
endif()
# We actually only use system and thread explicitly, but they require linking in date_time and chrono
if (WIN32)
find_package(Boost COMPONENTS system thread date_time chrono program_options filesystem timer REQUIRED)
else()
find_package(Boost COMPONENTS system thread program_options filesystem timer REQUIRED)
endif()
find_package(ACE REQUIRED)
find_package(CUDA_advanced)
if (CUDA_FOUND)
add_definitions(-DUSE_CUDA)
set( GADGETRON_CUDA_FOUND_BOOL 1 )
include_directories( ${CUDA_INCLUDE_DIRS} )
if (NOT WIN32)
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
endif ()
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} )
set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
#set(CUDA_VERBOSE_BUILD ON)
# Compile kernels for compute models 1.0 and 2.0 as default for Cuda 4.1
# Support compute model 3.0 from Cuda 4.2 and up
# Support compute model 3.5 from Cuda 5 and up
option(GADGETRON_CUDA_ALL_COMPUTE_MODEL "Build CUDA components for all computing models" Off)
if (GADGETRON_CUDA_ALL_COMPUTE_MODEL)
message("Compiling CUDA components to support compute model 2.0, 3.0 and 3.5")
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-gencode arch=compute_20,code=sm_20")
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-gencode arch=compute_30,code=sm_30")
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-gencode arch=compute_35,code=sm_35")
endif ()
message("Compiling with ${CUDA_NVCC_FLAGS}")
else ()
message("CUDA not found. CUDA components will not be compiled.")
set( GADGETRON_CUDA_FOUND_BOOL 0 )
set( CUDA_NVCC_FLAGS "NA")
endif ()
find_package(GTest)
#Add support for the default ubuntu package of gtest (which is not compiled
if (NOT GTEST_FOUND)
find_path(GTEST_SRC_DIR src/gtest.cc HINTS /usr/src/gtest)
find_path(GTEST_INCLUDE_DIRS gtest.h HINTS /usr/include/gtest)
if (GTEST_SRC_DIR AND GTEST_INCLUDE_DIRS)
message("GTest src package found. Compiling as part of Gadgetron.")
add_subdirectory(${GTEST_SRC_DIR} ${CMAKE_BINARY_DIR}/gtest )
include_directories(${GTEST_INCLUDE_DIRS})
set(GTEST_FOUND 1)
set(GTEST_LIBRARIES gtest gtest_main)
endif ()
endif ()
find_package(Armadillo)
# check whether ILP64 MKL should is used
if(ARMADILLO_FOUND)
add_definitions(-DUSE_ARMADILLO)
set(ARMADILLO_BLAS_LONG_LONG FALSE)
if(EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp")
# Read and parse armadillo config.hpp to find out whether BLAS uses long long
file(STRINGS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp" _armadillo_blas_long_long REGEX "// #define ARMA_BLAS_LONG_LONG")
if ( NOT _armadillo_blas_long_long )
set(ARMADILLO_BLAS_LONG_LONG TRUE)
message("Armadillo is found to use long long for BLAS calls")
else ()
message("Armadillo found. Note that ARMADILLO_BLAS_LONG_LONG _must_ be defined in ${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp to link against the MKL ILP64 interface.")
endif ()
unset(_armadillo_blas_long_long)
endif()
else()
message("Armadillo not found. This will disable many toolboxes and gadgets.")
endif()
find_package(HDF5 1.8 COMPONENTS C CXX HL REQUIRED)
find_package(FFTW3 COMPONENTS single double REQUIRED)
find_package(ISMRMRD REQUIRED)
link_directories(${ISMRMRD_LIBRARY_DIRS})
find_package(MKL)
if (MKL_FOUND)
if ( MKL_VERSION_STRING VERSION_LESS 11.2.0 )
message(FATAL_ERROR "Gadgetron requires Intel MKL version >= 11.2.0")
endif ()
endif ()
find_package(BLAS)
find_package(LAPACK)
if (LAPACK_FOUND)
message("LAPACK Found")
add_definitions(-DUSE_LAPACK)
endif ()
find_package(PythonLibs 2)
string(REPLACE "." ";" PYTHON_VERSION_MAJOR ${PYTHONLIBS_VERSION_STRING})
list(GET PYTHON_VERSION_MAJOR 0 PYVER)
add_definitions(-DPYVER=${PYVER})
find_package(NumPy)
find_package(GMatlab)
if (MATLAB_FOUND)
add_definitions(-DUSE_MATLAB)
endif ()
message("Searching for OpenGL, GLEW, GLUT, and Qt. These libraries are only used in a single standalone application and are thus non-essential.")
if(WIN32)
message("For Windows users in particular, for ease of installation we do not reccomend installing these libraries.")
endif()
find_package(OpenGL)
find_package(GLEW)
find_package(GLUT)
find_package(Qt4 4.6)
find_package(PLplot)
add_subdirectory(toolboxes)
add_subdirectory(apps)
if (ACE_FOUND AND ISMRMRD_FOUND AND FFTW3_FOUND AND HDF5_FOUND)
add_subdirectory(gadgets)
else()
message("Required dependencies for gadget compilation not found (ACE, ISMRMRD, FFTW3, HDF5).")
endif()
add_subdirectory(test)
add_subdirectory(cmake)
add_subdirectory(doc)
add_subdirectory(chroot)
# install dependencies for WIN32
if (WIN32)
if (GADGETRON_INSTALL_DEPENDENCIES)
include(${CMAKE_SOURCE_DIR}/cmake/InstallWinDependencies.cmake)
endif ()
endif ()
if (UNIX)
if (NOT APPLE)
if (GADGETRON_INSTALL_DEPENDENCIES)
include(${CMAKE_SOURCE_DIR}/cmake/InstallLinuxDependencies.cmake)
endif ()
endif ()
endif ()
# --- Main Library (end) ----
# Create package
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
include(${CMAKE_SOURCE_DIR}/cmake/gadgetron_cpack.cmake)
if(CPACK_GENERATOR)
message(STATUS "Found CPack generators: ${CPACK_GENERATOR}")
configure_file("${CMAKE_SOURCE_DIR}/cmake/cpack_options.cmake.in" ${GADGETRON_CPACK_CFG_FILE} @ONLY)
set(CPACK_PROJECT_CONFIG_FILE ${GADGETRON_CPACK_CFG_FILE})
include(CPack)
endif()