CMakeLists.txt 32 KB
Newer Older
1
PROJECT(Slicer)
2

3 4 5 6 7
#-----------------------------------------------------------------------------
# See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details
#-----------------------------------------------------------------------------

SET(project_policies
8
  CMP0001 # NEW: CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.
9 10 11 12 13 14 15 16 17 18 19
  #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.
  #CMP0010 # NEW: Bad variable reference syntax is an error.
  #CMP0011 # NEW: Included scripts do automatic cmake_policy PUSH and POP.
  CMP0012 # NEW: if() recognizes numbers and boolean constants.
jcfr's avatar
jcfr committed
20
  CMP0013 # NEW: Duplicate binary directories are not allowed.
21 22 23 24 25 26 27
  #CMP0014 # NEW: Input directories must have CMakeLists.txt
  )
FOREACH(policy ${project_policies})
  IF(POLICY ${policy})
    CMAKE_POLICY(SET ${policy} NEW)
  ENDIF()
ENDFOREACH()
28

29

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

49
set(Slicer_HOME "${Slicer_BINARY_DIR}")
50

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

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

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

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

108 109 110 111
include(${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
test_big_endian(CMAKE_WORDS_BIGENDIAN)

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

121 122
#-----------------------------------------------------------------------------
# Slicer version number.
123
#
124 125
set(Slicer_VERSION_MAJOR "4")
set(Slicer_VERSION_MINOR "0")
126
IF(NOT Slicer_VERSION_PATCH)
127
  set(Slicer_VERSION_PATCH "alpha")
128
ENDIF()
129 130
set(Slicer_VERSION "${Slicer_VERSION_MAJOR}.${Slicer_VERSION_MINOR}")
set(Slicer_VERSION_FULL "${Slicer_VERSION}.${Slicer_VERSION_PATCH}")
131

132 133
#-----------------------------------------------------------------------------
# Build shared lib by default
134
#
135
option(BUILD_SHARED_LIBS "Build Slicer with shared libraries." ON)
136

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

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

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

164
# See http://www.cmake.org/Wiki/CMakeMacroParseArguments
165
include("${Slicer_CMAKE_DIR}/SlicerParseArgumentsMacro.cmake")
166

167
## QT
168
INCLUDE(${Slicer_CMAKE_DIR}/SlicerFindQT.cmake)
169

170
#-----------------------------------------------------------------------------
171
# Top level slicer configurations
172
#
173 174 175 176 177
# 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")

178 179 180

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

#-----------------------------------------------------------------------------
# Slicer include and libraries subdirectory
188
#
189 190
slicer3_set_persistent_property(Slicer_Libs_LIBRARIES "")
slicer3_set_persistent_property(Slicer_Base_LIBRARIES "")
191 192
slicer3_set_persistent_property(Slicer_Modules_LIBRARIES "")
slicer3_set_persistent_property(Slicer_QTModules_LIBRARIES "")
193

194 195
slicer3_set_persistent_property(Slicer_Libs_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer_Base_INCLUDE_DIRS "")
196 197
slicer3_set_persistent_property(Slicer_Modules_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer_QTModules_INCLUDE_DIRS "")
pieper's avatar
pieper committed
198

199 200 201
#-----------------------------------------------------------------------------
# Get sytem name and architecture
#
202
SET(Slicer_BUILD NA)
203
INCLUDE(${Slicer_CMAKE_DIR}/DiscoverSystemNameAndBits.cmake)
204
MESSAGE(STATUS "Slicer_BUILD:${Slicer_BUILD}")
205

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

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

228
ENDIF()
hliu's avatar
hliu committed
229

230
#-----------------------------------------------------------------------------
231
# By default, build without KWWidget (TODO: eliminate this option for slicer4)
232
#
233
option(Slicer_USE_KWWIDGETS "Build Slicer with KWWidgets." OFF)
234 235 236

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

246
#-----------------------------------------------------------------------------
247 248 249 250 251
# Libs
# - ITK
# - KWWidgets (pulls in VTK)
#

252 253 254 255
# 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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

526 527 528
# --------------------------------------------------------------------------
# Configure and install headers

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

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

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

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

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

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

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

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

569 570 571 572 573 574
INCLUDE_DIRECTORIES(
  "${CMAKE_CURRENT_SOURCE_DIR}"
  "${CMAKE_CURRENT_BINARY_DIR}"
  )

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

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

584
#-----------------------------------------------------------------------------
585
# Generate SlicerVersion.txt
586

587
INCLUDE(${Slicer_CMAKE_DIR}/SlicerTodayMacro.cmake)
588 589

# Get build time
590
TODAY(Slicer_BUILDDATE)
591

592
# Note that Slicer_BUILD is set above
593

594 595
SET(Slicer_WC_URL NA)
SET(Slicer_WC_REVISION 0)
596 597 598 599 600

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

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

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

625

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

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

646 647
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
648

649

650 651
#-----------------------------------------------------------------------------
# Module Logic
652
#
653

654
INCLUDE("${Slicer_CMAKE_DIR}/SlicerModuleLogicMacros.cmake")
655

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


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

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

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

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

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

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

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

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

735 736 737
#-----------------------------------------------------------------------------
# Testing
#
738
IF(Slicer_BUILD_TESTING)
739
  add_subdirectory(Testing)
740
ENDIF()
pieper's avatar
pieper committed
741

barre's avatar