CMakeLists.txt 31.9 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

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
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
211
# Testing
212
#
213
OPTION(BUILD_TESTING "Test the project" ON)
214
SET(LAUNCH_EXE ${Slicer_BINARY_DIR}/Slicer3 --launch)
jcfr's avatar
jcfr committed
215
IF(BUILD_TESTING)
216 217 218 219
  ENABLE_TESTING()
  INCLUDE(CTest)
  SET(CXX_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  MARK_AS_ADVANCED(TCL_TCLSH DART_ROOT)
220

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

226
ENDIF()
hliu's avatar
hliu committed
227

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

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

244
#-----------------------------------------------------------------------------
245 246 247 248 249
# Libs
# - ITK
# - KWWidgets (pulls in VTK)
#

250 251 252 253
# 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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

524 525 526
# --------------------------------------------------------------------------
# Configure and install headers

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

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

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

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

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

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

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

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

567 568 569 570 571 572
INCLUDE_DIRECTORIES(
  "${CMAKE_CURRENT_SOURCE_DIR}"
  "${CMAKE_CURRENT_BINARY_DIR}"
  )

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

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

582
#-----------------------------------------------------------------------------
583
# Generate SlicerVersion.txt
584

585
INCLUDE(${Slicer_CMAKE_DIR}/SlicerTodayMacro.cmake)
586 587

# Get build time
588
TODAY(Slicer_BUILDDATE)
589

590
# Note that Slicer_BUILD is set above
591

592 593
SET(Slicer_WC_URL NA)
SET(Slicer_WC_REVISION 0)
594 595 596 597 598

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

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

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

623

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

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

644 645
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
646

647

648 649
#-----------------------------------------------------------------------------
# Module Logic
650
#
651

652
INCLUDE("${Slicer_CMAKE_DIR}/SlicerModuleLogicMacros.cmake")
653

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


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

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

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

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

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

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

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

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