forked from mklassen/gadgetron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
312 lines (281 loc) · 11.6 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
cmake_minimum_required(VERSION 2.8)
project(GADGETRON)
# 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")
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 7)
set(GADGETRON_VERSION_PATCH 6)
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(${GADGETRON_GIT_SHA1_LEN} LESS 40)
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(NOT CMAKE_BUILD_TYPE)
# 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( CMAKE_SIZEOF_VOID_P EQUAL 8 )
message("32bit system is found")
set( HAS_64_BIT Off CACHE BOOL "64bit build")
endif( CMAKE_SIZEOF_VOID_P EQUAL 8 )
# 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 (USE_OPENMP)
message("OpenMP multithreading is supported, but disabled")
endif(USE_OPENMP)
else (OPENMP_FOUND)
message("OpenMP multithreading not supported")
endif (OPENMP_FOUND)
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 ( HAS_64_BIT )
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP")
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 (WIN32)
if (UNIX)
if (APPLE)
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
else (APPLE)
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++11")
endif (APPLE)
endif (UNIX)
endif (WIN32)
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 (WIN32)
endif (BUILD_SUPPRESS_WARNINGS)
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(WIN32)
if(WIN32)
add_definitions( -DBOOST_ALL_NO_LIB )
add_definitions( -DBOOST_ALL_DYN_LINK )
endif(WIN32)
# 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 REQUIRED)
else(WIN32)
find_package(Boost COMPONENTS system thread program_options filesystem REQUIRED)
endif(WIN32)
find_package(ACE)
if(NOT ACE_FOUND)
MESSAGE("ACE not found. Only toolboxes and standalone applications are compiled. The streaming framework will NOT be compiled.")
endif(NOT ACE_FOUND)
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 (NOT WIN32)
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 (GADGETRON_CUDA_ALL_COMPUTE_MODEL)
MESSAGE("Compiling with ${CUDA_NVCC_FLAGS}")
else (CUDA_FOUND)
MESSAGE("CUDA not found. CUDA components will not be compiled.")
SET( GADGETRON_CUDA_FOUND_BOOL 0 )
SET( CUDA_NVCC_FLAGS "NA")
endif (CUDA_FOUND)
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 (GTEST_SRC_DIR AND GTEST_INCLUDE_DIRS)
endif (NOT GTEST_FOUND)
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 ( NOT _armadillo_blas_long_long )
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 ( NOT _armadillo_blas_long_long )
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)
if (HDF5_FOUND)
message("HDF5 Found")
else()
message("HDF5 not found")
endif()
find_package(FFTW3 COMPONENTS single double)
if (FFTW3_FOUND)
message("FFTW3 Found")
else()
message("FFTW3 not found")
endif()
find_package(Ismrmrd)
if (ISMRMRD_FOUND)
message("ISMRMRD Found")
else()
message("ISMRMRD not found")
endif()
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 (MKL_FOUND)
find_package(BLAS)
find_package(LAPACK)
if (LAPACK_FOUND)
message("LAPACK Found")
ADD_DEFINITIONS(-DUSE_LAPACK)
endif (LAPACK_FOUND)
find_package(PythonLibs 2)
find_package(NumPy)
find_package(GMatlab)
if (MATLAB_FOUND)
ADD_DEFINITIONS(-DUSE_MATLAB)
endif (MATLAB_FOUND)
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(WIN32)
find_package(OpenGL)
find_package(GLEW)
find_package(GLUT)
find_package(Qt4 4.6)
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 (GADGETRON_INSTALL_DEPENDENCIES)
endif (WIN32)
if (UNIX)
if (NOT APPLE)
if (GADGETRON_INSTALL_DEPENDENCIES)
include(${CMAKE_SOURCE_DIR}/cmake/InstallLinuxDependencies.cmake)
endif (GADGETRON_INSTALL_DEPENDENCIES)
endif (NOT APPLE)
endif (UNIX)
# --- 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(CPACK_GENERATOR)