CMakeLists.txt 10 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
57
58
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../CMake)


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

62
include(ExternalProject)
63
64


65
66
67
#-----------------------------------------------------------------------------
# Slicer Options
#-----------------------------------------------------------------------------
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
#
#                         ----------------------------
#                         | 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
# 
101
102
103

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

105
# QT
106
107
108
109
110
111
112
113
option(Slicer3_USE_QT  "Build Slicer3 Qt GUI" OFF)

if(Slicer3_USE_QT)
  find_package(Qt4 REQUIRED)
  # Enable modules
  SET(QT_USE_QTNETWORK ON)
  # Includes Qt headers
  INCLUDE(${QT_USE_FILE})
114
115
116
117
118
119

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

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# 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

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# 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()

163
# Always build Shared
164
165
set(BUILD_SHARED_LIBS ON)

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

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

176
177
178
179
180
181
182
# 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()
183

184
185
186
187
188
189
190
191
192
193
# Enable VTK Debug Leaks
option(Slicer3_USE_VTK_DEBUG_LEAKS 
  "Turn on VTKs Debug Leaks functionality in both VTK and Slicer." ON)

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

set(tk_DEPENDENCIES tcl)
set(incrTcl_DEPENDENCIES tcl tk)
194
set(iwidgets_DEPENDENCIES tcl itcl)
195
set(blt_DEPENDENCIES tcl tk)
196
197
198
199
set(python_DEPENDENCIES)
if(Slicer3_USE_KWWIDGETS)
  set(python_DEPENDENCIES tcl)
endif()
200
201
202
set(PythonQt_DEPENDENCIES python)
set(blas_DEPENDENCIES)
set(lapack_DEPENDENCIES)
203
204
set(numpy_DEPENDENCIES blas lapack python)
set(scipy_DEPENDENCIES numpy)
205
set(vtk_DEPENDENCIES)
206
set(CTK_DEPENDENCIES vtk)
207
208
set(KWWidgets_DEPENDENCIES vtk)
set(Insight_DEPENDENCIES)
209
210
211
set(BatchMake_DEPENDENCIES Insight)
set(OpenIGTLink_DEPENDENCIES)
set(teem_DEPENDENCIES vtk)
212
set(cmcurl_DEPENDENCIES)
213
set(slicer_DEPENDENCIES vtk Insight BatchMake OpenIGTLink teem cmcurl)
214
215
216
217

#------------------------------------------------------------------------------
# Include Each Target
#------------------------------------------------------------------------------
218
if(Slicer3_USE_KWWIDGETS)
219
220
221
222
223
  include(External_Tcl)
  include(External_Tk)
  include(External_incrTcl)
  include(External_iwidgets)
  include(External_blt)
224
endif(Slicer3_USE_KWWIDGETS)
225

226
if(Slicer3_USE_PYTHON OR Slicer3_USE_PYTHONQT)
227
  include(External_Python26)
228
endif(Slicer3_USE_PYTHON OR Slicer3_USE_PYTHONQT)
229

230
if(CMAKE_Fortran_COMPILER AND Slicer3_BUILD_NUMPY)
231
232
233
  include(External_BLAS)
  include(External_LAPACK)
  include(External_NumPy)
234

235
236
237
238
  if(Slicer3_BUILD_SCIPY)
    include(External_SciPy)
  endif(Slicer3_BUILD_SCIPY)
endif(CMAKE_Fortran_COMPILER AND Slicer3_BUILD_NUMPY)
239

240
include(External_VTK)
241

242
if(Slicer3_USE_QT)
243
  include(External_CTK)
244
245
246
247
248
  
  if(Slicer3_USE_PYTHONQT)
    include(External_PythonQt)
  endif(Slicer3_USE_PYTHONQT)
  
249
250
endif(Slicer3_USE_QT)

251
if(Slicer3_USE_KWWIDGETS)
252
  include(External_KWWidgets)
253
endif(Slicer3_USE_KWWIDGETS)
254

255
256
257
258
259
include(External_Insight)
include(External_teem)
include(External_OpenIGTLink)
include(External_BatchMake)
include(External_cmcurl)
260

261
#-----------------------------------------------------------------------------
262
263
264
265
266
267
268
# build the slicer
# - first run cmake
# - create the Slicer3Version.txt file
# - then run plaftorm specific build command

set(proj Slicer3)

269
# For now, tk and itcl are used only when Slicer3_USE_KWWIDGETS is ON
270
if(Slicer3_USE_KWWIDGETS)
271
272
273
274
275
  if(WIN32)
    list(APPEND slicer_DEPENDENCIES tcl KWWidgets)
  else()
    list(APPEND slicer_DEPENDENCIES tcl tk itcl KWWidgets)
  endif()
276
277
endif(Slicer3_USE_KWWIDGETS)

278
if(CMAKE_Fortran_COMPILER)
279
  list(APPEND slicer_DEPENDENCIES numpy blas lapack)
280
endif(CMAKE_Fortran_COMPILER)
partyd's avatar
partyd committed
281

282
283
284
set(slicer_QT_ARGS)
if(Slicer3_USE_QT)
  set(slicer_QT_ARGS
285
    -DQT_QMAKE_EXECUTABLE:PATH=${QT_QMAKE_EXECUTABLE}
286
    -DCTK_DIR:PATH=${CMAKE_BINARY_DIR}/CTK-build
287
    )
288
  list(APPEND slicer_DEPENDENCIES CTK)
289
290
endif(Slicer3_USE_QT)

291
if(Slicer3_USE_PYTHON)
292
  list(APPEND slicer_DEPENDENCIES python)
293
294
295
endif(Slicer3_USE_PYTHON)

if (Slicer3_USE_PYTHONQT)
296
  list(APPEND slicer_DEPENDENCIES PythonQt)
297
298
299
300
301
endif(Slicer3_USE_PYTHONQT)

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

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