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
14
15
16
17
18
19
20
  #CMP0002 # NEW: Logical target names must be globally unique.
  CMP0003 # NEW: Libraries linked via full path no longer produce linker search paths.
  #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
23
  #CMP0011 # NEW: Included scripts do automatic cmake_policy PUSH and POP.
  CMP0012 # NEW: if() recognizes numbers and boolean constants.
jcfr's avatar
jcfr committed
24
  CMP0013 # NEW: Duplicate binary directories are not allowed.
25
26
27
28
29
30
31
  #CMP0014 # NEW: Input directories must have CMakeLists.txt
  )
FOREACH(policy ${project_policies})
  IF(POLICY ${policy})
    CMAKE_POLICY(SET ${policy} NEW)
  ENDIF()
ENDFOREACH()
32

33

34
#-----------------------------------------------------------------------------
35
#
36
37
set(Slicer_INSTALL_BIN_DIR "bin")
set(Slicer_INSTALL_LIB_DIR "lib/Slicer3")
38
39
set(Slicer_INSTALL_INCLUDE_DIR "include/Slicer")
set(Slicer_INSTALL_SHARE_DIR "share/Slicer")
40
41
42
43
44
45
46
47
48
49
50
51
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")
52

53
set(Slicer_HOME "${Slicer_BINARY_DIR}")
54

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

77
#-----------------------------------------------------------------------------
78
79
# Disable the warnings that DevStudio 2005 emits wrt to sprintf, strcpu, etc.
#
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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
          )
99
100
101
102
      ENDIF()
    ENDIF()
  ENDIF()
ENDIF()
103

104
105
# Disable warning C4996: [...] This function or variable may be unsafe. [...]
# To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details
106
IF(MSVC90)
107
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
108
ENDIF()
109

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

112
113
114
115
include(${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
test_big_endian(CMAKE_WORDS_BIGENDIAN)

#-----------------------------------------------------------------------------
116
117
118
119
# avoid linker bug in Mac OS 10.5
# see:
# http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
#
120
IF(APPLE)
121
122
  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")
123
ENDIF()
124

125
126
#-----------------------------------------------------------------------------
# Slicer version number.
127
#
128
129
set(Slicer_VERSION_MAJOR "4")
set(Slicer_VERSION_MINOR "0")
130
IF(NOT Slicer_VERSION_PATCH)
131
  set(Slicer_VERSION_PATCH "alpha")
132
ENDIF()
133
134
set(Slicer_VERSION "${Slicer_VERSION_MAJOR}.${Slicer_VERSION_MINOR}")
set(Slicer_VERSION_FULL "${Slicer_VERSION}.${Slicer_VERSION_PATCH}")
135

136
137
#-----------------------------------------------------------------------------
# Build shared lib by default
138
#
139
option(BUILD_SHARED_LIBS "Build Slicer with shared libraries." ON)
140

141
142
143
#-----------------------------------------------------------------------------
# Append the library version information to the library target properties.
#
144
145
OPTION(Slicer_WITH_LIBRARY_VERSION "Build with library version information" OFF)
IF(Slicer_WITH_LIBRARY_VERSION)
146
  SET(Slicer_LIBRARY_PROPERTIES ${Slicer_LIBRARY_PROPERTIES}
147
148
    VERSION ${Slicer_VERSION_FULL}
    SOVERSION ${Slicer_VERSION}
149
  )
150
ENDIF()
151

152
#-----------------------------------------------------------------------------
153
# Slicer macros
pieper's avatar
pieper committed
154
#
155
set(Slicer_CMAKE_DIR "${Slicer_SOURCE_DIR}/CMake" CACHE INTERNAL "")
156
157
158
add_subdirectory(CMake)
# Make sure VTK_CMAKE_DIR is at the beginning so that VTK's FindTCL is
# used before CMake's FindTCL.
159
160
set(CMAKE_MODULE_PATH
  "${VTK_CMAKE_DIR}"
161
  "${Slicer_CMAKE_DIR}"
162
  ${Slicer_BINARY_DIR}/CMake
163
164
  ${CMAKE_MODULE_PATH}
  )
pieper's avatar
pieper committed
165

166
include("${Slicer_CMAKE_DIR}/Slicer3PersistenceMacros.cmake")
hliu's avatar
hliu committed
167

168
# See http://www.cmake.org/Wiki/CMakeMacroParseArguments
169
include("${Slicer_CMAKE_DIR}/SlicerParseArgumentsMacro.cmake")
170

171
## QT
172
INCLUDE(${Slicer_CMAKE_DIR}/SlicerFindQT.cmake)
173

174
#-----------------------------------------------------------------------------
175
# Top level slicer configurations
176
#
177
178
179
180
181
# 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")

182
183
184

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

#-----------------------------------------------------------------------------
# Slicer include and libraries subdirectory
192
#
193
194
slicer3_set_persistent_property(Slicer_Libs_LIBRARIES "")
slicer3_set_persistent_property(Slicer_Base_LIBRARIES "")
195
196
slicer3_set_persistent_property(Slicer_Modules_LIBRARIES "")
slicer3_set_persistent_property(Slicer_QTModules_LIBRARIES "")
197

198
199
slicer3_set_persistent_property(Slicer_Libs_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer_Base_INCLUDE_DIRS "")
200
201
slicer3_set_persistent_property(Slicer_Modules_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer_QTModules_INCLUDE_DIRS "")
pieper's avatar
pieper committed
202

203
204
205
#-----------------------------------------------------------------------------
# Get sytem name and architecture
#
206
SET(Slicer_BUILD NA)
207
INCLUDE(${Slicer_CMAKE_DIR}/DiscoverSystemNameAndBits.cmake)
208
MESSAGE(STATUS "Slicer_BUILD:${Slicer_BUILD}")
209

210
#-----------------------------------------------------------------------------
pieper's avatar
pieper committed
211
# Add the testing directories
212
#
213
OPTION(BUILD_TESTING "Test the project" ON)
214
SET(Slicer_BUILD_TESTING ${BUILD_TESTING})
215
SET(LAUNCH_EXE ${Slicer_BINARY_DIR}/Slicer3 --launch)
216
IF(Slicer_BUILD_TESTING)
217
  #IF(NOT BUILDNAME)
218
  #  SET(BUILDNAME "${Slicer_BUILD}" CACHE STRING "Name of build on the dashboard")
219
220
221
  #ELSE()
  #  SET(BUILDNAME "${BUILDNAME}" CACHE STRING "Name of build on the dashboard")
  #ENDIF()
222
223
224
225
  ENABLE_TESTING()
  INCLUDE(CTest)
  SET(CXX_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  MARK_AS_ADVANCED(TCL_TCLSH DART_ROOT)
226

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

232
ENDIF()
hliu's avatar
hliu committed
233

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Get build time
594
TODAY(Slicer_BUILDDATE)
595

596
# Note that Slicer_BUILD is set above
597

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

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

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

# Case where Slicer is checkout using Git-SVN
617
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
618
619
620
621
622
623
  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(
624
625
    ${CMAKE_CURRENT_SOURCE_DIR}/SlicerVersion.txt.in
    ${Slicer_HOME}/lib/Slicer3/SlicerVersion.txt
626
627
628
    )
ENDIF()

629

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

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

650
651
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
652

653

654
655
#-----------------------------------------------------------------------------
# Module Logic
656
#
657

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

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


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

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

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

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

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

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

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

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

739
740
741
#-----------------------------------------------------------------------------
# Testing
#
742
IF(Slicer_BUILD_TESTING)
743
  add_subdirectory(Testing)
744
ENDIF()
pieper's avatar
pieper committed
745

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

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

#-----------------------------------------------------------------------------
756
# Launcher for slicer
757
#
758

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

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

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