CMakeLists.txt 27.5 KB
Newer Older
1
2
3
4
5
PROJECT(Slicer3)

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
IF(COMMAND CMAKE_POLICY)
  CMAKE_POLICY(SET CMP0003 NEW)
6
  CMAKE_POLICY(SET CMP0012 NEW)
7
8
ENDIF(COMMAND CMAKE_POLICY)
MARK_AS_ADVANCED(CMAKE_BACKWARDS_COMPATIBILITY)
9

10

11
#-----------------------------------------------------------------------------
12
#
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
set(Slicer3_INSTALL_BIN_DIR "bin")
set(Slicer3_INSTALL_LIB_DIR "lib/Slicer3")
set(Slicer3_INSTALL_INCLUDE_DIR "include/Slicer3")
set(Slicer3_INSTALL_SHARE_DIR "share/Slicer3")
set(Slicer3_INSTALL_ITKFACTORIES_DIR "${Slicer3_INSTALL_LIB_DIR}/ITKFactories")

set(Slicer3_INSTALL_PLUGINS_BIN_DIR "${Slicer3_INSTALL_LIB_DIR}/Plugins")
set(Slicer3_INSTALL_PLUGINS_LIB_DIR "${Slicer3_INSTALL_LIB_DIR}/Plugins")
set(Slicer3_INSTALL_PLUGINS_INCLUDE_DIR "${Slicer3_INSTALL_INCLUDE_DIR}/Plugins")
set(Slicer3_INSTALL_PLUGINS_SHARE_DIR "${Slicer3_INSTALL_SHARE_DIR}/Plugins")
set(Slicer3_INSTALL_PLUGINS_CACHE_DIR "${Slicer3_INSTALL_LIB_DIR}/PluginsCache")

set(Slicer3_INSTALL_MODULES_BIN_DIR "${Slicer3_INSTALL_LIB_DIR}/Modules")
set(Slicer3_INSTALL_MODULES_LIB_DIR "${Slicer3_INSTALL_LIB_DIR}/Modules")
set(Slicer3_INSTALL_MODULES_INCLUDE_DIR "${Slicer3_INSTALL_INCLUDE_DIR}/Modules")
set(Slicer3_INSTALL_MODULES_SHARE_DIR "${Slicer3_INSTALL_SHARE_DIR}/Modules")

set(Slicer3_HOME "${Slicer3_BINARY_DIR}")

32
33
34
35
#-----------------------------------------------------------------------------
# Convenient macro allowing to download a file
#
MACRO(downloadFile url dest)
36
37
38
39
40
41
42
  IF(NOT EXISTS ${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()
43
44
  ELSE()
    # Make sure the file is not empty
45
46
47
    FILE(READ ${dest} dest_content LIMIT 4)
    STRING(LENGTH "${dest_content}" dest_length)
    IF(NOT "${dest_length}" EQUAL 4)
48
49
50
      FILE(REMOVE ${dest})
      downloadFile(${url} ${dest})
    ENDIF()
51
52
53
  ENDIF()
ENDMACRO()

54
#-----------------------------------------------------------------------------
55
56
# Disable the warnings that DevStudio 2005 emits wrt to sprintf, strcpu, etc.
#
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
# warnings (copied from ITK's CMake files so that ITK templated code will compile
# correctly).
IF(WIN32)
  IF(NOT BORLAND)
    IF(NOT CYGWIN)
      IF(NOT MINGW)
        ADD_DEFINITIONS(
          -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
          -D_CRT_IS_WCTYPE_NO_DEPRECATE
          -D_CRT_MANAGED_FP_NO_DEPRECATE
          -D_CRT_NONSTDC_NO_DEPRECATE
          -D_CRT_SECURE_NO_DEPRECATE
          -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
          -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
          -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
          -D_CRT_VCCLRIT_NO_DEPRECATE
          -D_SCL_SECURE_NO_DEPRECATE
          )
      ENDIF(NOT MINGW)
    ENDIF(NOT CYGWIN)
  ENDIF(NOT BORLAND)
ENDIF(WIN32)

81

82
# include a test for endianness (used to be done by default)
barre's avatar
barre committed
83

84
85
86
87
include(${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
test_big_endian(CMAKE_WORDS_BIGENDIAN)

#-----------------------------------------------------------------------------
88
89
90
91
# avoid linker bug in Mac OS 10.5
# see:
# http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
#
92
93
94
95
if(APPLE)
  set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib")
  set(CMAKE_EXE_LINKER_FLAGS "-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib")
endif(APPLE)
96

97
98
#-----------------------------------------------------------------------------
# Slicer version number.
99
#
100
set(Slicer3_VERSION_MAJOR "3")
101
set(Slicer3_VERSION_MINOR "5")
102
103
104
105
106
if(NOT Slicer3_VERSION_PATCH)
  set(Slicer3_VERSION_PATCH "0")
endif(NOT Slicer3_VERSION_PATCH)
set(Slicer3_VERSION "${Slicer3_VERSION_MAJOR}.${Slicer3_VERSION_MINOR}")
set(Slicer3_VERSION_FULL "${Slicer3_VERSION}.${Slicer3_VERSION_PATCH}")
107

108
109
#-----------------------------------------------------------------------------
# Build shared lib by default
110
#
111
112
option(BUILD_SHARED_LIBS "Build Slicer3 with shared libraries." ON)

113
114
115
116
117
118
119
120
121
122
123
#-----------------------------------------------------------------------------
# Append the library version information to the library target properties.
#
OPTION(Slicer3_WITH_LIBRARY_VERSION "Build with library version information" OFF)
IF(Slicer3_WITH_LIBRARY_VERSION)
  SET(Slicer3_LIBRARY_PROPERTIES ${Slicer3_LIBRARY_PROPERTIES}
    VERSION ${Slicer3_VERSION_FULL}
    SOVERSION ${Slicer3_VERSION}
  )
ENDIF(Slicer3_WITH_LIBRARY_VERSION)

124
125
#-----------------------------------------------------------------------------
# Slicer3 macros
pieper's avatar
pieper committed
126
#
127
128
129
130
set(Slicer3_CMAKE_DIR "${Slicer3_SOURCE_DIR}/CMake" CACHE INTERNAL "")
add_subdirectory(CMake)
# Make sure VTK_CMAKE_DIR is at the beginning so that VTK's FindTCL is
# used before CMake's FindTCL.
131
132
133
134
135
136
set(CMAKE_MODULE_PATH
  "${VTK_CMAKE_DIR}"
  "${Slicer3_CMAKE_DIR}"
  ${Slicer3_BINARY_DIR}/CMake
  ${CMAKE_MODULE_PATH}
  )
pieper's avatar
pieper committed
137

138
include("${Slicer3_CMAKE_DIR}/Slicer3PersistenceMacros.cmake")
hliu's avatar
hliu committed
139

140
141
142
# See http://www.cmake.org/Wiki/CMakeMacroParseArguments
include("${Slicer3_CMAKE_DIR}/Slicer3ParseArgumentsMacro.cmake")

143
144
145
## QT
INCLUDE(${Slicer3_CMAKE_DIR}/Slicer3FindQT.cmake)

146
147
#-----------------------------------------------------------------------------
# Top level slicer3 configurations
148
#
149
150
151
152
153
# If CMake >= 2.6.0
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")

154
155
156

# Do NOT force into the cache, as plugins need to override locally and scoping
# becomes an issue.
157
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/ 
158
#  CACHE PATH "Single output directory for building all libraries." FORCE)
159
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/ 
160
161
162
163
#  CACHE PATH "Single output directory for building all executables." FORCE)

#-----------------------------------------------------------------------------
# Slicer include and libraries subdirectory
164
#
165
166
167
slicer3_set_persistent_property(Slicer3_Libs_LIBRARIES "")
slicer3_set_persistent_property(Slicer3_Base_LIBRARIES "")
slicer3_set_persistent_property(Slicer3_Modules_LIBRARIES "")
168
slicer3_set_persistent_property(Slicer3_QTModules_LIBRARIES "")
169

170
171
172
slicer3_set_persistent_property(Slicer3_Libs_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer3_Base_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer3_Modules_INCLUDE_DIRS "")
173
slicer3_set_persistent_property(Slicer3_QTModules_INCLUDE_DIRS "")
pieper's avatar
pieper committed
174

175
176
177
178
179
180
181
#-----------------------------------------------------------------------------
# Get sytem name and architecture
#
SET(Slicer3_BUILD NA)
INCLUDE(${Slicer3_CMAKE_DIR}/DiscoverSystemNameAndBits.cmake)
MESSAGE(STATUS "Slicer3_BUILD:${Slicer3_BUILD}")

182
#-----------------------------------------------------------------------------
pieper's avatar
pieper committed
183
# Add the testing directories
184
#
185
186
187
188
OPTION(BUILD_TESTING "Test the project" ON)
SET(Slicer3_BUILD_TESTING ${BUILD_TESTING})
SET(LAUNCH_EXE ${Slicer3_BINARY_DIR}/Slicer3 --launch)
IF(Slicer3_BUILD_TESTING)
189
190
191
192
193
  #IF (NOT BUILDNAME)
  #  SET(BUILDNAME "${Slicer3_BUILD}" CACHE STRING "Name of build on the dashboard")
  #ELSE()
  #  SET(BUILDNAME "${BUILDNAME}" CACHE STRING "Name of build on the dashboard")
  #ENDIF()
194
195
196
197
  ENABLE_TESTING()
  INCLUDE(CTest)
  SET(CXX_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  MARK_AS_ADVANCED(TCL_TCLSH DART_ROOT)
198
199
200
201
202
203

#-----------------------------------------------------------------------------
# Run test through valgrind: particularly useful for testing modules.
#
option(USE_VALGRIND "Run tests through valgrind." OFF)

204
ENDIF(Slicer3_BUILD_TESTING)
hliu's avatar
hliu committed
205

206
207
208
209
210
211
212
213
#-----------------------------------------------------------------------------
# By default, build with KWWidget
#
option(Slicer3_USE_KWWIDGETS "Build Slicer3 with KWWidgets." ON)

#-----------------------------------------------------------------------------
# Since modules are KWWidgets based, unset there variables
IF (NOT Slicer3_USE_KWWIDGETS)
214
215
216
217
  # Since the module Logic is shared between QTModules and regular Modules,
  # the associated BIN and LIB directory shouldn't be unset
  #UNSET(Slicer3_INSTALL_MODULES_BIN_DIR)
  #UNSET(Slicer3_INSTALL_MODULES_LIB_DIR)
218
219
220
221
  UNSET(Slicer3_INSTALL_MODULES_INCLUDE_DIR)
  UNSET(Slicer3_INSTALL_MODULES_SHARE_DIR)
ENDIF (NOT Slicer3_USE_KWWIDGETS)

222
#-----------------------------------------------------------------------------
223
224
225
226
227
# Libs
# - ITK
# - KWWidgets (pulls in VTK)
#

228
229
230
231
# Relax some constraints related to the build settings file. This was
# preventing people from using the same compiler but with a different generator,
# or just the same compiler installed in a non-standard location.

232
233
234
IF (Slicer3_USE_KWWIDGETS)
  set(SKIP_KWWidgets_BUILD_SETTINGS_FILE 1)
ENDIF(Slicer3_USE_KWWIDGETS)
235
236
set(SKIP_VTK_BUILD_SETTINGS_FILE 1)
set(SKIP_ITK_BUILD_SETTINGS_FILE 1)
237
set(SKIP_Teem_BUILD_SETTINGS_FILE 1)
238
239

#-----------------------------------------------------------------------------
240
## Python
241
242
option(Slicer3_USE_PYTHON "Integrate a python interpreter into Slicer." OFF)
if(Slicer3_USE_PYTHON)
243
  find_package(PythonLibs)
244
endif(Slicer3_USE_PYTHON)
245

246
#-----------------------------------------------------------------------------
247
## ITK
248
249
250
251
252
find_package(ITK REQUIRED)
if(NOT ITK_FOUND)
  message(FATAL_ERROR "Need ITK to build")
endif(NOT ITK_FOUND)
include(${ITK_USE_FILE})
253

254
255
256
#-----------------------------------------------------------------------------
# FindCTK
#
257
SET(git_repo http://github.com/commontk/CTK/raw/master/)
258
259
260
261
262
263
264
265
266
267
268

if (Slicer3_USE_QT)
  SET(file Utilities/CMake/FindCTK.cmake)
  downloadFile(${git_repo}/${file} ${Slicer3_BINARY_DIR}/CMake/FindCTK.cmake)

  FIND_PACKAGE(CTK REQUIRED)
  IF(CTK_FOUND)
    INCLUDE(${CTK_USE_FILE})
  ENDIF()
ENDIF()

269
270
271
272
273
274
275
276
#-----------------------------------------------------------------------------
IF (Slicer3_USE_KWWIDGETS)
  ## KWWidgets
  FIND_PACKAGE(KWWidgets REQUIRED)
  IF(NOT KWWidgets_FOUND)
    MESSAGE(FATAL_ERROR "Need KWWidgets to build")
  ENDIF(NOT KWWidgets_FOUND)
  INCLUDE(${KWWidgets_USE_FILE})
277
  
278
ELSE(Slicer3_USE_KWWIDGETS)
279
280

  # VTK
281
282
  FIND_PACKAGE(VTK REQUIRED)
  IF(NOT VTK_FOUND)
283
    MESSAGE(FATAL_ERROR "Need VTK to build")
284
285
286
287
288
289
  ELSE(NOT VTK_FOUND)
    IF(NOT VTK_USE_QVTK)
      MESSAGE("Please make sure VTK is build with VTK_USE_GUISUPPORT and VTK_USE_QVTK enabled")
    ENDIF(NOT VTK_USE_QVTK)
  ENDIF(NOT VTK_FOUND)
  INCLUDE(${VTK_USE_FILE})
290
  
291
292
ENDIF (Slicer3_USE_KWWIDGETS)

293
294
295
#-----------------------------------------------------------------------------
# Slicer3 is built with cvs head
#
296
297
option(Slicer3_USE_VTK_CVSHEAD "Slicer3 is configurated with cvs head." OFF)
mark_as_advanced(Slicer3_USE_VTK_CVSHEAD)
298

299
#-----------------------------------------------------------------------------
300
301
302
303
304
#
# Call macro defined in ${PROJECT_SOURCE_DIR}/CMake/Slicer3FindQT.cmake
#
SLICER3_SETUP_QT()

305
306
307
308
309
310
311
312
#-----------------------------------------------------------------------------
# Alert the user if both Slicer3_USE_QT and Slicer3_USE_KWWIDGETS are OFF
IF(NOT Slicer3_USE_QT AND NOT Slicer3_USE_KWWIDGETS)
  MESSAGE(FATAL_ERROR "Both Slicer3_USE_QT and Slicer3_USE_KWWIDGETS are OFF. Please, choose one")
ENDIF(NOT Slicer3_USE_QT AND NOT Slicer3_USE_KWWIDGETS)

#-----------------------------------------------------------------------------
# If Slicer3_USE_QT is ON and Slicer3_USE_KWWIDGETS is OFF, complain if VTK_WRAP_TCL is ON
313
# Note: Later on we will expect VTK_WRAP_PYTHON to be ON
314
315
316
317
318
319
IF(Slicer3_USE_QT AND NOT Slicer3_USE_KWWIDGETS)
  IF(VTK_WRAP_TCL)
    MESSAGE(FATAL_ERROR "For now, if Slicer3_USE_QT is ON and Slicer3_USE_KWWIDGETS is OFF, we expect VTK_WRAP_TCL to be OFF")
  ENDIF(VTK_WRAP_TCL)
ENDIF(Slicer3_USE_QT AND NOT Slicer3_USE_KWWIDGETS)

320
321
322
323
324
325
326
327
#-----------------------------------------------------------------------------
# Add Slicer3_USE_PYTHONQT option if Slicer3_USE_QT is ON
IF(Slicer3_USE_QT)
  option(Slicer3_USE_PYTHONQT "Integrate a python-QT interpreter into Slicer." OFF)
  IF(Slicer3_USE_PYTHONQT)
    IF(NOT VTK_WRAP_PYTHON)
      MESSAGE(FATAL_ERROR "Since both Slicer3_USE_QT and Slicer3_USE_PYTHONQT are ON, VTK_WRAP_PYTHON is expected to be ON. Disable Slicer3_USE_PYTHONQT or re-configure VTK with python wrapping.")
    ENDIF(NOT VTK_WRAP_PYTHON)
328
329
    # Enable qMRMLWidgets python wrapping
    SET(qMRMLWidgets_WRAP_PYTHON ON)
330
331
332
  ENDIF(Slicer3_USE_PYTHONQT)
ENDIF(Slicer3_USE_QT)  

333
#-----------------------------------------------------------------------------
334
## Teem
335
336
337
338
339
find_package(Teem REQUIRED)
if(NOT Teem_FOUND)
  message(FATAL_ERROR "Need Teem to build")
endif(NOT Teem_FOUND)
include(${Teem_USE_FILE})
340

341
#-----------------------------------------------------------------------------
342
343
344
345
346
## SlicerLibCurl
find_package(SLICERLIBCURL REQUIRED)
if(SLICERLIBCURL_FOUND)
  include(${SLICERLIBCURL_USE_FILE})
endif(SLICERLIBCURL_FOUND)
347
348

#-----------------------------------------------------------------------------
349
350
351
## BatchMake
option(Slicer3_USE_BatchMake "Build Slicer3 with BatchMake support." OFF)
if(Slicer3_USE_BatchMake)
352
353
  find_package(BatchMake REQUIRED)
  include(${BatchMake_USE_FILE})
354
endif(Slicer3_USE_BatchMake)
355

356
#-----------------------------------------------------------------------------
357
358
## MIDAS
option(Slicer3_USE_MIDAS "Build Slicer3 with MIDAS support." OFF)
359

360
#-----------------------------------------------------------------------------
361
362
363
364
365
366
## OpenIGTLink (Built in Slicer3-lib)
option(Slicer3_USE_OPENIGTLINK "Build Slicer3 with OpenIGTLink support." OFF)
if(Slicer3_USE_OPENIGTLINK)
  find_package(OpenIGTLink REQUIRED)
  include(${OpenIGTLink_USE_FILE})
endif(Slicer3_USE_OPENIGTLINK)
hliu's avatar
hliu committed
367

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#-----------------------------------------------------------------------------
## OpenCV (Built in Slicer3-lib)
option(Slicer3_USE_OPENCV "Build Slicer3 with OpenCV support." OFF)
if(Slicer3_USE_OPENCV)
  find_package(OpenCV REQUIRED)

  IF(OPENCV_BUILD_SETTINGS_FILE AND NOT SKIP_OPENCV_BUILD_SETTINGS_FILE)
    INCLUDE(${CMAKE_ROOT}/Modules/CMakeImportBuildSettings.cmake)
    CMAKE_IMPORT_BUILD_SETTINGS(${OPENCV_BUILD_SETTINGS_FILE})
  ENDIF(OPENCV_BUILD_SETTINGS_FILE AND NOT SKIP_OPENCV_BUILD_SETTINGS_FILE)
  
  # Add compiler flags needed to use OPENCV.
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPENCV_REQUIRED_C_FLAGS}")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPENCV_REQUIRED_CXX_FLAGS}")
  SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OPENCV_REQUIRED_LINK_FLAGS}")
  SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OPENCV_REQUIRED_LINK_FLAGS}")
  SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${OPENCV_REQUIRED_LINK_FLAGS}")
  
  # Add include directories needed to use OPENCV.
  INCLUDE_DIRECTORIES(BEFORE ${OPENCV_INCLUDE_DIRS})
  
  # Add link directories needed to use OPENCV.
  LINK_DIRECTORIES(${OPENCV_LIBRARY_DIRS})
  #include(${OPENCV_USE_FILE})
endif(Slicer3_USE_OPENCV)


395
396
#-----------------------------------------------------------------------------
# Need some Tcl/Tk info
397
398
399
400
401
402
403
404
405
406
407
408
IF (VTK_WRAP_TCL)
  include("${VTK_CMAKE_DIR}/vtkTclTkMacros.cmake")
  VTK_GET_TCL_TK_VERSION(TCL_TK_MAJOR_VERSION TCL_TK_MINOR_VERSION)
  set(TCL_TK_VERSION_DOT "${TCL_TK_MAJOR_VERSION}.${TCL_TK_MINOR_VERSION}")
  set(TCL_TK_VERSION "${TCL_TK_MAJOR_VERSION}${TCL_TK_MINOR_VERSION}")
  IF(Slicer3_USE_KWWIDGETS)
    include("${KWWidgets_CMAKE_DIR}/KWWidgetsTclTkMacros.cmake")
    incr_tcl_get_version(INCR_TCL_MAJOR_VERSION INCR_TCL_MINOR_VERSION)
    set(INCR_TCL_VERSION_DOT "${INCR_TCL_MAJOR_VERSION}.${INCR_TCL_MINOR_VERSION}")
    set(INCR_TCL_VERSION "${INCR_TCL_MAJOR_VERSION}${INCR_TCL_MINOR_VERSION}")
  ENDIF(Slicer3_USE_KWWIDGETS)
ENDIF (VTK_WRAP_TCL)
409

410
#-----------------------------------------------------------------------------
barre's avatar
barre committed
411
412
413
# Generate the default setup paths scripts.
# Generate some useful scripts that can be used to setup various environment 
# variables and launch the executable properly against external packages.
414
#
415
416
417
418
419
IF (Slicer3_USE_KWWIDGETS)
  include("${KWWidgets_CMAKE_DIR}/KWWidgetsPathsMacros.cmake")
  set(extra_dirs
    "${Teem_DIR}/bin"
    "${BatchMake_DIR}/bin"
420
    "${OpenIGTLink_DIR}/bin"
421
422
423
424
425
426
427
428
    "${Slicer3_HOME}/${Slicer3_INSTALL_PLUGINS_BIN_DIR}"
    "${Slicer3_HOME}/${Slicer3_INSTALL_PLUGINS_LIB_DIR}"
    "${Slicer3_HOME}/${Slicer3_INSTALL_MODULES_BIN_DIR}"
    "${Slicer3_HOME}/${Slicer3_INSTALL_MODULES_LIB_DIR}"
    )
  kwwidgets_generate_setup_paths_scripts(
    "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" "Slicer3SetupPaths"
    "${extra_dirs}"
429
  )
430
ENDIF (Slicer3_USE_KWWIDGETS)
barre's avatar
barre committed
431

432
#-----------------------------------------------------------------------------
barre's avatar
barre committed
433
434
435
436
437
# VTK 5.0 does not have VTK_CMAKE_DIR
# Alternatively you could use KWWidget's wrapping, which encapsulate
# the differences between various VTK versions:
#  INCLUDE("${KWWidgets_CMAKE_DIR}/KWWidgetsWrappingMacros.cmake")
#  KWWidgets_WRAP_TCL(${LIB_NAME} LIB_TCL_SRCS "${LIB_SRCS}" "")
438
#
439
440
441
442
443
444
IF (Slicer3_USE_KWWIDGETS)
  if(NOT VTK_CMAKE_DIR)
    set(VTK_CMAKE_DIR "${VTK_SOURCE_DIR}/CMake")
  endif(NOT VTK_CMAKE_DIR)
  include("${VTK_CMAKE_DIR}/vtkWrapTcl.cmake")
ENDIF (Slicer3_USE_KWWIDGETS)
445

446
447
#-----------------------------------------------------------------------------
# Check versions of VTK to track CVS HEAD
448
#
449
450
451
452
453
454
455
456
457
458
459
460
461
462
IF (Slicer3_USE_KWWIDGETS)
  find_package(VTK REQUIRED)
  if(EXISTS ${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
    include(${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
  else(EXISTS ${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
    #MESSAGE("Using local version of VTKVersionMacros for compatibility.")
    include(${Slicer3_SOURCE_DIR}/Scripts/VTKVersionMacros.cmake)
  endif(EXISTS ${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)

  vtk_get_source_revision_and_date(VTKsource_revision VTKsource_date)
  if(VTKsource_revision LESS 1.2196)
    message(FATAL_ERROR "Sorry, your VTK library was last updated on ${VTKsource_date}. Its source revision, according to vtkKWWidgetsVersion.h, is ${VTKsource_revision}. Please update to a newer revision.")
  endif(VTKsource_revision LESS 1.2196)
ENDIF (Slicer3_USE_KWWIDGETS)
463

464
465
#-----------------------------------------------------------------------------
# These packages may exist within the Slicer3 source tree
lorensen's avatar
lorensen committed
466
#
467
468
469
set(TCLAP_DIR ${Slicer3_BINARY_DIR}/Libs/SlicerExecutionModel/tclap)
set(ModuleDescriptionParser_DIR ${Slicer3_BINARY_DIR}/Libs/SlicerExecutionModel/ModuleDescriptionParser)
set(GenerateCLP_DIR ${Slicer3_BINARY_DIR}/Libs/SlicerExecutionModel/GenerateCLP)
470
471
472
set(GenerateLM_DIR ${Slicer3_BINARY_DIR}/Libs/GenerateLM)
set(LoadableModule_DIR ${Slicer3_BINARY_DIR}/Libs/LoadableModule)
set(vtkITK_DIR ${Slicer3_BINARY_DIR}/Libs/vtkITK)
473

jcfr's avatar
jcfr committed
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#-----------------------------------------------------------------------------
# Qt Loadable Modules
#
IF(Slicer3_USE_QT)
  OPTION(Slicer3_BUILD_QTLOADABLEMODULES "Build Slicer3 QT Loadable Modules" ON)
  IF(Slicer3_BUILD_QTLOADABLEMODULES)
    ADD_DEFINITIONS(-DSlicer3_BUILD_QTLOADABLEMODULES)
    set(Slicer3_INSTALL_QTLOADABLEMODULES_BIN_DIR "${Slicer3_INSTALL_LIB_DIR}/QTLoadableModules")
    set(Slicer3_INSTALL_QTLOADABLEMODULES_LIB_DIR "${Slicer3_INSTALL_LIB_DIR}/QTLoadableModules")
    set(Slicer3_INSTALL_QTLOADABLEMODULES_INCLUDE_DIR "${Slicer3_INSTALL_INCLUDE_DIR}/QTLoadableModules")
    set(Slicer3_INSTALL_QTLOADABLEMODULES_SHARE_DIR "${Slicer3_INSTALL_SHARE_DIR}/QTLoadableModules")
  ENDIF(Slicer3_BUILD_QTLOADABLEMODULES)
ENDIF(Slicer3_USE_QT)

488
489
490
# --------------------------------------------------------------------------
# Configure and install headers

491
CONFIGURE_FILE(
492
493
494
495
  ${CMAKE_CURRENT_SOURCE_DIR}/vtkSlicerConfigure.h.in 
  ${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h
  )

496
497
498
499
500
501
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/vtkSlicerVersionConfigure.h.in 
  ${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerVersionConfigure.h
  )

CONFIGURE_FILE(
502
503
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runValgrind.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runValgrind.sh
504
505
  )

506
507
508
509
510
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runValgrindForOneModule.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runValgrindForOneModule.sh
  )

511
CONFIGURE_FILE(
512
513
514
515
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/computeCodeCoverageLocally.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/computeCodeCoverageLocally.sh
  )

516
517
518
519
520
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/computeCodeCoverageForOneTest.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/computeCodeCoverageForOneTest.sh
  )

521
CONFIGURE_FILE(
522
523
524
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runExperimentalOffScreen.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runExperimentalOffScreen.sh
  )
525

526
527
528
529
530
531
INCLUDE_DIRECTORIES(
  "${CMAKE_CURRENT_SOURCE_DIR}"
  "${CMAKE_CURRENT_BINARY_DIR}"
  )

INSTALL(FILES 
532
533
534
535
  "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h"
  DESTINATION ${Slicer3_INSTALL_INCLUDE_DIR} COMPONENT Development
  )

536
537
538
539
540
INSTALL(FILES 
  "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerVersionConfigure.h"
  DESTINATION ${Slicer3_INSTALL_INCLUDE_DIR} COMPONENT Development
  )

541
542
543
544
545
546
547
548
#-----------------------------------------------------------------------------
# Generate Slicer3Version.txt

INCLUDE(${Slicer3_CMAKE_DIR}/Slicer3TodayMacro.cmake)

# Get build time
TODAY(Slicer3_BUILDDATE)

549
# Note that Slicer_BUILD is set above
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581

SET(Slicer3_WC_URL NA)
SET(Slicer3_WC_REVISION 0)

# Get SVN info
FIND_PACKAGE(Subversion)
IF(NOT Subversion_FOUND)
  MESSAGE(FATAL_ERROR "error: Install SVN and try to re-configure")
ENDIF(NOT Subversion_FOUND)

# Case where Slicer is checkout using SVN
IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.svn)
  Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} Slicer3)
  CONFIGURE_FILE(
    ${CMAKE_CURRENT_SOURCE_DIR}/Slicer3Version.txt.in 
    ${Slicer3_HOME}/lib/Slicer3/Slicer3Version.txt
    )
ENDIF()

# Case where Slicer is checkout using Git-SVN
IF (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
  FIND_PACKAGE(Git)
  IF(NOT Git_FOUND)
    MESSAGE(FATAL_ERROR "error: Failed to locate Git")
  ENDIF(NOT Git_FOUND)
  Git_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} Slicer3)
  CONFIGURE_FILE(
    ${CMAKE_CURRENT_SOURCE_DIR}/Slicer3Version.txt.in
    ${Slicer3_HOME}/lib/Slicer3/Slicer3Version.txt
    )
ENDIF()

582

583
#-----------------------------------------------------------------------------
pieper's avatar
pieper committed
584
585
# Subdirectories
#
586
587
add_subdirectory(Libs)
add_subdirectory(Base)
588
add_subdirectory(Resources)
589

590
#-----------------------------------------------------------------------------
591
# At this point, let's not have the applications and modules guess which
592
593
# include paths or libraries they need, but use Slicer3_*_LIBRARIES and
# Slicer3_*_INCLUDE_DIRS instead. As far as modules are concerned, both
594
595
596
597
598
# variables are actually set automatically by the import script when building
# against a Slicer3 build or installed tree. When in-source, we need to
# set both variables now. Retrieve them from the persistent property cache
# since they were collected in each subdir (which makes it impossible to
# use normal variables, since a new scope is created in each subdir).
599
600
601
#
slicer3_get_persistent_property(Slicer3_Libs_LIBRARIES Slicer3_Libs_LIBRARIES)
slicer3_get_persistent_property(Slicer3_Base_LIBRARIES Slicer3_Base_LIBRARIES)
602

603
604
slicer3_get_persistent_property(Slicer3_Libs_INCLUDE_DIRS Slicer3_Libs_INCLUDE_DIRS)
slicer3_get_persistent_property(Slicer3_Base_INCLUDE_DIRS Slicer3_Base_INCLUDE_DIRS)
pieper's avatar
pieper committed
605

606
607
608
609
610
#-----------------------------------------------------------------------------
# Module Logic

INCLUDE("${Slicer3_CMAKE_DIR}/Slicer3ModuleLogicMacros.cmake")

611
612
613
614
615
616
617
618
619
IF (NOT Slicer3_USE_KWWIDGETS)
  # Loop through Modules subdirectory and try to include Logic subdirectory if it exists
  FILE(GLOB modules_subdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} Modules/*)
  FOREACH(subdir ${modules_subdirs})
    IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/Logic)
      ADD_SUBDIRECTORY(${subdir}/Logic)
    ENDIF()
  ENDFOREACH()
ENDIF()
620
621


622
623
624
625
#-----------------------------------------------------------------------------
# Modules and CLI
#
option(Slicer3_BUILD_CLI "Build Slicer3 CLI Plugins" ON)
626
627
628
IF (Slicer3_USE_KWWIDGETS)
  option(Slicer3_BUILD_MODULES "Build Slicer3 Modules" ON)
ENDIF (Slicer3_USE_KWWIDGETS)
629

barre's avatar
barre committed
630
include("${Slicer3_CMAKE_DIR}/Slicer3PluginsMacros.cmake")
pieper's avatar
pieper committed
631

632
633
634
635
636
637
638
639
640
641
642
643
644
IF (Slicer3_USE_KWWIDGETS)
  include("${Slicer3_CMAKE_DIR}/Slicer3ModulesMacros.cmake")
  
  if(Slicer3_BUILD_MODULES)
    add_subdirectory(Modules)
  else(Slicer3_BUILD_MODULES)
    # if Slicer3_BUILD_CLI is ON, we still need at least the CommandLineModule
    # so that we can have CLI, without all the other modules
    if(Slicer3_BUILD_CLI)
      add_subdirectory(Modules/CommandLineModule)
    endif(Slicer3_BUILD_CLI)
  endif(Slicer3_BUILD_MODULES)
ENDIF (Slicer3_USE_KWWIDGETS)
645
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
646
# Qt Loadable Modules
647
#
jcfr's avatar
jcfr committed
648
649
650
IF(Slicer3_USE_QT AND Slicer3_BUILD_QTLOADABLEMODULES)
  add_subdirectory(QTModules)
ENDIF(Slicer3_USE_QT AND Slicer3_BUILD_QTLOADABLEMODULES)
651

652
653
654
655
#-----------------------------------------------------------------------------
# Applications need to be built after Modules to capture the TractTracing in
# the correct ordering.
#
656
add_subdirectory(Applications)
657

658
659
660
#-----------------------------------------------------------------------------
# Testing
#
661
662
663
if(Slicer3_BUILD_TESTING)
  add_subdirectory(Testing)
endif(Slicer3_BUILD_TESTING)
pieper's avatar
pieper committed
664

665
# Install testing data
andy's avatar
andy committed
666

667
668
669
670
671
672
673
674
install(DIRECTORY
  Testing
  DESTINATION ${Slicer3_INSTALL_SHARE_DIR} COMPONENT Development
  PATTERN ".svn" EXCLUDE
  PATTERN "CMakeLists.txt" EXCLUDE
  )

#-----------------------------------------------------------------------------
675
# Launcher for slicer
676
#
677

678
679
# let's build the launcher for Kww, KwwAndQt and also QtOnly slicer ...
ADD_SUBDIRECTORY(Utilities/Launcher)
680

681
682
683
684
685
# Compute Slicer3_QT_PLUGIN_PATH used to configure launch.tcl.in
SET(Slicer3_QT_PLUGIN_PATH "")
IF(Slicer3_USE_QT)
  SET(designer_launcher_project_name SlicerQT)
  GET_TARGET_PROPERTY(output_directory ${designer_launcher_project_name} LIBRARY_OUTPUT_DIRECTORY)
686
  SET(Slicer3_QT_PLUGIN_PATH ${output_directory})
687
688
ENDIF(Slicer3_USE_QT)

689
690
691
692
693
694
695
696
CONFIGURE_FILE(
  ${Slicer3_SOURCE_DIR}/launch.tcl.in
  "${Slicer3_BINARY_DIR}/${Slicer3_INSTALL_LIB_DIR}/launch.tcl"
  )
INSTALL(
  FILES "${Slicer3_BINARY_DIR}/${Slicer3_INSTALL_LIB_DIR}/launch.tcl"
  DESTINATION ${Slicer3_INSTALL_LIB_DIR}
  )
697

698
699
700
701
702
703
704
705
#-----------------------------------------------------------------------------
# Launcher for QTDesigner
#

IF (Slicer3_USE_QT)
  add_subdirectory(Utilities/Designer)
ENDIF (Slicer3_USE_QT)

706
#-----------------------------------------------------------------------------
707
# Package slicer
708
#
709
add_subdirectory(Utilities/Package)
andy's avatar
andy committed
710

711
#-----------------------------------------------------------------------------
712
# Documentation
713
#
714
715
716
717
option(BUILD_DOCUMENTATION "Build Slicer3 Documentation" OFF)
if(BUILD_DOCUMENTATION)
  add_subdirectory(Utilities/Doxygen)
endif(BUILD_DOCUMENTATION)
andy's avatar
andy committed
718

719
720
721
722
723
724
725
#-----------------------------------------------------------------------------
# Setup file for setting custom ctest vars
CONFIGURE_FILE(
  ${Slicer3_SOURCE_DIR}/CTestCustom.cmake.in
  ${Slicer3_BINARY_DIR}/CTestCustom.cmake
  @ONLY
  )
726

727

728
#-----------------------------------------------------------------------------
729
730
# Set up for building against a Slicer3 build tree and a Slicer3 installation 
#
731
732
include(${Slicer3_SOURCE_DIR}/GenerateSlicer3Config.cmake)

733
734
735
configure_file(${Slicer3_SOURCE_DIR}/CTestConfig.cmake
  ${Slicer3_BINARY_DIR}/${Slicer3_INSTALL_LIB_DIR}/CTestConfig.cmake COPYONLY IMMEDIATE)

736
737
738
configure_file(${Slicer3_SOURCE_DIR}/UseSlicer3.cmake.in
  ${Slicer3_BINARY_DIR}/UseSlicer3.cmake COPYONLY IMMEDIATE)

739
740
741
742
743
configure_file(${Slicer3_SOURCE_DIR}/CMake/RemoveTemporaryFiles.cmake.in
  ${Slicer3_BINARY_DIR}/CMake/RemoveTemporaryFiles.cmake @ONLY IMMEDIATE)
configure_file(${Slicer3_SOURCE_DIR}/CMake/Slicer3SampleBuildTest.cmake.in
  ${Slicer3_BINARY_DIR}/CMake/Slicer3SampleBuildTest.cmake @ONLY)

744
745
install(FILES
  #   ${Slicer3_BINARY_DIR}/Slicer3BuildSettings.cmake
746
  ${Slicer3_SOURCE_DIR}/CTestConfig.cmake
747
748
  ${Slicer3_BINARY_DIR}/UseSlicer3.cmake
  ${Slicer3_BINARY_DIR}/Utilities/Slicer3Config.cmake
hayes's avatar
hayes committed
749
  ${Slicer3_BINARY_DIR}/lib/Slicer3/Slicer3Version.txt
750
  DESTINATION ${Slicer3_INSTALL_LIB_DIR}
751
752
  COMPONENT Development
  )