CMakeLists.txt 32.2 KB
Newer Older
1
2
3
4
#-----------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8.2)
#-----------------------------------------------------------------------------

5
PROJECT(Slicer)
6

7
8
9
10
11
#-----------------------------------------------------------------------------
# See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details
#-----------------------------------------------------------------------------

SET(project_policies
12
  CMP0001 # NEW: CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.
13
  CMP0002 # NEW: Logical target names must be globally unique.
14
  CMP0003 # NEW: Libraries linked via full path no longer produce linker search paths.
15
16
17
18
19
20
  CMP0004 # NEW: Libraries linked may NOT have leading or trailing whitespace.
  CMP0005 # NEW: Preprocessor definition values are now escaped automatically.
  CMP0006 # NEW: Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.
  CMP0007 # NEW: List command no longer ignores empty elements.
  CMP0008 # NEW: Libraries linked by full-path must have a valid library file name.
  CMP0009 # NEW: FILE GLOB_RECURSE calls should not follow symlinks by default.
jcfr's avatar
jcfr committed
21
  CMP0010 # NEW: Bad variable reference syntax is an error.
22
  CMP0011 # NEW: Included scripts do automatic cmake_policy PUSH and POP.
23
  CMP0012 # NEW: if() recognizes numbers and boolean constants.
jcfr's avatar
jcfr committed
24
  CMP0013 # NEW: Duplicate binary directories are not allowed.
25
  CMP0014 # NEW: Input directories must have CMakeLists.txt
26
27
28
29
30
31
  )
FOREACH(policy ${project_policies})
  IF(POLICY ${policy})
    CMAKE_POLICY(SET ${policy} NEW)
  ENDIF()
ENDFOREACH()
32

jcfr's avatar
jcfr committed
33
34
35
36
37
38
#-----------------------------------------------------------------------------
# Output directories.
#
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Slicer_BINARY_DIR}/bin)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Slicer_BINARY_DIR}/bin)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Slicer_BINARY_DIR}/lib)
39

40
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
41
# Install directories
42
#
43
44
set(Slicer_INSTALL_BIN_DIR "bin")
set(Slicer_INSTALL_LIB_DIR "lib/Slicer3")
45
46
set(Slicer_INSTALL_INCLUDE_DIR "include/Slicer")
set(Slicer_INSTALL_SHARE_DIR "share/Slicer")
47
48
49
50
51
52
53
54
55
56
57
58
set(Slicer_INSTALL_ITKFACTORIES_DIR "${Slicer_INSTALL_LIB_DIR}/ITKFactories")

set(Slicer_INSTALL_PLUGINS_BIN_DIR "${Slicer_INSTALL_LIB_DIR}/Plugins")
set(Slicer_INSTALL_PLUGINS_LIB_DIR "${Slicer_INSTALL_LIB_DIR}/Plugins")
set(Slicer_INSTALL_PLUGINS_INCLUDE_DIR "${Slicer_INSTALL_INCLUDE_DIR}/Plugins")
set(Slicer_INSTALL_PLUGINS_SHARE_DIR "${Slicer_INSTALL_SHARE_DIR}/Plugins")
set(Slicer_INSTALL_PLUGINS_CACHE_DIR "${Slicer_INSTALL_LIB_DIR}/PluginsCache")

set(Slicer_INSTALL_MODULES_BIN_DIR "${Slicer_INSTALL_LIB_DIR}/Modules")
set(Slicer_INSTALL_MODULES_LIB_DIR "${Slicer_INSTALL_LIB_DIR}/Modules")
set(Slicer_INSTALL_MODULES_INCLUDE_DIR "${Slicer_INSTALL_INCLUDE_DIR}/Modules")
set(Slicer_INSTALL_MODULES_SHARE_DIR "${Slicer_INSTALL_SHARE_DIR}/Modules")
59

60
set(Slicer_HOME "${Slicer_BINARY_DIR}")
61

62
63
64
65
#-----------------------------------------------------------------------------
# Convenient macro allowing to download a file
#
MACRO(downloadFile url dest)
66
67
68
69
70
71
72
  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()
73
74
  ELSE()
    # Make sure the file is not empty
75
76
77
    FILE(READ ${dest} dest_content LIMIT 4)
    STRING(LENGTH "${dest_content}" dest_length)
    IF(NOT "${dest_length}" EQUAL 4)
78
79
80
      FILE(REMOVE ${dest})
      downloadFile(${url} ${dest})
    ENDIF()
81
82
83
  ENDIF()
ENDMACRO()

84
#-----------------------------------------------------------------------------
85
86
# Disable the warnings that DevStudio 2005 emits wrt to sprintf, strcpu, etc.
#
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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
          )
106
107
108
109
      ENDIF()
    ENDIF()
  ENDIF()
ENDIF()
110

111
112
# Disable warning C4996: [...] This function or variable may be unsafe. [...]
# To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details
113
IF(MSVC90)
114
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
115
ENDIF()
116

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

119
120
121
122
include(${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
test_big_endian(CMAKE_WORDS_BIGENDIAN)

#-----------------------------------------------------------------------------
123
124
125
126
# avoid linker bug in Mac OS 10.5
# see:
# http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
#
127
IF(APPLE)
128
129
  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")
130
ENDIF()
131

132
133
#-----------------------------------------------------------------------------
# Slicer version number.
134
#
135
136
set(Slicer_VERSION_MAJOR "4")
set(Slicer_VERSION_MINOR "0")
137
IF(NOT Slicer_VERSION_PATCH)
138
  set(Slicer_VERSION_PATCH "alpha")
139
ENDIF()
140
141
set(Slicer_VERSION "${Slicer_VERSION_MAJOR}.${Slicer_VERSION_MINOR}")
set(Slicer_VERSION_FULL "${Slicer_VERSION}.${Slicer_VERSION_PATCH}")
142

143
144
#-----------------------------------------------------------------------------
# Build shared lib by default
145
#
146
option(BUILD_SHARED_LIBS "Build Slicer with shared libraries." ON)
147

148
149
150
#-----------------------------------------------------------------------------
# Append the library version information to the library target properties.
#
151
152
OPTION(Slicer_WITH_LIBRARY_VERSION "Build with library version information" OFF)
IF(Slicer_WITH_LIBRARY_VERSION)
153
  SET(Slicer_LIBRARY_PROPERTIES ${Slicer_LIBRARY_PROPERTIES}
154
155
    VERSION ${Slicer_VERSION_FULL}
    SOVERSION ${Slicer_VERSION}
156
  )
157
ENDIF()
158

159
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
160
# Update CMake module path
pieper's avatar
pieper committed
161
#
jcfr's avatar
jcfr committed
162

163
164
# Make sure VTK_CMAKE_DIR is at the beginning so that VTK's FindTCL is
# used before CMake's FindTCL.
165
set(CMAKE_MODULE_PATH
jcfr's avatar
jcfr committed
166
167
  ${VTK_CMAKE_DIR}
  ${Slicer_SOURCE_DIR}/CMake
168
  ${Slicer_BINARY_DIR}/CMake
169
170
  ${CMAKE_MODULE_PATH}
  )
jcfr's avatar
jcfr committed
171
172
  
set(Slicer_CMAKE_DIR "${Slicer_SOURCE_DIR}/CMake" CACHE INTERNAL "")
pieper's avatar
pieper committed
173

jcfr's avatar
jcfr committed
174
175
176
177
178
179
#-----------------------------------------------------------------------------
# CMake Function(s) and Macro(s)
#
include(CMake/Slicer3PersistenceMacros.cmake)
include(CMake/SlicerParseArgumentsMacro.cmake)
include(CMake/SlicerFindQT.cmake)
180

jcfr's avatar
jcfr committed
181
182
# Add CMake directory so that install rules associated with *.cmake files are evaluated
add_subdirectory(CMake)
183

184
#-----------------------------------------------------------------------------
185
# Top level slicer configurations
186
187
188

# Do NOT force into the cache, as plugins need to override locally and scoping
# becomes an issue.
189
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/ 
190
#  CACHE PATH "Single output directory for building all libraries." FORCE)
191
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/ 
192
193
194
195
#  CACHE PATH "Single output directory for building all executables." FORCE)

#-----------------------------------------------------------------------------
# Slicer include and libraries subdirectory
196
#
197
198
slicer3_set_persistent_property(Slicer_Libs_LIBRARIES "")
slicer3_set_persistent_property(Slicer_Base_LIBRARIES "")
199
200
slicer3_set_persistent_property(Slicer_Modules_LIBRARIES "")
slicer3_set_persistent_property(Slicer_QTModules_LIBRARIES "")
201

202
203
slicer3_set_persistent_property(Slicer_Libs_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer_Base_INCLUDE_DIRS "")
204
205
slicer3_set_persistent_property(Slicer_Modules_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer_QTModules_INCLUDE_DIRS "")
pieper's avatar
pieper committed
206

207
208
209
#-----------------------------------------------------------------------------
# Get sytem name and architecture
#
210
SET(Slicer_BUILD NA)
jcfr's avatar
jcfr committed
211
INCLUDE(CMake/DiscoverSystemNameAndBits.cmake)
212
MESSAGE(STATUS "Slicer_BUILD:${Slicer_BUILD}")
213

214
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
215
# Testing
216
#
217
OPTION(BUILD_TESTING "Test the project" ON)
218
SET(LAUNCH_EXE ${Slicer_BINARY_DIR}/Slicer3 --launch)
jcfr's avatar
jcfr committed
219
IF(BUILD_TESTING)
220
221
222
223
  ENABLE_TESTING()
  INCLUDE(CTest)
  SET(CXX_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  MARK_AS_ADVANCED(TCL_TCLSH DART_ROOT)
224

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

230
ENDIF()
hliu's avatar
hliu committed
231

232
#-----------------------------------------------------------------------------
233
# By default, build without KWWidget (TODO: eliminate this option for slicer4)
234
#
235
236
option(Slicer_USE_KWWIDGETS "Deprecated - Build Slicer with KWWidgets" OFF)
MARK_AS_ADVANCED(Slicer_USE_KWWIDGETS)
237
238
239

#-----------------------------------------------------------------------------
# Since modules are KWWidgets based, unset there variables
240
IF(NOT Slicer_USE_KWWIDGETS)
241
  # Since the module Logic is shared between QTModules and regular Modules,
242
  # the associated BIN, LIB and INCLUDE directory shouldn't be unset
243
244
245
246
  #UNSET(Slicer_INSTALL_MODULES_BIN_DIR)
  #UNSET(Slicer_INSTALL_MODULES_LIB_DIR)
  #UNSET(Slicer_INSTALL_MODULES_INCLUDE_DIR)
  UNSET(Slicer_INSTALL_MODULES_SHARE_DIR)
247
ENDIF()
248

249
#-----------------------------------------------------------------------------
250
251
252
253
254
# Libs
# - ITK
# - KWWidgets (pulls in VTK)
#

255
256
257
258
# 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.

259
IF(Slicer_USE_KWWIDGETS)
260
  set(SKIP_KWWidgets_BUILD_SETTINGS_FILE 1)
261
ENDIF()
262
263
set(SKIP_VTK_BUILD_SETTINGS_FILE 1)
set(SKIP_ITK_BUILD_SETTINGS_FILE 1)
264
set(SKIP_Teem_BUILD_SETTINGS_FILE 1)
265
266

#-----------------------------------------------------------------------------
267
## Python
268
269
option(Slicer_USE_PYTHON "Integrate a python interpreter into Slicer." OFF)
IF(Slicer_USE_PYTHON OR Slicer_USE_PYTHONQT)
270
  find_package(PythonLibs)
271
  find_package(PythonInterp)
272
ENDIF()
273

274
#-----------------------------------------------------------------------------
275
## ITK
276
find_package(ITK REQUIRED)
277
IF(NOT ITK_FOUND)
278
  message(FATAL_ERROR "Need ITK to build")
279
ENDIF()
280
include(${ITK_USE_FILE})
281

282
283
284
#-----------------------------------------------------------------------------
# FindCTK
#
285
SET(git_repo http://github.com/commontk/CTK/raw/master/)
286

287
IF(Slicer_USE_QT)
288
  SET(file Utilities/CMake/FindCTK.cmake)
289
  downloadFile(${git_repo}/${file} ${Slicer_BINARY_DIR}/CMake/FindCTK.cmake)
290
291
292
293

  FIND_PACKAGE(CTK REQUIRED)
  IF(CTK_FOUND)
    INCLUDE(${CTK_USE_FILE})
294
295
    # Update CMake module path
    SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CTK_CMAKE_UTILITIES_DIR})
296
    IF(Slicer_USE_PYTHONQT)
297
      SET(PYTHONQT_INSTALL_DIR ${CTK_PYTHONQT_INSTALL_DIR})
298
      LINK_DIRECTORIES(${PYTHONQT_INSTALL_DIR}/lib)
299
300
      INCLUDE(${CTK_CMAKE_DIR}/ctkMacroWrapPythonQt.cmake)
    ENDIF()
301
302
303
  ENDIF()
ENDIF()

304
#-----------------------------------------------------------------------------
305
IF(Slicer_USE_KWWIDGETS)
306
307
308
309
  ## KWWidgets
  FIND_PACKAGE(KWWidgets REQUIRED)
  IF(NOT KWWidgets_FOUND)
    MESSAGE(FATAL_ERROR "Need KWWidgets to build")
310
  ENDIF()
311
  INCLUDE(${KWWidgets_USE_FILE})
312
  
313
ELSE()
314
315

  # VTK
316
317
  FIND_PACKAGE(VTK REQUIRED)
  IF(NOT VTK_FOUND)
318
    MESSAGE(FATAL_ERROR "Need VTK to build")
319
  ELSE()
320
321
    IF(NOT VTK_USE_QVTK)
      MESSAGE("Please make sure VTK is build with VTK_USE_GUISUPPORT and VTK_USE_QVTK enabled")
322
323
    ENDIF()
  ENDIF()
324
  INCLUDE(${VTK_USE_FILE})
325
  
326
ENDIF()
327
328

#-----------------------------------------------------------------------------
329
#
330
# Call macro defined in ${PROJECT_SOURCE_DIR}/CMake/SlicerFindQT.cmake
331
#
332
SLICER_SETUP_QT()
333

334
#-----------------------------------------------------------------------------
335
336
337
# Alert the user if both Slicer_USE_QT and Slicer_USE_KWWIDGETS are OFF
IF(NOT Slicer_USE_QT AND NOT Slicer_USE_KWWIDGETS)
  MESSAGE(FATAL_ERROR "Both Slicer_USE_QT and Slicer_USE_KWWIDGETS are OFF. Please, choose one")
338
ENDIF()
339
340

#-----------------------------------------------------------------------------
341
# If Slicer_USE_QT is ON and Slicer_USE_KWWIDGETS is OFF, complain if VTK_WRAP_TCL is ON
342
# Note: Later on we will expect VTK_WRAP_PYTHON to be ON
343
IF(Slicer_USE_QT AND NOT Slicer_USE_KWWIDGETS)
344
  IF(VTK_WRAP_TCL)
345
    MESSAGE(FATAL_ERROR "For now, if Slicer_USE_QT is ON and Slicer_USE_KWWIDGETS is OFF, we expect VTK_WRAP_TCL to be OFF")
346
347
  ENDIF()
ENDIF()
348

349
#-----------------------------------------------------------------------------
350
# Add Slicer_USE_PYTHONQT option if Slicer_USE_QT is ON
351
IF(Slicer_USE_QT)
352
353
  option(Slicer_USE_PYTHONQT "Integrate a python-QT interpreter into Slicer." OFF)
  IF(Slicer_USE_PYTHONQT)
354
    IF(NOT VTK_WRAP_PYTHON)
355
      MESSAGE(FATAL_ERROR "Since both Slicer_USE_QT and Slicer_USE_PYTHONQT are ON, VTK_WRAP_PYTHON is expected to be ON. Disable Slicer_USE_PYTHONQT or re-configure VTK with python wrapping.")
356
    ENDIF()
357
    # Include convenient script allowing to copy and compile python scripts
358
    INCLUDE(${Slicer_CMAKE_DIR}/SlicerCompilePythonScripts.cmake)
359
    # Enable qMRMLWidgets python wrapping
360
    SET(qMRMLWidgets_WRAP_PYTHON OFF)
361
362
  ENDIF()
ENDIF()
363

364
#-----------------------------------------------------------------------------
365
## Teem
366
find_package(Teem REQUIRED)
367
IF(NOT Teem_FOUND)
368
  message(FATAL_ERROR "Need Teem to build")
369
ENDIF()
370
include(${Teem_USE_FILE})
371

372
#-----------------------------------------------------------------------------
373
374
## SlicerLibCurl
find_package(SLICERLIBCURL REQUIRED)
375
IF(SLICERLIBCURL_FOUND)
376
  include(${SLICERLIBCURL_USE_FILE})
377
ENDIF()
378
379

#-----------------------------------------------------------------------------
380
## BatchMake
381
382
option(Slicer_USE_BatchMake "Build Slicer with BatchMake support." OFF)
IF(Slicer_USE_BatchMake)
383
384
  find_package(BatchMake REQUIRED)
  include(${BatchMake_USE_FILE})
385
ENDIF()
386

387
#-----------------------------------------------------------------------------
388
## MIDAS
389
option(Slicer_USE_MIDAS "Build Slicer with MIDAS support." OFF)
390

391
#-----------------------------------------------------------------------------
392
## OpenIGTLink
393
394
option(Slicer_USE_OPENIGTLINK "Build Slicer with OpenIGTLink support." OFF)
IF(Slicer_USE_OPENIGTLINK)
395
396
  find_package(OpenIGTLink REQUIRED)
  include(${OpenIGTLink_USE_FILE})
397
ENDIF()
hliu's avatar
hliu committed
398

399
400
#-----------------------------------------------------------------------------
## OpenCV (Built in Slicer3-lib)
401
option(Slicer_USE_OPENCV "Build Slicer with OpenCV support." OFF)
402
IF(Slicer_USE_OPENCV)
403
404
405
406
407
  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})
408
  ENDIF()
409
410
411
412
413
414
415
416
417
418
419
420
421
422
  
  # 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})
423
ENDIF()
424
425


426
427
#-----------------------------------------------------------------------------
# Need some Tcl/Tk info
428
IF(VTK_WRAP_TCL)
429
430
431
432
  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}")
433
  IF(Slicer_USE_KWWIDGETS)
434
435
436
437
    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}")
438
439
  ENDIF()
ELSE()
440
441
442
443
444
  # TODO: these should be passed in by SuperBuild
  # For now, use 3.2 as a fallback - we haven't changed versions in years and probably 
  # never will, so this is always likely to work.
  # This is needed so the launcher can set the paths to the correct subdirectories
  # for incrTcl and incrTk
445
446
  set(TCL_TK_VERSION_DOT "8.4")
  set(TCL_TK_VERSION "84")
447
448
  set(INCR_TCL_VERSION_DOT "3.2")
  set(INCR_TCL_VERSION "32")
449
ENDIF()
450

451
#-----------------------------------------------------------------------------
barre's avatar
barre committed
452
453
454
# 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.
455
#
456
IF(Slicer_USE_KWWIDGETS)
457
458
459
460
  include("${KWWidgets_CMAKE_DIR}/KWWidgetsPathsMacros.cmake")
  set(extra_dirs
    "${Teem_DIR}/bin"
    "${BatchMake_DIR}/bin"
461
    "${OpenIGTLink_DIR}/bin"
462
463
464
465
    "${Slicer_HOME}/${Slicer_INSTALL_PLUGINS_BIN_DIR}"
    "${Slicer_HOME}/${Slicer_INSTALL_PLUGINS_LIB_DIR}"
    "${Slicer_HOME}/${Slicer_INSTALL_MODULES_BIN_DIR}"
    "${Slicer_HOME}/${Slicer_INSTALL_MODULES_LIB_DIR}"
466
467
468
469
    )
  kwwidgets_generate_setup_paths_scripts(
    "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" "Slicer3SetupPaths"
    "${extra_dirs}"
470
  )
471
ENDIF()
barre's avatar
barre committed
472

473
#-----------------------------------------------------------------------------
barre's avatar
barre committed
474
475
476
477
478
# 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}" "")
479
#
480
IF(Slicer_USE_KWWIDGETS)
481
  IF(NOT VTK_CMAKE_DIR)
482
    set(VTK_CMAKE_DIR "${VTK_SOURCE_DIR}/CMake")
483
  ENDIF()
484
  include("${VTK_CMAKE_DIR}/vtkWrapTcl.cmake")
485
ENDIF()
486

487
488
#-----------------------------------------------------------------------------
# Check versions of VTK to track CVS HEAD
489
#
490
IF(Slicer_USE_KWWIDGETS)
491
  find_package(VTK REQUIRED)
492
  IF(EXISTS ${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
493
    include(${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
494
  else()
495
    #MESSAGE("Using local version of VTKVersionMacros for compatibility.")
496
    include(${Slicer_SOURCE_DIR}/Scripts/VTKVersionMacros.cmake)
497
  ENDIF()
498
499

  vtk_get_source_revision_and_date(VTKsource_revision VTKsource_date)
500
  IF(VTKsource_revision LESS 1.2196)
501
    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.")
502
503
  ENDIF()
ENDIF()
504

505
#-----------------------------------------------------------------------------
506
# These packages may exist within the Slicer source tree
lorensen's avatar
lorensen committed
507
#
508
509
510
511
512
513
set(TCLAP_DIR ${Slicer_BINARY_DIR}/Libs/SlicerExecutionModel/tclap)
set(ModuleDescriptionParser_DIR ${Slicer_BINARY_DIR}/Libs/SlicerExecutionModel/ModuleDescriptionParser)
set(GenerateCLP_DIR ${Slicer_BINARY_DIR}/Libs/SlicerExecutionModel/GenerateCLP)
set(GenerateLM_DIR ${Slicer_BINARY_DIR}/Libs/GenerateLM)
set(LoadableModule_DIR ${Slicer_BINARY_DIR}/Libs/LoadableModule)
set(vtkITK_DIR ${Slicer_BINARY_DIR}/Libs/vtkITK)
514

jcfr's avatar
jcfr committed
515
516
517
#-----------------------------------------------------------------------------
# Qt Loadable Modules
#
518
IF(Slicer_USE_QT)
519
  OPTION(Slicer_BUILD_QTLOADABLEMODULES "Build Slicer QT Loadable Modules" ON)
520
521
  IF(Slicer_BUILD_QTLOADABLEMODULES)
    ADD_DEFINITIONS(-DSlicer_BUILD_QTLOADABLEMODULES)
522
523
524
525
    set(Slicer_INSTALL_QTLOADABLEMODULES_BIN_DIR "${Slicer_INSTALL_LIB_DIR}/QTLoadableModules")
    set(Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR "${Slicer_INSTALL_LIB_DIR}/QTLoadableModules")
    set(Slicer_INSTALL_QTLOADABLEMODULES_INCLUDE_DIR "${Slicer_INSTALL_INCLUDE_DIR}/QTLoadableModules")
    set(Slicer_INSTALL_QTLOADABLEMODULES_SHARE_DIR "${Slicer_INSTALL_SHARE_DIR}/QTLoadableModules")
526
527
  ENDIF()
ENDIF()
jcfr's avatar
jcfr committed
528

529
530
531
# --------------------------------------------------------------------------
# Configure and install headers

532
CONFIGURE_FILE(
533
534
535
536
  ${CMAKE_CURRENT_SOURCE_DIR}/vtkSlicerConfigure.h.in 
  ${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h
  )

537
538
539
540
541
542
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/vtkSlicerVersionConfigure.h.in 
  ${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerVersionConfigure.h
  )

CONFIGURE_FILE(
543
544
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runValgrind.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runValgrind.sh
545
546
  )

547
548
549
550
551
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runValgrindForOneModule.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runValgrindForOneModule.sh
  )

552
553
554
555
556
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runValgrindForOneModuleWithSlicer4AndQT.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runValgrindForOneModuleWithSlicer4AndQT.sh
  )

557
CONFIGURE_FILE(
558
559
560
561
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/computeCodeCoverageLocally.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/computeCodeCoverageLocally.sh
  )

562
563
564
565
566
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/computeCodeCoverageForOneTest.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/computeCodeCoverageForOneTest.sh
  )

567
CONFIGURE_FILE(
568
569
570
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runExperimentalOffScreen.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runExperimentalOffScreen.sh
  )
571

572
573
574
575
576
577
INCLUDE_DIRECTORIES(
  "${CMAKE_CURRENT_SOURCE_DIR}"
  "${CMAKE_CURRENT_BINARY_DIR}"
  )

INSTALL(FILES 
578
  "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h"
579
  DESTINATION ${Slicer_INSTALL_INCLUDE_DIR} COMPONENT Development
580
581
  )

582
583
INSTALL(FILES 
  "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerVersionConfigure.h"
584
  DESTINATION ${Slicer_INSTALL_INCLUDE_DIR} COMPONENT Development
585
586
  )

587
#-----------------------------------------------------------------------------
588
# Generate SlicerVersion.txt
589

590
INCLUDE(${Slicer_CMAKE_DIR}/SlicerTodayMacro.cmake)
591
592

# Get build time
593
TODAY(Slicer_BUILDDATE)
594

595
# Note that Slicer_BUILD is set above
596

597
598
SET(Slicer_WC_URL NA)
SET(Slicer_WC_REVISION 0)
599
600
601
602
603

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

# Case where Slicer is checkout using SVN
607
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.svn)
608
609
  Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} Slicer3)
  CONFIGURE_FILE(
610
611
    ${CMAKE_CURRENT_SOURCE_DIR}/SlicerVersion.txt.in 
    ${Slicer_HOME}/lib/Slicer3/SlicerVersion.txt
612
613
614
615
    )
ENDIF()

# Case where Slicer is checkout using Git-SVN
616
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
617
  FIND_PACKAGE(Git)
618
  IF(NOT GIT_FOUND)
619
    MESSAGE(FATAL_ERROR "error: Failed to locate Git")
620
621
  ENDIF(NOT GIT_FOUND)
  GIT_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} Slicer3)
622
  CONFIGURE_FILE(
623
624
    ${CMAKE_CURRENT_SOURCE_DIR}/SlicerVersion.txt.in
    ${Slicer_HOME}/lib/Slicer3/SlicerVersion.txt
625
626
627
    )
ENDIF()

628

629
#-----------------------------------------------------------------------------
pieper's avatar
pieper committed
630
631
# Subdirectories
#
632
633
add_subdirectory(Libs)
add_subdirectory(Base)
634
add_subdirectory(Resources)
635

636
#-----------------------------------------------------------------------------
637
# At this point, let's not have the applications and modules guess which
638
# include paths or libraries they need, but use Slicer3_*_LIBRARIES and
639
# Slicer_*_INCLUDE_DIRS instead. As far as modules are concerned, both
640
# variables are actually set automatically by the import script when building
641
# against a Slicer build or installed tree. When in-source, we need to
642
643
644
# 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).
645
#
646
647
slicer3_get_persistent_property(Slicer_Libs_LIBRARIES Slicer_Libs_LIBRARIES)
slicer3_get_persistent_property(Slicer_Base_LIBRARIES Slicer_Base_LIBRARIES)
648

649
650
slicer3_get_persistent_property(Slicer_Libs_INCLUDE_DIRS Slicer_Libs_INCLUDE_DIRS)
slicer3_get_persistent_property(Slicer_Base_INCLUDE_DIRS Slicer_Base_INCLUDE_DIRS)
pieper's avatar
pieper committed
651

652

653
654
#-----------------------------------------------------------------------------
# Module Logic
655
#
656

657
INCLUDE("${Slicer_CMAKE_DIR}/SlicerModuleLogicMacros.cmake")
658

659
IF(NOT Slicer_USE_KWWIDGETS)
660
661
662
  # KWWidgets and Qt modules share the same logics typically located in the
  # kwwdigets modules. When KWWidgets is not build, the logic are missing for Qt
  # we need to manually add them:
663
664
665
666
667
668
  # 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()
669
    FILE(GLOB subsubdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${subdir}/*)
670
    FOREACH(subsubdir ${subsubdirs})
671
672
      IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${subsubdir}/Logic)
        ADD_SUBDIRECTORY(${subsubdir}/Logic)
673
674
      ENDIF()
    ENDFOREACH()
675
676
  ENDFOREACH()
ENDIF()
677
678


679
680
681
#-----------------------------------------------------------------------------
# Modules and CLI
#
682
option(Slicer_BUILD_CLI "Build Slicer CLI Plugins" ON)
683
IF(Slicer_USE_KWWIDGETS)
684
  option(Slicer_BUILD_MODULES "Build Slicer Modules" ON)
685
ENDIF()
686

687
include("${Slicer_CMAKE_DIR}/Slicer3PluginsMacros.cmake")
pieper's avatar
pieper committed
688

689
IF(Slicer_USE_KWWIDGETS)
690
  include("${Slicer_CMAKE_DIR}/Slicer3ModulesMacros.cmake")
691
  
692
  IF(Slicer_BUILD_MODULES)
693
    add_subdirectory(Modules)
694
  else(Slicer_BUILD_MODULES)
695
    # if Slicer_BUILD_CLI is ON, we still need at least the CommandLineModule
696
    # so that we can have CLI, without all the other modules
697
    IF(Slicer_BUILD_CLI)
698
      add_subdirectory(Modules/CommandLineModule)
699
    ENDIF(Slicer_BUILD_CLI)
700
  ENDIF(Slicer_BUILD_MODULES)
701
ENDIF()
702
703
704
705

#-----------------------------------------------------------------------------
# Module EMSegment libraries
# The EMSegment{Registration,Graph,Algorithm,MRML} libraries are built from the top-level
706
# CMakeLists.txt. Doing so allow to build these libraries also if Slicer_USE_KWWIDGETS is OFF
707

708
IF(Slicer_BUILD_MODULES OR Slicer_BUILD_QTLOADABLEMODULES)
709
  include("${Slicer_CMAKE_DIR}/Slicer3ModulesMacros.cmake")
710
711
712
713
  ADD_SUBDIRECTORY(Modules/EMSegment/Algorithm)
  ADD_SUBDIRECTORY(Modules/EMSegment/MRML)
  ADD_SUBDIRECTORY(Modules/EMSegment/Registration)
  ADD_SUBDIRECTORY(Modules/EMSegment/Graph)
714
ENDIF()
715

716
717
718
# Since EMSegment module expects Volume module and its associated library to be
# built beforehand,let's enfore that by building EMSegment here.
# Note that EMSegment has been commented in Modules/CMakeLists.txt
719
IF(Slicer_USE_KWWIDGETS)
720
  IF(Slicer_BUILD_MODULES)
721
    ADD_SUBDIRECTORY(Modules/EMSegment)
722
  ENDIF()
723
724
ENDIF()

725
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
726
# Qt Loadable Modules
727
#
728
IF(Slicer_USE_QT AND Slicer_BUILD_QTLOADABLEMODULES)
jcfr's avatar
jcfr committed
729
  add_subdirectory(QTModules)
730
ENDIF()
731

732
733
734
735
#-----------------------------------------------------------------------------
# Applications need to be built after Modules to capture the TractTracing in
# the correct ordering.
#
736
add_subdirectory(Applications)
737

738
739
740
#-----------------------------------------------------------------------------
# Testing
#
jcfr's avatar
jcfr committed
741
IF(BUILD_TESTING)
742
  add_subdirectory(Testing)
743
ENDIF()
pieper's avatar
pieper committed
744

745
# Install testing data
andy's avatar
andy committed
746

747
748
install(DIRECTORY
  Testing
749
  DESTINATION ${Slicer_INSTALL_SHARE_DIR} COMPONENT Development
750
751
752
753
754
  PATTERN ".svn" EXCLUDE
  PATTERN "CMakeLists.txt" EXCLUDE
  )

#-----------------------------------------------------------------------------
755
# Launcher for slicer
756
#
757

758
759
# let's build the launcher for Kww, KwwAndQt and also QtOnly slicer ...
ADD_SUBDIRECTORY(Utilities/Launcher)
760

761
762
# Compute Slicer_QT_PLUGIN_PATH used to configure launch.tcl.in
SET(Slicer_QT_PLUGIN_PATH "")
763
IF(Slicer_USE_QT)
764
765
  SET(designer_launcher_project_name SlicerQT)
  GET_TARGET_PROPERTY(output_directory ${designer_launcher_project_name} LIBRARY_OUTPUT_DIRECTORY)
766
  SET(Slicer_QT_PLUGIN_PATH ${output_directory})
767
768
769
770
771
772

  # on Mac we need to include the path of each Qt Framework in DYLD_LIBRARY_PATH in the launcher.
  IF(APPLE)
    SET (QTLIBLIST QTCORE QTGUI QTNETWORK QTXML QTTEST QTSQL QTOPENGL QTWEBKIT PHONON QTXMLPATTERNS)

    FOREACH(qtlib ${QTLIBLIST})
773
      IF(QT_${qtlib}_LIBRARY_RELEASE AND APPLE)
774
          GET_FILENAME_COMPONENT(QT_FRAMEWORK_NAME_tmp ${QT_${qtlib}_LIBRARY_RELEASE} NAME)
775
          SET(Slicer_QT_FRAMEWORK_DIRS "lib/Qt/${QT_FRAMEWORK_NAME_tmp}/Versions/4:${Slicer_QT_FRAMEWORK_DIRS}")
776
      ENDIF()
777
778
    ENDFOREACH()
  ENDIF()
779
780
781