CMakeLists.txt 10.1 KB
Newer Older
1

partyd's avatar
partyd committed
2
project(Slicer3)
3

4
5
6
enable_language(C)
enable_language(CXX)

7
cmake_minimum_required(VERSION 2.8)
8
9
10
11
12
if(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
mark_as_advanced(CMAKE_BACKWARDS_COMPATIBILITY)

13
14
15
16
17

# Disable the warnings that DevStudio 2005 emits wrt to sprintf, strcpu, etc.
if(CMAKE_COMPILER_2005)
  add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
endif(CMAKE_COMPILER_2005)
18

19
20
21
22
23
24
#-----------------------------------------------------------------------------
# Update CMake module path
#
set(CMAKE_MODULE_PATH
  ${CMAKE_SOURCE_DIR}/CMake
  ${CMAKE_BINARY_DIR}/CMake
25
  ${CMAKE_CURRENT_SOURCE_DIR}
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  ${CMAKE_MODULE_PATH}
  )
  
#-----------------------------------------------------------------------------
# Convenient macro allowing to download a file
#
MACRO(downloadFile url dest)
  FILE(DOWNLOAD ${url} ${dest} STATUS status)
  LIST(GET status 0 error_code)
  LIST(GET status 1 error_msg)
  IF(error_code)
    MESSAGE(FATAL_ERROR "error: Failed to download ${url} - ${error_msg}")
  ENDIF()
ENDMACRO()

#-----------------------------------------------------------------------------
# Prerequisites
#
set(git_repo http://github.com/pieper/CTK/raw/master/)

set(file CMake/ExternalProject.cmake)
downloadFile(${git_repo}/${file} ${CMAKE_BINARY_DIR}/${file})

49
50
51
52
53
54
55
#-----------------------------------------------------------------------------
# Disable the warnings that DevStudio 2005 emits wrt to sprintf, strcpu, etc.
#
if(CMAKE_COMPILER_2005)
  add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
endif(CMAKE_COMPILER_2005)

56
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../CMake)
57
set(Slicer3_CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../CMake)
58
59


60
61
set(base "${CMAKE_BINARY_DIR}/CMakeExternals")
set(prefix "${base}/Install")
62

63
include(ExternalProject)
64
65


66
67
68
#-----------------------------------------------------------------------------
# Slicer Options
#-----------------------------------------------------------------------------
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
#
#                         ----------------------------
#                         | Case 1 | Case 2 | Case 3 |
# ----------------------------------------------------
# | Slicer3_USE_KWWIDGETS |  ON    |  ON    |  OFF   |
# |---------------------------------------------------
# | Slicer3_USE_QT        |  OFF   |  ON    |  ON    |
# |--------------------------------------------------|
# | Slicer3_USE_PYTHON    | ON|OFF | ON|OFF |  OFF   |
# |--------------------------------------------------|
# | Slicer3_USE_PYTHONQT  |   OFF  |  OFF   | ON|OFF |
# |---------------------------------------------------
#
# Case 1: [Slicer3_USE_KWWIDGETS: ON, Slicer3_USE_QT: OFF, VTK_WRAP_TCL:ON]
#   a) KwwOnly-NoPython  
#   b) KwwOnly-Python    
# 
# Case 2: [Slicer3_USE_KWWIDGETS: ON, Slicer3_USE_QT: ON, VTK_WRAP_TCL:ON]
#   a) KwwAndQt-NoPython-NoPythonQt
#   b) KwwAndQt-Python
#   c) KwwAndQt-PythonQt          [VTK_WRAP_PYTHON: ON]  -> TODO
#   d) KwwAndQt-Python-PythonQt   [VTK_WRAP_PYTHON: ON]  -> TODO
#
# Case 3: [Slicer3_USE_KWWIDGETS: OFF, Slicer3_USE_QT: ON,  VTK_WRAP_TCL:OFF]
#   a) QtOnly-NoPythonQt
#   b) QtOnly-PythonQt            [VTK_WRAP_PYTHON: ON]
#
#
# Note:
#   Tcl, Tk, blt, incrTcl and iwidgets are build only if Slicer3_USE_KWWIDGETS is ON
#   Python is build if either Slicer3_USE_PYTHON or Slicer3_USE_PYTHONQT are ON
# 
102
103
104

# KWWidgets on by default.
option(Slicer3_USE_KWWIDGETS "Build Slicer3 KWWidgets GUI" ON)
105

106
# QT
107
108
109
option(Slicer3_USE_QT  "Build Slicer3 Qt GUI" OFF)

if(Slicer3_USE_QT)
110
111
  find_package(Qt4 4.6 REQUIRED)
  
112
113
114
115
  # Enable modules
  SET(QT_USE_QTNETWORK ON)
  # Includes Qt headers
  INCLUDE(${QT_USE_FILE})
116
117
118
119
120
121

  option(Slicer3_USE_PYTHONQT "Integrate a python-QT interpreter into Slicer." OFF)
  if (Slicer3_USE_PYTHONQT)
  
  endif()
  
122
123
endif()

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Python
option(Slicer3_USE_PYTHON "Build Slicer with Python support" OFF)

if(Slicer3_USE_PYTHON)

  # Attempt to detect if we have a Fortran Compiler available.
  include(CheckFortran)

  if(CMAKE_Fortran_COMPILER)
    option(Slicer3_BUILD_NUMPY "Build Slicer with NumPy (builds Blas and Lapack)." ON)

    if(Slicer3_BUILD_NUMPY)
      option(Slicer3_BUILD_SCIPY "Build Slicer with SciPy (requires NumPy)" ON)
    endif()

  endif(CMAKE_Fortran_COMPILER)
endif() # Slicer3_USE_PYTHON

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Check options
if (NOT Slicer3_USE_KWWIDGETS AND NOT Slicer3_USE_QT)
  set(err "error: Slicer SuperBuild requires at least Slicer3_USE_KWWIDGETS or Slicer3_USE_QT to be ON.

Slicer3_USE_KWWIDGETS = ON
 -> Means Slicer will be built only with KWWidgets support.
 
Slicer3_USE_KWWIDGETS = ON and Slicer3_USE_QT = ON
 -> Means Slicer will be built with both KWWidgets and QT support.
 
Slicer3_USE_QT = ON
 -> Means Slicer will be build only with QT support.
")

  message(FATAL_ERROR "${err}")
endif()

if (Slicer3_USE_PYTHON AND Slicer3_USE_PYTHONQT)
  set(err "error: Slicer SuperBuild doesn't support Slicer3_USE_PYTHON and Slicer3_USE_PYTHONQT ON.")

  message(FATAL_ERROR "${err}")
endif()

165
# Always build Shared
166
167
set(BUILD_SHARED_LIBS ON)

168
# By default, let's build as Debug
partyd's avatar
partyd committed
169
if(NOT DEFINED CMAKE_BUILD_TYPE)
170
  set(CMAKE_BUILD_TYPE "Debug")
partyd's avatar
partyd committed
171
endif()
172

173
174
175
176
177
# let a dashboard override the default.
if(CTEST_BUILD_CONFIGURATION)
  set(CMAKE_BUILD_TYPE "${CTEST_BUILD_CONFIGURATION}")
endif()

178
179
180
181
182
183
184
# Compute -G arg for configuring external projects with the same CMake generator:
#
if(CMAKE_EXTRA_GENERATOR)
  set(gen "${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
else()
  set(gen "${CMAKE_GENERATOR}")
endif()
185

186
187
188
# Enable VTK Debug Leaks
option(Slicer3_USE_VTK_DEBUG_LEAKS 
  "Turn on VTKs Debug Leaks functionality in both VTK and Slicer." ON)
189
190
191
192
193
194
195
  
  
# Configure the CTest custom file for excluding warnings fromexternal projects.
configure_file(
  ${Slicer3_CMAKE_DIR}/CTestCustom.cmake.in
  ${Slicer3_BINARY_DIR}/CTestCustom.cmake
  @ONLY IMMEDIATE)
196
197
198
199
200
201
202

#------------------------------------------------------------------------------
# Establish Target Dependencies based on Selected Options
#------------------------------------------------------------------------------

set(tk_DEPENDENCIES tcl)
set(incrTcl_DEPENDENCIES tcl tk)
203
set(iwidgets_DEPENDENCIES tcl itcl)
204
set(blt_DEPENDENCIES tcl tk)
205
206
set(python_DEPENDENCIES)
if(Slicer3_USE_KWWIDGETS)
207
  set(python_DEPENDENCIES tcl tk)
208
endif()
209
210
set(blas_DEPENDENCIES)
set(lapack_DEPENDENCIES)
211
212
set(numpy_DEPENDENCIES blas lapack python)
set(scipy_DEPENDENCIES numpy)
213
set(vtk_DEPENDENCIES)
214
set(CTK_DEPENDENCIES vtk)
215
216
217
if(Slicer3_USE_PYTHONQT)
  list(append CTK_DEPENDENCIES python)
endif()
218
219
set(KWWidgets_DEPENDENCIES vtk)
set(Insight_DEPENDENCIES)
220
221
222
set(BatchMake_DEPENDENCIES Insight)
set(OpenIGTLink_DEPENDENCIES)
set(teem_DEPENDENCIES vtk)
223
set(cmcurl_DEPENDENCIES)
224
set(slicer_DEPENDENCIES vtk Insight BatchMake OpenIGTLink teem cmcurl)
225
226
227
228

#------------------------------------------------------------------------------
# Include Each Target
#------------------------------------------------------------------------------
229
if(Slicer3_USE_KWWIDGETS)
230
231
232
233
234
  include(External_Tcl)
  include(External_Tk)
  include(External_incrTcl)
  include(External_iwidgets)
  include(External_blt)
235
endif(Slicer3_USE_KWWIDGETS)
236

237
if(Slicer3_USE_PYTHON OR Slicer3_USE_PYTHONQT)
238
  include(External_Python26)
239
endif(Slicer3_USE_PYTHON OR Slicer3_USE_PYTHONQT)
240

241
if(CMAKE_Fortran_COMPILER AND Slicer3_BUILD_NUMPY)
242
243
244
  include(External_BLAS)
  include(External_LAPACK)
  include(External_NumPy)
245

246
247
248
249
  if(Slicer3_BUILD_SCIPY)
    include(External_SciPy)
  endif(Slicer3_BUILD_SCIPY)
endif(CMAKE_Fortran_COMPILER AND Slicer3_BUILD_NUMPY)
250

251
include(External_VTK)
252

253
if(Slicer3_USE_QT)
254
  include(External_CTK)
255
256
endif(Slicer3_USE_QT)

257
if(Slicer3_USE_KWWIDGETS)
258
  include(External_KWWidgets)
259
endif(Slicer3_USE_KWWIDGETS)
260

261
262
263
264
265
include(External_Insight)
include(External_teem)
include(External_OpenIGTLink)
include(External_BatchMake)
include(External_cmcurl)
266

267
#-----------------------------------------------------------------------------
268
269
270
271
272
273
274
# build the slicer
# - first run cmake
# - create the Slicer3Version.txt file
# - then run plaftorm specific build command

set(proj Slicer3)

275
# For now, tk and itcl are used only when Slicer3_USE_KWWIDGETS is ON
276
if(Slicer3_USE_KWWIDGETS)
277
278
279
280
281
  if(WIN32)
    list(APPEND slicer_DEPENDENCIES tcl KWWidgets)
  else()
    list(APPEND slicer_DEPENDENCIES tcl tk itcl KWWidgets)
  endif()
282
283
endif(Slicer3_USE_KWWIDGETS)

284
if(CMAKE_Fortran_COMPILER)
285
  list(APPEND slicer_DEPENDENCIES numpy blas lapack)
286
endif(CMAKE_Fortran_COMPILER)
partyd's avatar
partyd committed
287

288
289
290
set(slicer_QT_ARGS)
if(Slicer3_USE_QT)
  set(slicer_QT_ARGS
291
    -DQT_QMAKE_EXECUTABLE:PATH=${QT_QMAKE_EXECUTABLE}
292
    -DCTK_DIR:PATH=${CMAKE_BINARY_DIR}/CTK-build
293
    )
294
  list(APPEND slicer_DEPENDENCIES CTK)
295
296
endif(Slicer3_USE_QT)

297
if(Slicer3_USE_PYTHON)
298
  list(APPEND slicer_DEPENDENCIES python)
299
300
301
302
303
endif(Slicer3_USE_PYTHON)

set(slicer_KWWIDGETS_ARGS)
if(Slicer3_USE_KWWIDGETS)
  set(slicer_KWWIDGETS_ARGS
304
    -DKWWidgets_DIR:PATH=${CMAKE_BINARY_DIR}/KWWidgets-build
305
306
307
    )
endif(Slicer3_USE_KWWIDGETS)

308
ExternalProject_Add(${proj}
309
  DEPENDS ${slicer_DEPENDENCIES}
310
311
  DOWNLOAD_COMMAND ""
  SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..
312
313
314
  BINARY_DIR Slicer3-build
  CMAKE_GENERATOR ${gen}
  CMAKE_ARGS
315
    -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
316
317
318
    -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
    -DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
    -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
319
    -DVTK_DEBUG_LEAKS:BOOL=${Slicer3_USE_VTK_DEBUG_LEAKS}
320
321
    -DBUILD_EXAMPLES:BOOL=OFF
    -DBUILD_TESTING:BOOL=ON
partyd's avatar
partyd committed
322
323
324
325
326
    -DITK_DIR:PATH=${CMAKE_BINARY_DIR}/Insight-build
    -DTeem_DIR:PATH=${CMAKE_BINARY_DIR}/teem-build
    -DOpenIGTLink_DIR:PATH=${CMAKE_BINARY_DIR}/OpenIGTLink-build
    -DBatchMake_DIR:PATH=${CMAKE_BINARY_DIR}/BatchMake-build
    -DVTK_DIR:PATH=${CMAKE_BINARY_DIR}/VTK-build
327
    -DSlicer3_USE_BatchMake=ON
partyd's avatar
partyd committed
328
329
    -DINCR_TCL_LIBRARY:FILEPATH=${slicer_TCL_LIB}
    -DINCR_TK_LIBRARY:FILEPATH=${slicer_TK_LIB}
partyd's avatar
partyd committed
330
    -DSlicer3_TCL_DIR:PATH=${tcl_build}
331
    -DSlicer3_USE_OPENIGTLINK:BOOL=ON
partyd's avatar
partyd committed
332
    -DSLICERLIBCURL_DIR:PATH=${CMAKE_BINARY_DIR}/cmcurl-build
333
    -DSlicer3_USE_PYTHON:BOOL=${Slicer3_USE_PYTHON}
334
    -DSlicer3_USE_SYSTEM_PYTHON:BOOL=OFF
335
    -DSlicer3_USE_NUMPY:BOOL=${Slicer3_BUILD_NUMPY}
336
    ${vtk_PYTHON_ARGS}
partyd's avatar
partyd committed
337
    -DPYTHON_EXECUTABLE:FILEPATH=${slicer_PYTHON_EXECUTABLE}
338
    -DSlicer3_USE_QT:BOOL=${Slicer3_USE_QT}
339
    ${slicer_QT_ARGS}
340
341
    -DSlicer3_USE_KWWIDGETS:BOOL=${Slicer3_USE_KWWIDGETS}
    ${slicer_KWWIDGETS_ARGS}
342
343
  INSTALL_COMMAND ""
)