CMakeLists.txt 32.1 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
option(Slicer_USE_KWWIDGETS "Build Slicer with KWWidgets." OFF)
236
237
238

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

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

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

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

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

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

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

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

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

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

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

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

333
#-----------------------------------------------------------------------------
334
335
336
# 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")
337
ENDIF()
338
339

#-----------------------------------------------------------------------------
340
# If Slicer_USE_QT is ON and Slicer_USE_KWWIDGETS is OFF, complain if VTK_WRAP_TCL is ON
341
# Note: Later on we will expect VTK_WRAP_PYTHON to be ON
342
IF(Slicer_USE_QT AND NOT Slicer_USE_KWWIDGETS)
343
  IF(VTK_WRAP_TCL)
344
    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")
345
346
  ENDIF()
ENDIF()
347

348
#-----------------------------------------------------------------------------
349
# Add Slicer_USE_PYTHONQT option if Slicer_USE_QT is ON
350
IF(Slicer_USE_QT)
351
352
  option(Slicer_USE_PYTHONQT "Integrate a python-QT interpreter into Slicer." OFF)
  IF(Slicer_USE_PYTHONQT)
353
    IF(NOT VTK_WRAP_PYTHON)
354
      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.")
355
    ENDIF()
356
    # Include convenient script allowing to copy and compile python scripts
357
    INCLUDE(${Slicer_CMAKE_DIR}/SlicerCompilePythonScripts.cmake)
358
    # Enable qMRMLWidgets python wrapping
359
    SET(qMRMLWidgets_WRAP_PYTHON OFF)
360
361
  ENDIF()
ENDIF()
362

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

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

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

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

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

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


425
426
#-----------------------------------------------------------------------------
# Need some Tcl/Tk info
427
IF(VTK_WRAP_TCL)
428
429
430
431
  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}")
432
  IF(Slicer_USE_KWWIDGETS)
433
434
435
436
    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}")
437
438
  ENDIF()
ELSE()
439
440
441
442
443
  # 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
444
445
  set(TCL_TK_VERSION_DOT "8.4")
  set(TCL_TK_VERSION "84")
446
447
  set(INCR_TCL_VERSION_DOT "3.2")
  set(INCR_TCL_VERSION "32")
448
ENDIF()
449

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

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

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

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

504
#-----------------------------------------------------------------------------
505
# These packages may exist within the Slicer source tree
lorensen's avatar
lorensen committed
506
#
507
508
509
510
511
512
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)
513

jcfr's avatar
jcfr committed
514
515
516
#-----------------------------------------------------------------------------
# Qt Loadable Modules
#
517
IF(Slicer_USE_QT)
518
  OPTION(Slicer_BUILD_QTLOADABLEMODULES "Build Slicer QT Loadable Modules" ON)
519
520
  IF(Slicer_BUILD_QTLOADABLEMODULES)
    ADD_DEFINITIONS(-DSlicer_BUILD_QTLOADABLEMODULES)
521
522
523
524
    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")
525
526
  ENDIF()
ENDIF()
jcfr's avatar
jcfr committed
527

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Get build time
592
TODAY(Slicer_BUILDDATE)
593

594
# Note that Slicer_BUILD is set above
595

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

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

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

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

627

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

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

648
649
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
650

651

652
653
#-----------------------------------------------------------------------------
# Module Logic
654
#
655

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

658
IF(NOT Slicer_USE_KWWIDGETS)
659
660
661
  # 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:
662
663
664
665
666
667
  # 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()
668
    FILE(GLOB subsubdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${subdir}/*)
669
    FOREACH(subsubdir ${subsubdirs})
670
671
      IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${subsubdir}/Logic)
        ADD_SUBDIRECTORY(${subsubdir}/Logic)
672
673
      ENDIF()
    ENDFOREACH()
674
675
  ENDFOREACH()
ENDIF()
676
677


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

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

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

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

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

715
716
717
# 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
718
IF(Slicer_USE_KWWIDGETS)
719
  IF(Slicer_BUILD_MODULES)
720
    ADD_SUBDIRECTORY(Modules/EMSegment)
721
  ENDIF()
722
723
ENDIF()

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

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

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

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

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

#-----------------------------------------------------------------------------
754
# Launcher for slicer
755
#
756

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

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

  # 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})
772
      IF(QT_${qtlib}_LIBRARY_RELEASE AND APPLE)
773
          GET_FILENAME_COMPONENT(QT_FRAMEWORK_NAME_tmp ${QT_${qtlib}_LIBRARY_RELEASE} NAME)
774
          SET(Slicer_QT_FRAMEWORK_DIRS "lib/Qt/${QT_FRAMEWORK_NAME_tmp}/Versions/4:${Slicer_QT_FRAMEWORK_DIRS}")
775
      ENDIF()
776
777
    ENDFOREACH()
  ENDIF()
778
779
780
781
782