CMakeLists.txt 31.3 KB
Newer Older
1 2 3 4 5
PROJECT(Slicer3)

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
IF(COMMAND CMAKE_POLICY)
  CMAKE_POLICY(SET CMP0003 NEW)
6
  CMAKE_POLICY(SET CMP0012 NEW)
7 8
ENDIF(COMMAND CMAKE_POLICY)
MARK_AS_ADVANCED(CMAKE_BACKWARDS_COMPATIBILITY)
9

10

11
#-----------------------------------------------------------------------------
12
#
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
set(Slicer_INSTALL_BIN_DIR "bin")
set(Slicer_INSTALL_LIB_DIR "lib/Slicer3")
set(Slicer_INSTALL_INCLUDE_DIR "include/Slicer3")
set(Slicer_INSTALL_SHARE_DIR "share/Slicer3")
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")
29 30 31

set(Slicer3_HOME "${Slicer3_BINARY_DIR}")

32 33 34 35
#-----------------------------------------------------------------------------
# Convenient macro allowing to download a file
#
MACRO(downloadFile url dest)
36 37 38 39 40 41 42
  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()
43 44
  ELSE()
    # Make sure the file is not empty
45 46 47
    FILE(READ ${dest} dest_content LIMIT 4)
    STRING(LENGTH "${dest_content}" dest_length)
    IF(NOT "${dest_length}" EQUAL 4)
48 49 50
      FILE(REMOVE ${dest})
      downloadFile(${url} ${dest})
    ENDIF()
51 52 53
  ENDIF()
ENDMACRO()

54
#-----------------------------------------------------------------------------
55 56
# Disable the warnings that DevStudio 2005 emits wrt to sprintf, strcpu, etc.
#
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
# 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
          )
76 77 78 79
      ENDIF()
    ENDIF()
  ENDIF()
ENDIF()
80

81 82
# Disable warning C4996: [...] This function or variable may be unsafe. [...]
# To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details
83
IF(MSVC90)
84
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
85
ENDIF()
86

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

89 90 91 92
include(${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
test_big_endian(CMAKE_WORDS_BIGENDIAN)

#-----------------------------------------------------------------------------
93 94 95 96
# avoid linker bug in Mac OS 10.5
# see:
# http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
#
97
IF(APPLE)
98 99
  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")
100
ENDIF()
101

102 103
#-----------------------------------------------------------------------------
# Slicer version number.
104
#
105 106
set(Slicer_VERSION_MAJOR "4")
set(Slicer_VERSION_MINOR "0")
107
IF(NOT Slicer_VERSION_PATCH)
108
  set(Slicer_VERSION_PATCH "alpha")
109
ENDIF()
110 111
set(Slicer_VERSION "${Slicer_VERSION_MAJOR}.${Slicer_VERSION_MINOR}")
set(Slicer_VERSION_FULL "${Slicer_VERSION}.${Slicer_VERSION_PATCH}")
112

113 114
#-----------------------------------------------------------------------------
# Build shared lib by default
115
#
116 117
option(BUILD_SHARED_LIBS "Build Slicer3 with shared libraries." ON)

118 119 120 121 122 123
#-----------------------------------------------------------------------------
# Append the library version information to the library target properties.
#
OPTION(Slicer3_WITH_LIBRARY_VERSION "Build with library version information" OFF)
IF(Slicer3_WITH_LIBRARY_VERSION)
  SET(Slicer3_LIBRARY_PROPERTIES ${Slicer3_LIBRARY_PROPERTIES}
124 125
    VERSION ${Slicer_VERSION_FULL}
    SOVERSION ${Slicer_VERSION}
126
  )
127
ENDIF()
128

129 130
#-----------------------------------------------------------------------------
# Slicer3 macros
pieper's avatar
pieper committed
131
#
132
set(Slicer_CMAKE_DIR "${Slicer3_SOURCE_DIR}/CMake" CACHE INTERNAL "")
133 134 135
add_subdirectory(CMake)
# Make sure VTK_CMAKE_DIR is at the beginning so that VTK's FindTCL is
# used before CMake's FindTCL.
136 137
set(CMAKE_MODULE_PATH
  "${VTK_CMAKE_DIR}"
138
  "${Slicer_CMAKE_DIR}"
139 140 141
  ${Slicer3_BINARY_DIR}/CMake
  ${CMAKE_MODULE_PATH}
  )
pieper's avatar
pieper committed
142

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

145
# See http://www.cmake.org/Wiki/CMakeMacroParseArguments
146
include("${Slicer_CMAKE_DIR}/SlicerParseArgumentsMacro.cmake")
147

148
## QT
149
INCLUDE(${Slicer_CMAKE_DIR}/SlicerFindQT.cmake)
150

151 152
#-----------------------------------------------------------------------------
# Top level slicer3 configurations
153
#
154 155 156 157 158
# 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")

159 160 161

# Do NOT force into the cache, as plugins need to override locally and scoping
# becomes an issue.
162
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/ 
163
#  CACHE PATH "Single output directory for building all libraries." FORCE)
164
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/ 
165 166 167 168
#  CACHE PATH "Single output directory for building all executables." FORCE)

#-----------------------------------------------------------------------------
# Slicer include and libraries subdirectory
169
#
170 171 172
slicer3_set_persistent_property(Slicer3_Libs_LIBRARIES "")
slicer3_set_persistent_property(Slicer3_Base_LIBRARIES "")
slicer3_set_persistent_property(Slicer3_Modules_LIBRARIES "")
173
slicer3_set_persistent_property(Slicer3_QTModules_LIBRARIES "")
174

175 176 177
slicer3_set_persistent_property(Slicer3_Libs_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer3_Base_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer3_Modules_INCLUDE_DIRS "")
178
slicer3_set_persistent_property(Slicer3_QTModules_INCLUDE_DIRS "")
pieper's avatar
pieper committed
179

180 181 182 183
#-----------------------------------------------------------------------------
# Get sytem name and architecture
#
SET(Slicer3_BUILD NA)
184
INCLUDE(${Slicer_CMAKE_DIR}/DiscoverSystemNameAndBits.cmake)
185 186
MESSAGE(STATUS "Slicer3_BUILD:${Slicer3_BUILD}")

187
#-----------------------------------------------------------------------------
pieper's avatar
pieper committed
188
# Add the testing directories
189
#
190 191 192 193
OPTION(BUILD_TESTING "Test the project" ON)
SET(Slicer3_BUILD_TESTING ${BUILD_TESTING})
SET(LAUNCH_EXE ${Slicer3_BINARY_DIR}/Slicer3 --launch)
IF(Slicer3_BUILD_TESTING)
194
  #IF(NOT BUILDNAME)
195 196 197 198
  #  SET(BUILDNAME "${Slicer3_BUILD}" CACHE STRING "Name of build on the dashboard")
  #ELSE()
  #  SET(BUILDNAME "${BUILDNAME}" CACHE STRING "Name of build on the dashboard")
  #ENDIF()
199 200 201 202
  ENABLE_TESTING()
  INCLUDE(CTest)
  SET(CXX_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  MARK_AS_ADVANCED(TCL_TCLSH DART_ROOT)
203

204 205 206 207
  #-----------------------------------------------------------------------------
  # Run test through valgrind: particularly useful for testing modules.
  #
  option(USE_VALGRIND "Run tests through valgrind." OFF)
208

209
ENDIF()
hliu's avatar
hliu committed
210

211
#-----------------------------------------------------------------------------
212
# By default, build without KWWidget (TODO: eliminate this option for slicer4)
213
#
214
option(Slicer3_USE_KWWIDGETS "Build Slicer3 with KWWidgets." OFF)
215 216 217

#-----------------------------------------------------------------------------
# Since modules are KWWidgets based, unset there variables
218
IF(NOT Slicer3_USE_KWWIDGETS)
219
  # Since the module Logic is shared between QTModules and regular Modules,
220
  # the associated BIN, LIB and INCLUDE directory shouldn't be unset
221 222 223 224
  #UNSET(Slicer_INSTALL_MODULES_BIN_DIR)
  #UNSET(Slicer_INSTALL_MODULES_LIB_DIR)
  #UNSET(Slicer_INSTALL_MODULES_INCLUDE_DIR)
  UNSET(Slicer_INSTALL_MODULES_SHARE_DIR)
225
ENDIF()
226

227
#-----------------------------------------------------------------------------
228 229 230 231 232
# Libs
# - ITK
# - KWWidgets (pulls in VTK)
#

233 234 235 236
# 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.

237
IF(Slicer3_USE_KWWIDGETS)
238
  set(SKIP_KWWidgets_BUILD_SETTINGS_FILE 1)
239
ENDIF()
240 241
set(SKIP_VTK_BUILD_SETTINGS_FILE 1)
set(SKIP_ITK_BUILD_SETTINGS_FILE 1)
242
set(SKIP_Teem_BUILD_SETTINGS_FILE 1)
243 244

#-----------------------------------------------------------------------------
245
## Python
246
option(Slicer3_USE_PYTHON "Integrate a python interpreter into Slicer." OFF)
247
IF(Slicer3_USE_PYTHON OR Slicer3_USE_PYTHONQT)
248
  find_package(PythonLibs)
249
  find_package(PythonInterp)
250
ENDIF()
251

252
#-----------------------------------------------------------------------------
253
## ITK
254
find_package(ITK REQUIRED)
255
IF(NOT ITK_FOUND)
256
  message(FATAL_ERROR "Need ITK to build")
257
ENDIF()
258
include(${ITK_USE_FILE})
259

260 261 262
#-----------------------------------------------------------------------------
# FindCTK
#
263
SET(git_repo http://github.com/commontk/CTK/raw/master/)
264

265
IF(Slicer3_USE_QT)
266 267 268 269 270 271
  SET(file Utilities/CMake/FindCTK.cmake)
  downloadFile(${git_repo}/${file} ${Slicer3_BINARY_DIR}/CMake/FindCTK.cmake)

  FIND_PACKAGE(CTK REQUIRED)
  IF(CTK_FOUND)
    INCLUDE(${CTK_USE_FILE})
272 273 274 275
    # Update CMake module path
    SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CTK_CMAKE_UTILITIES_DIR})
    IF(Slicer3_USE_PYTHONQT)
      SET(PYTHONQT_INSTALL_DIR ${CTK_PYTHONQT_INSTALL_DIR})
276
      LINK_DIRECTORIES(${PYTHONQT_INSTALL_DIR}/lib)
277 278
      INCLUDE(${CTK_CMAKE_DIR}/ctkMacroWrapPythonQt.cmake)
    ENDIF()
279 280 281
  ENDIF()
ENDIF()

282
#-----------------------------------------------------------------------------
283
IF(Slicer3_USE_KWWIDGETS)
284 285 286 287
  ## KWWidgets
  FIND_PACKAGE(KWWidgets REQUIRED)
  IF(NOT KWWidgets_FOUND)
    MESSAGE(FATAL_ERROR "Need KWWidgets to build")
288
  ENDIF()
289
  INCLUDE(${KWWidgets_USE_FILE})
290
  
291
ELSE()
292 293

  # VTK
294 295
  FIND_PACKAGE(VTK REQUIRED)
  IF(NOT VTK_FOUND)
296
    MESSAGE(FATAL_ERROR "Need VTK to build")
297
  ELSE()
298 299
    IF(NOT VTK_USE_QVTK)
      MESSAGE("Please make sure VTK is build with VTK_USE_GUISUPPORT and VTK_USE_QVTK enabled")
300 301
    ENDIF()
  ENDIF()
302
  INCLUDE(${VTK_USE_FILE})
303
  
304
ENDIF()
305

306 307 308
#-----------------------------------------------------------------------------
# Slicer3 is built with cvs head
#
309 310
option(Slicer3_USE_VTK_CVSHEAD "Slicer3 is configurated with cvs head." OFF)
mark_as_advanced(Slicer3_USE_VTK_CVSHEAD)
311

312
#-----------------------------------------------------------------------------
313
#
314
# Call macro defined in ${PROJECT_SOURCE_DIR}/CMake/SlicerFindQT.cmake
315
#
316
SLICER_SETUP_QT()
317

318 319 320 321
#-----------------------------------------------------------------------------
# Alert the user if both Slicer3_USE_QT and Slicer3_USE_KWWIDGETS are OFF
IF(NOT Slicer3_USE_QT AND NOT Slicer3_USE_KWWIDGETS)
  MESSAGE(FATAL_ERROR "Both Slicer3_USE_QT and Slicer3_USE_KWWIDGETS are OFF. Please, choose one")
322
ENDIF()
323 324 325

#-----------------------------------------------------------------------------
# If Slicer3_USE_QT is ON and Slicer3_USE_KWWIDGETS is OFF, complain if VTK_WRAP_TCL is ON
326
# Note: Later on we will expect VTK_WRAP_PYTHON to be ON
327 328 329
IF(Slicer3_USE_QT AND NOT Slicer3_USE_KWWIDGETS)
  IF(VTK_WRAP_TCL)
    MESSAGE(FATAL_ERROR "For now, if Slicer3_USE_QT is ON and Slicer3_USE_KWWIDGETS is OFF, we expect VTK_WRAP_TCL to be OFF")
330 331
  ENDIF()
ENDIF()
332

333 334 335 336 337 338 339
#-----------------------------------------------------------------------------
# Add Slicer3_USE_PYTHONQT option if Slicer3_USE_QT is ON
IF(Slicer3_USE_QT)
  option(Slicer3_USE_PYTHONQT "Integrate a python-QT interpreter into Slicer." OFF)
  IF(Slicer3_USE_PYTHONQT)
    IF(NOT VTK_WRAP_PYTHON)
      MESSAGE(FATAL_ERROR "Since both Slicer3_USE_QT and Slicer3_USE_PYTHONQT are ON, VTK_WRAP_PYTHON is expected to be ON. Disable Slicer3_USE_PYTHONQT or re-configure VTK with python wrapping.")
340
    ENDIF()
341
    # Include convenient script allowing to copy and compile python scripts
342
    INCLUDE(${Slicer_CMAKE_DIR}/SlicerCompilePythonScripts.cmake)
343
    # Enable qMRMLWidgets python wrapping
344
    SET(qMRMLWidgets_WRAP_PYTHON OFF)
345 346
  ENDIF()
ENDIF()
347

348
#-----------------------------------------------------------------------------
349
## Teem
350
find_package(Teem REQUIRED)
351
IF(NOT Teem_FOUND)
352
  message(FATAL_ERROR "Need Teem to build")
353
ENDIF()
354
include(${Teem_USE_FILE})
355

356
#-----------------------------------------------------------------------------
357 358
## SlicerLibCurl
find_package(SLICERLIBCURL REQUIRED)
359
IF(SLICERLIBCURL_FOUND)
360
  include(${SLICERLIBCURL_USE_FILE})
361
ENDIF()
362 363

#-----------------------------------------------------------------------------
364
## BatchMake
365 366
option(Slicer_USE_BatchMake "Build Slicer with BatchMake support." OFF)
IF(Slicer_USE_BatchMake)
367 368
  find_package(BatchMake REQUIRED)
  include(${BatchMake_USE_FILE})
369
ENDIF()
370

371
#-----------------------------------------------------------------------------
372
## MIDAS
373
option(Slicer_USE_MIDAS "Build Slicer with MIDAS support." OFF)
374

375
#-----------------------------------------------------------------------------
376 377
## OpenIGTLink (Built in Slicer3-lib)
option(Slicer3_USE_OPENIGTLINK "Build Slicer3 with OpenIGTLink support." OFF)
378
IF(Slicer3_USE_OPENIGTLINK)
379 380
  find_package(OpenIGTLink REQUIRED)
  include(${OpenIGTLink_USE_FILE})
381
ENDIF()
hliu's avatar
hliu committed
382

383 384 385
#-----------------------------------------------------------------------------
## OpenCV (Built in Slicer3-lib)
option(Slicer3_USE_OPENCV "Build Slicer3 with OpenCV support." OFF)
386
IF(Slicer3_USE_OPENCV)
387 388 389 390 391
  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})
392
  ENDIF()
393 394 395 396 397 398 399 400 401 402 403 404 405 406
  
  # 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})
407
ENDIF()
408 409


410 411
#-----------------------------------------------------------------------------
# Need some Tcl/Tk info
412
IF(VTK_WRAP_TCL)
413 414 415 416 417 418 419 420 421
  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}")
  IF(Slicer3_USE_KWWIDGETS)
    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}")
422 423
  ENDIF()
ELSE()
424 425 426 427 428
  # 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
429 430
  set(TCL_TK_VERSION_DOT "8.4")
  set(TCL_TK_VERSION "84")
431 432
  set(INCR_TCL_VERSION_DOT "3.2")
  set(INCR_TCL_VERSION "32")
433
ENDIF()
434

435
#-----------------------------------------------------------------------------
barre's avatar
barre committed
436 437 438
# 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.
439
#
440
IF(Slicer3_USE_KWWIDGETS)
441 442 443 444
  include("${KWWidgets_CMAKE_DIR}/KWWidgetsPathsMacros.cmake")
  set(extra_dirs
    "${Teem_DIR}/bin"
    "${BatchMake_DIR}/bin"
445
    "${OpenIGTLink_DIR}/bin"
446 447 448 449
    "${Slicer3_HOME}/${Slicer_INSTALL_PLUGINS_BIN_DIR}"
    "${Slicer3_HOME}/${Slicer_INSTALL_PLUGINS_LIB_DIR}"
    "${Slicer3_HOME}/${Slicer_INSTALL_MODULES_BIN_DIR}"
    "${Slicer3_HOME}/${Slicer_INSTALL_MODULES_LIB_DIR}"
450 451 452 453
    )
  kwwidgets_generate_setup_paths_scripts(
    "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" "Slicer3SetupPaths"
    "${extra_dirs}"
454
  )
455
ENDIF()
barre's avatar
barre committed
456

457
#-----------------------------------------------------------------------------
barre's avatar
barre committed
458 459 460 461 462
# 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}" "")
463
#
464 465
IF(Slicer3_USE_KWWIDGETS)
  IF(NOT VTK_CMAKE_DIR)
466
    set(VTK_CMAKE_DIR "${VTK_SOURCE_DIR}/CMake")
467
  ENDIF()
468
  include("${VTK_CMAKE_DIR}/vtkWrapTcl.cmake")
469
ENDIF()
470

471 472
#-----------------------------------------------------------------------------
# Check versions of VTK to track CVS HEAD
473
#
474
IF(Slicer3_USE_KWWIDGETS)
475
  find_package(VTK REQUIRED)
476
  IF(EXISTS ${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
477
    include(${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
478
  else()
479 480
    #MESSAGE("Using local version of VTKVersionMacros for compatibility.")
    include(${Slicer3_SOURCE_DIR}/Scripts/VTKVersionMacros.cmake)
481
  ENDIF()
482 483

  vtk_get_source_revision_and_date(VTKsource_revision VTKsource_date)
484
  IF(VTKsource_revision LESS 1.2196)
485
    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.")
486 487
  ENDIF()
ENDIF()
488

489 490
#-----------------------------------------------------------------------------
# These packages may exist within the Slicer3 source tree
lorensen's avatar
lorensen committed
491
#
492 493 494
set(TCLAP_DIR ${Slicer3_BINARY_DIR}/Libs/SlicerExecutionModel/tclap)
set(ModuleDescriptionParser_DIR ${Slicer3_BINARY_DIR}/Libs/SlicerExecutionModel/ModuleDescriptionParser)
set(GenerateCLP_DIR ${Slicer3_BINARY_DIR}/Libs/SlicerExecutionModel/GenerateCLP)
495 496 497
set(GenerateLM_DIR ${Slicer3_BINARY_DIR}/Libs/GenerateLM)
set(LoadableModule_DIR ${Slicer3_BINARY_DIR}/Libs/LoadableModule)
set(vtkITK_DIR ${Slicer3_BINARY_DIR}/Libs/vtkITK)
498

jcfr's avatar
jcfr committed
499 500 501 502 503 504 505
#-----------------------------------------------------------------------------
# Qt Loadable Modules
#
IF(Slicer3_USE_QT)
  OPTION(Slicer3_BUILD_QTLOADABLEMODULES "Build Slicer3 QT Loadable Modules" ON)
  IF(Slicer3_BUILD_QTLOADABLEMODULES)
    ADD_DEFINITIONS(-DSlicer3_BUILD_QTLOADABLEMODULES)
506 507 508 509
    set(Slicer3_INSTALL_QTLOADABLEMODULES_BIN_DIR "${Slicer_INSTALL_LIB_DIR}/QTLoadableModules")
    set(Slicer3_INSTALL_QTLOADABLEMODULES_LIB_DIR "${Slicer_INSTALL_LIB_DIR}/QTLoadableModules")
    set(Slicer3_INSTALL_QTLOADABLEMODULES_INCLUDE_DIR "${Slicer_INSTALL_INCLUDE_DIR}/QTLoadableModules")
    set(Slicer3_INSTALL_QTLOADABLEMODULES_SHARE_DIR "${Slicer_INSTALL_SHARE_DIR}/QTLoadableModules")
510 511
  ENDIF()
ENDIF()
jcfr's avatar
jcfr committed
512

513 514 515
# --------------------------------------------------------------------------
# Configure and install headers

516
CONFIGURE_FILE(
517 518 519 520
  ${CMAKE_CURRENT_SOURCE_DIR}/vtkSlicerConfigure.h.in 
  ${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h
  )

521 522 523 524 525 526
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/vtkSlicerVersionConfigure.h.in 
  ${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerVersionConfigure.h
  )

CONFIGURE_FILE(
527 528
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runValgrind.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runValgrind.sh
529 530
  )

531 532 533 534 535
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runValgrindForOneModule.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runValgrindForOneModule.sh
  )

536 537 538 539 540
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runValgrindForOneModuleWithSlicer4AndQT.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runValgrindForOneModuleWithSlicer4AndQT.sh
  )

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

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

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

556 557 558 559 560 561
INCLUDE_DIRECTORIES(
  "${CMAKE_CURRENT_SOURCE_DIR}"
  "${CMAKE_CURRENT_BINARY_DIR}"
  )

INSTALL(FILES 
562
  "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h"
563
  DESTINATION ${Slicer_INSTALL_INCLUDE_DIR} COMPONENT Development
564 565
  )

566 567
INSTALL(FILES 
  "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerVersionConfigure.h"
568
  DESTINATION ${Slicer_INSTALL_INCLUDE_DIR} COMPONENT Development
569 570
  )

571 572 573
#-----------------------------------------------------------------------------
# Generate Slicer3Version.txt

574
INCLUDE(${Slicer_CMAKE_DIR}/SlicerTodayMacro.cmake)
575 576 577 578

# Get build time
TODAY(Slicer3_BUILDDATE)

579
# Note that Slicer_BUILD is set above
580 581 582 583 584 585 586 587

SET(Slicer3_WC_URL NA)
SET(Slicer3_WC_REVISION 0)

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

# Case where Slicer is checkout using SVN
591
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.svn)
592 593 594 595 596 597 598 599
  Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} Slicer3)
  CONFIGURE_FILE(
    ${CMAKE_CURRENT_SOURCE_DIR}/Slicer3Version.txt.in 
    ${Slicer3_HOME}/lib/Slicer3/Slicer3Version.txt
    )
ENDIF()

# Case where Slicer is checkout using Git-SVN
600
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
601 602 603 604 605 606 607 608 609 610 611
  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(
    ${CMAKE_CURRENT_SOURCE_DIR}/Slicer3Version.txt.in
    ${Slicer3_HOME}/lib/Slicer3/Slicer3Version.txt
    )
ENDIF()

612

613
#-----------------------------------------------------------------------------
pieper's avatar
pieper committed
614 615
# Subdirectories
#
616 617
add_subdirectory(Libs)
add_subdirectory(Base)
618
add_subdirectory(Resources)
619

620
#-----------------------------------------------------------------------------
621
# At this point, let's not have the applications and modules guess which
622 623
# include paths or libraries they need, but use Slicer3_*_LIBRARIES and
# Slicer3_*_INCLUDE_DIRS instead. As far as modules are concerned, both
624 625 626 627 628
# variables are actually set automatically by the import script when building
# against a Slicer3 build or installed tree. When in-source, we need to
# 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).
629 630 631
#
slicer3_get_persistent_property(Slicer3_Libs_LIBRARIES Slicer3_Libs_LIBRARIES)
slicer3_get_persistent_property(Slicer3_Base_LIBRARIES Slicer3_Base_LIBRARIES)
632

633 634
slicer3_get_persistent_property(Slicer3_Libs_INCLUDE_DIRS Slicer3_Libs_INCLUDE_DIRS)
slicer3_get_persistent_property(Slicer3_Base_INCLUDE_DIRS Slicer3_Base_INCLUDE_DIRS)
pieper's avatar
pieper committed
635

636

637 638
#-----------------------------------------------------------------------------
# Module Logic
639
#
640

641
INCLUDE("${Slicer_CMAKE_DIR}/SlicerModuleLogicMacros.cmake")
642

643
IF(NOT Slicer3_USE_KWWIDGETS)
644 645 646
  # 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:
647 648 649 650 651 652
  # 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()
653
    FILE(GLOB subsubdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${subdir}/*)
654
    FOREACH(subsubdir ${subsubdirs})
655 656
      IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${subsubdir}/Logic)
        ADD_SUBDIRECTORY(${subsubdir}/Logic)
657 658
      ENDIF()
    ENDFOREACH()
659 660
  ENDFOREACH()
ENDIF()
661 662


663 664 665 666
#-----------------------------------------------------------------------------
# Modules and CLI
#
option(Slicer3_BUILD_CLI "Build Slicer3 CLI Plugins" ON)
667
IF(Slicer3_USE_KWWIDGETS)
668
  option(Slicer3_BUILD_MODULES "Build Slicer3 Modules" ON)
669
ENDIF()
670

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

673
IF(Slicer3_USE_KWWIDGETS)
674
  include("${Slicer_CMAKE_DIR}/Slicer3ModulesMacros.cmake")
675
  
676
  IF(Slicer3_BUILD_MODULES)
677 678 679 680
    add_subdirectory(Modules)
  else(Slicer3_BUILD_MODULES)
    # if Slicer3_BUILD_CLI is ON, we still need at least the CommandLineModule
    # so that we can have CLI, without all the other modules
681
    IF(Slicer3_BUILD_CLI)
682
      add_subdirectory(Modules/CommandLineModule)
683 684 685
    ENDIF(Slicer3_BUILD_CLI)
  ENDIF(Slicer3_BUILD_MODULES)
ENDIF()
686 687 688 689 690 691

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

692
IF(Slicer3_BUILD_MODULES OR Slicer3_BUILD_QTLOADABLEMODULES)
693
  include("${Slicer_CMAKE_DIR}/Slicer3ModulesMacros.cmake")
694 695 696 697
  ADD_SUBDIRECTORY(Modules/EMSegment/Algorithm)
  ADD_SUBDIRECTORY(Modules/EMSegment/MRML)
  ADD_SUBDIRECTORY(Modules/EMSegment/Registration)
  ADD_SUBDIRECTORY(Modules/EMSegment/Graph)
698
ENDIF()
699

700 701 702
# 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
703 704
IF(Slicer3_USE_KWWIDGETS)
  IF(Slicer3_BUILD_MODULES)
705
    ADD_SUBDIRECTORY(Modules/EMSegment)
706
  ENDIF()
707 708
ENDIF()

709
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
710
# Qt Loadable Modules
711
#
jcfr's avatar
jcfr committed
712 713
IF(Slicer3_USE_QT AND Slicer3_BUILD_QTLOADABLEMODULES)
  add_subdirectory(QTModules)
714
ENDIF()
715

716 717 718 719
#-----------------------------------------------------------------------------
# Applications need to be built after Modules to capture the TractTracing in
# the correct ordering.
#
720
add_subdirectory(Applications)
721

722 723 724
#-----------------------------------------------------------------------------
# Testing
#
725
IF(Slicer3_BUILD_TESTING)
726
  add_subdirectory(Testing)
727
ENDIF()
pieper's avatar
pieper committed
728

729
# Install testing data
andy's avatar
andy committed
730

731 732
install(DIRECTORY
  Testing
733
  DESTINATION ${Slicer_INSTALL_SHARE_DIR} COMPONENT Development
734 735 736 737 738
  PATTERN ".svn" EXCLUDE
  PATTERN "CMakeLists.txt" EXCLUDE
  )

#-----------------------------------------------------------------------------
739
# Launcher for slicer
740
#
741

742 743
# let's build the launcher for Kww, KwwAndQt and also QtOnly slicer ...
ADD_SUBDIRECTORY(Utilities/Launcher)
744

745 746 747 748 749
# Compute Slicer3_QT_PLUGIN_PATH used to configure launch.tcl.in
SET(Slicer3_QT_PLUGIN_PATH "")
IF(Slicer3_USE_QT)
  SET(designer_launcher_project_name SlicerQT)
  GET_TARGET_PROPERTY(output_directory ${designer_launcher_project_name} LIBRARY_OUTPUT_DIRECTORY)
750
  SET(Slicer3_QT_PLUGIN_PATH ${output_directory})
751 752 753 754 755 756

  # 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})
757
      IF(QT_${qtlib}_LIBRARY_RELEASE AND APPLE)
758 759 760
          GET_FILENAME_COMPONENT(QT_FRAMEWORK_NAME_tmp ${QT_${qtlib}_LIBRARY_RELEASE} NAME)
          SET(Slicer3_QT_FRAMEWORK_DIRS "lib/Qt/${QT_FRAMEWORK_NAME_tmp}/Versions/4:${Slicer3_QT_FRAMEWORK_DIRS}")
      ENDIF()
761 762
    ENDFOREACH()
  ENDIF()
763 764 765 766 767 768 769
  
  option(Slicer_USE_CTKAPPLAUNCHER "Configure ctkAppLauncher." OFF)
  mark_as_advanced(Slicer_USE_CTKAPPLAUNCHER)
  
  # ctkAppLauncher for slicer
  IF(Slicer_USE_CTKAPPLAUNCHER)
    INCLUDE(${CTKAPPLAUNCHER_DIR}/CMake/ctkAppLauncher.cmake)
770
    INCLUDE(${Slicer_CMAKE_DIR}/SlicerCTKAppLauncherSettings.cmake)
771 772
    ctkAppLauncherConfigure(
      APPLICATION_PATH ${Slicer3_BINARY_DIR}/bin/SlicerQT-real${CMAKE_EXECUTABLE_SUFFIX}
773
      APPLICATION_INSTALL_SUBDIR ${Slicer_INSTALL_BIN_DIR}
774 775
      APPLICATION_NAME Slicer
      SPLASH_IMAGE_PATH ${Slicer3_SOURCE_DIR}/Applications/SlicerQT/Resources/Images/SlicerSplashScreen.png
776
      SPLASH_IMAGE_INSTALL_SUBDIR ${Slicer_INSTALL_BIN_DIR}
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
      SPLASHSCREEN_HIDE_DELAY_MS 3000
      ADDITIONAL_HELP_SHORT_ARG "-h"
      ADDITIONAL_HELP_LONG_ARG "--help"
      ADDITIONAL_NOSPLASH_LONG_ARG "--no-splash"
      DESTINATION_DIR ${Slicer3_BINARY_DIR}
      LIBRARY_PATHS_BUILD "${SLICER_LIBRARY_PATHS_BUILD}"
      PATHS_BUILD "${SLICER_PATHS_BUILD}"
      ENVVARS_BUILD "${SLICER_ENVVARS_BUILD}"
      LIBRARY_PATHS_INSTALLED "${SLICER_LIBRARY_PATHS_INSTALLED}"
      PATHS_INSTALLED "${SLICER_PATHS_INSTALLED}"
      ENVVARS_INSTALLED "${SLICER_ENVVARS_INSTALLED}"
      )
    install(PROGRAMS "${Slicer3_BINARY_DIR}/Slicer${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ".")
    install(
      FILES "${Slicer3_SOURCE_DIR}/Applications/SlicerQT/Resources/Images/SlicerSplashScreen.png" 
792
      DESTINATION ${Slicer_INSTALL_BIN_DIR}
793 794 795
      )
    install(
      FILES "${Slicer3_BINARY_DIR}/SlicerLauncherSettingsToInstall.ini" 
796
      DESTINATION ${Slicer_INSTALL_BIN_DIR}
797 798 799
      RENAME SlicerLauncherSettings.ini
      )
  ENDIF()
800

801 802
ENDIF(Slicer3_USE_QT)

803 804
CONFIGURE_FILE(
  ${Slicer3_SOURCE_DIR}/launch.tcl.in
805
  "${Slicer3_BINARY_DIR}/${Slicer_INSTALL_LIB_DIR}/launch.tcl"
806 807
  )
INSTALL(
808 809
  FILES "${Slicer3_BINARY_DIR}/${Slicer_INSTALL_LIB_DIR}/launch.tcl"
  DESTINATION ${Slicer_INSTALL_LIB_DIR}
810
  )
811

812 813 814 815
#-----------------------------------------------------------------------------
# Launcher for QTDesigner
#

816
IF(Slicer3_USE_QT)
817
  add_subdirectory(Utilities/Designer)