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

jcfr's avatar
jcfr committed
3
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.2)
4 5
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
set(Slicer_INSTALL_BIN_DIR "bin")
set(Slicer_INSTALL_LIB_DIR "lib/Slicer3")
15 16
set(Slicer_INSTALL_INCLUDE_DIR "include/Slicer")
set(Slicer_INSTALL_SHARE_DIR "share/Slicer")
17 18 19 20 21 22 23 24 25 26 27 28
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
set(Slicer_HOME "${Slicer_BINARY_DIR}")
31

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
option(BUILD_SHARED_LIBS "Build Slicer with shared libraries." ON)
117

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

129
#-----------------------------------------------------------------------------
130
# Slicer macros
pieper's avatar
pieper committed
131
#
132
set(Slicer_CMAKE_DIR "${Slicer_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
  ${Slicer_BINARY_DIR}/CMake
140 141
  ${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 slicer 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
slicer3_set_persistent_property(Slicer_Libs_LIBRARIES "")
slicer3_set_persistent_property(Slicer_Base_LIBRARIES "")
172 173
slicer3_set_persistent_property(Slicer_Modules_LIBRARIES "")
slicer3_set_persistent_property(Slicer_QTModules_LIBRARIES "")
174

175 176
slicer3_set_persistent_property(Slicer_Libs_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer_Base_INCLUDE_DIRS "")
177 178
slicer3_set_persistent_property(Slicer_Modules_INCLUDE_DIRS "")
slicer3_set_persistent_property(Slicer_QTModules_INCLUDE_DIRS "")
pieper's avatar
pieper committed
179

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

187
#-----------------------------------------------------------------------------
pieper's avatar
pieper committed
188
# Add the testing directories
189
#
190
OPTION(BUILD_TESTING "Test the project" ON)
191
SET(Slicer_BUILD_TESTING ${BUILD_TESTING})
192
SET(LAUNCH_EXE ${Slicer_BINARY_DIR}/Slicer3 --launch)
193
IF(Slicer_BUILD_TESTING)
194
  #IF(NOT BUILDNAME)
195
  #  SET(BUILDNAME "${Slicer_BUILD}" CACHE STRING "Name of build on the dashboard")
196 197 198
  #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(Slicer_USE_KWWIDGETS "Build Slicer with KWWidgets." OFF)
215 216 217

#-----------------------------------------------------------------------------
# Since modules are KWWidgets based, unset there variables
218
IF(NOT Slicer_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(Slicer_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 247
option(Slicer_USE_PYTHON "Integrate a python interpreter into Slicer." OFF)
IF(Slicer_USE_PYTHON OR Slicer_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(Slicer_USE_QT)
266
  SET(file Utilities/CMake/FindCTK.cmake)
267
  downloadFile(${git_repo}/${file} ${Slicer_BINARY_DIR}/CMake/FindCTK.cmake)
268 269 270 271

  FIND_PACKAGE(CTK REQUIRED)
  IF(CTK_FOUND)
    INCLUDE(${CTK_USE_FILE})
272 273
    # Update CMake module path
    SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CTK_CMAKE_UTILITIES_DIR})
274
    IF(Slicer_USE_PYTHONQT)
275
      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(Slicer_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
# Call macro defined in ${PROJECT_SOURCE_DIR}/CMake/SlicerFindQT.cmake
309
#
310
SLICER_SETUP_QT()
311

312
#-----------------------------------------------------------------------------
313 314 315
# 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")
316
ENDIF()
317 318

#-----------------------------------------------------------------------------
319
# If Slicer_USE_QT is ON and Slicer_USE_KWWIDGETS is OFF, complain if VTK_WRAP_TCL is ON
320
# Note: Later on we will expect VTK_WRAP_PYTHON to be ON
321
IF(Slicer_USE_QT AND NOT Slicer_USE_KWWIDGETS)
322
  IF(VTK_WRAP_TCL)
323
    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")
324 325
  ENDIF()
ENDIF()
326

327
#-----------------------------------------------------------------------------
328
# Add Slicer_USE_PYTHONQT option if Slicer_USE_QT is ON
329
IF(Slicer_USE_QT)
330 331
  option(Slicer_USE_PYTHONQT "Integrate a python-QT interpreter into Slicer." OFF)
  IF(Slicer_USE_PYTHONQT)
332
    IF(NOT VTK_WRAP_PYTHON)
333
      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.")
334
    ENDIF()
335
    # Include convenient script allowing to copy and compile python scripts
336
    INCLUDE(${Slicer_CMAKE_DIR}/SlicerCompilePythonScripts.cmake)
337
    # Enable qMRMLWidgets python wrapping
338
    SET(qMRMLWidgets_WRAP_PYTHON OFF)
339 340
  ENDIF()
ENDIF()
341

342
#-----------------------------------------------------------------------------
343
## Teem
344
find_package(Teem REQUIRED)
345
IF(NOT Teem_FOUND)
346
  message(FATAL_ERROR "Need Teem to build")
347
ENDIF()
348
include(${Teem_USE_FILE})
349

350
#-----------------------------------------------------------------------------
351 352
## SlicerLibCurl
find_package(SLICERLIBCURL REQUIRED)
353
IF(SLICERLIBCURL_FOUND)
354
  include(${SLICERLIBCURL_USE_FILE})
355
ENDIF()
356 357

#-----------------------------------------------------------------------------
358
## BatchMake
359 360
option(Slicer_USE_BatchMake "Build Slicer with BatchMake support." OFF)
IF(Slicer_USE_BatchMake)
361 362
  find_package(BatchMake REQUIRED)
  include(${BatchMake_USE_FILE})
363
ENDIF()
364

365
#-----------------------------------------------------------------------------
366
## MIDAS
367
option(Slicer_USE_MIDAS "Build Slicer with MIDAS support." OFF)
368

369
#-----------------------------------------------------------------------------
370
## OpenIGTLink
371 372
option(Slicer_USE_OPENIGTLINK "Build Slicer with OpenIGTLink support." OFF)
IF(Slicer_USE_OPENIGTLINK)
373 374
  find_package(OpenIGTLink REQUIRED)
  include(${OpenIGTLink_USE_FILE})
375
ENDIF()
hliu's avatar
hliu committed
376

377 378
#-----------------------------------------------------------------------------
## OpenCV (Built in Slicer3-lib)
379
option(Slicer_USE_OPENCV "Build Slicer with OpenCV support." OFF)
380
IF(Slicer_USE_OPENCV)
381 382 383 384 385
  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})
386
  ENDIF()
387 388 389 390 391 392 393 394 395 396 397 398 399 400
  
  # 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})
401
ENDIF()
402 403


404 405
#-----------------------------------------------------------------------------
# Need some Tcl/Tk info
406
IF(VTK_WRAP_TCL)
407 408 409 410
  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}")
411
  IF(Slicer_USE_KWWIDGETS)
412 413 414 415
    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}")
416 417
  ENDIF()
ELSE()
418 419 420 421 422
  # 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
423 424
  set(TCL_TK_VERSION_DOT "8.4")
  set(TCL_TK_VERSION "84")
425 426
  set(INCR_TCL_VERSION_DOT "3.2")
  set(INCR_TCL_VERSION "32")
427
ENDIF()
428

429
#-----------------------------------------------------------------------------
barre's avatar
barre committed
430 431 432
# 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.
433
#
434
IF(Slicer_USE_KWWIDGETS)
435 436 437 438
  include("${KWWidgets_CMAKE_DIR}/KWWidgetsPathsMacros.cmake")
  set(extra_dirs
    "${Teem_DIR}/bin"
    "${BatchMake_DIR}/bin"
439
    "${OpenIGTLink_DIR}/bin"
440 441 442 443
    "${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}"
444 445 446 447
    )
  kwwidgets_generate_setup_paths_scripts(
    "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" "Slicer3SetupPaths"
    "${extra_dirs}"
448
  )
449
ENDIF()
barre's avatar
barre committed
450

451
#-----------------------------------------------------------------------------
barre's avatar
barre committed
452 453 454 455 456
# 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}" "")
457
#
458
IF(Slicer_USE_KWWIDGETS)
459
  IF(NOT VTK_CMAKE_DIR)
460
    set(VTK_CMAKE_DIR "${VTK_SOURCE_DIR}/CMake")
461
  ENDIF()
462
  include("${VTK_CMAKE_DIR}/vtkWrapTcl.cmake")
463
ENDIF()
464

465 466
#-----------------------------------------------------------------------------
# Check versions of VTK to track CVS HEAD
467
#
468
IF(Slicer_USE_KWWIDGETS)
469
  find_package(VTK REQUIRED)
470
  IF(EXISTS ${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
471
    include(${VTK_CMAKE_DIR}/VTKVersionMacros.cmake)
472
  else()
473
    #MESSAGE("Using local version of VTKVersionMacros for compatibility.")
474
    include(${Slicer_SOURCE_DIR}/Scripts/VTKVersionMacros.cmake)
475
  ENDIF()
476 477

  vtk_get_source_revision_and_date(VTKsource_revision VTKsource_date)
478
  IF(VTKsource_revision LESS 1.2196)
479
    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.")
480 481
  ENDIF()
ENDIF()
482

483
#-----------------------------------------------------------------------------
484
# These packages may exist within the Slicer source tree
lorensen's avatar
lorensen committed
485
#
486 487 488 489 490 491
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)
492

jcfr's avatar
jcfr committed
493 494 495
#-----------------------------------------------------------------------------
# Qt Loadable Modules
#
496
IF(Slicer_USE_QT)
497
  OPTION(Slicer_BUILD_QTLOADABLEMODULES "Build Slicer QT Loadable Modules" ON)
498 499
  IF(Slicer_BUILD_QTLOADABLEMODULES)
    ADD_DEFINITIONS(-DSlicer_BUILD_QTLOADABLEMODULES)
500 501 502 503
    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")
504 505
  ENDIF()
ENDIF()
jcfr's avatar
jcfr committed
506

507 508 509
# --------------------------------------------------------------------------
# Configure and install headers

510
CONFIGURE_FILE(
511 512 513 514
  ${CMAKE_CURRENT_SOURCE_DIR}/vtkSlicerConfigure.h.in 
  ${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h
  )

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

CONFIGURE_FILE(
521 522
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runValgrind.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runValgrind.sh
523 524
  )

525 526 527 528 529
CONFIGURE_FILE(
  ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/runValgrindForOneModule.sh.in 
  ${CMAKE_CURRENT_BINARY_DIR}/Scripts/runValgrindForOneModule.sh
  )

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

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

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

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

550 551 552 553 554 555
INCLUDE_DIRECTORIES(
  "${CMAKE_CURRENT_SOURCE_DIR}"
  "${CMAKE_CURRENT_BINARY_DIR}"
  )

INSTALL(FILES 
556
  "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h"
557
  DESTINATION ${Slicer_INSTALL_INCLUDE_DIR} COMPONENT Development
558 559
  )

560 561
INSTALL(FILES 
  "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerVersionConfigure.h"
562
  DESTINATION ${Slicer_INSTALL_INCLUDE_DIR} COMPONENT Development
563 564
  )

565
#-----------------------------------------------------------------------------
566
# Generate SlicerVersion.txt
567

568
INCLUDE(${Slicer_CMAKE_DIR}/SlicerTodayMacro.cmake)
569 570

# Get build time
571
TODAY(Slicer_BUILDDATE)
572

573
# Note that Slicer_BUILD is set above
574

575 576
SET(Slicer_WC_URL NA)
SET(Slicer_WC_REVISION 0)
577 578 579 580 581

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

# Case where Slicer is checkout using SVN
585
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.svn)
586 587
  Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} Slicer3)
  CONFIGURE_FILE(
588 589
    ${CMAKE_CURRENT_SOURCE_DIR}/SlicerVersion.txt.in 
    ${Slicer_HOME}/lib/Slicer3/SlicerVersion.txt
590 591 592 593
    )
ENDIF()

# Case where Slicer is checkout using Git-SVN
594
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
595 596 597 598 599 600
  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(
601 602
    ${CMAKE_CURRENT_SOURCE_DIR}/SlicerVersion.txt.in
    ${Slicer_HOME}/lib/Slicer3/SlicerVersion.txt
603 604 605
    )
ENDIF()

606

607
#-----------------------------------------------------------------------------
pieper's avatar
pieper committed
608 609
# Subdirectories
#
610 611
add_subdirectory(Libs)
add_subdirectory(Base)
612
add_subdirectory(Resources)
613

614
#-----------------------------------------------------------------------------
615
# At this point, let's not have the applications and modules guess which
616
# include paths or libraries they need, but use Slicer3_*_LIBRARIES and
617
# Slicer_*_INCLUDE_DIRS instead. As far as modules are concerned, both
618
# variables are actually set automatically by the import script when building
619
# against a Slicer build or installed tree. When in-source, we need to
620 621 622
# 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).
623
#
624 625
slicer3_get_persistent_property(Slicer_Libs_LIBRARIES Slicer_Libs_LIBRARIES)
slicer3_get_persistent_property(Slicer_Base_LIBRARIES Slicer_Base_LIBRARIES)
626

627 628
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
629

630

631 632
#-----------------------------------------------------------------------------
# Module Logic
633
#
634

635
INCLUDE("${Slicer_CMAKE_DIR}/SlicerModuleLogicMacros.cmake")
636

637
IF(NOT Slicer_USE_KWWIDGETS)
638 639 640
  # 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:
641 642 643 644 645 646
  # 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()
647
    FILE(GLOB subsubdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${subdir}/*)
648
    FOREACH(subsubdir ${subsubdirs})
649 650
      IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${subsubdir}/Logic)
        ADD_SUBDIRECTORY(${subsubdir}/Logic)
651 652
      ENDIF()
    ENDFOREACH()
653 654
  ENDFOREACH()
ENDIF()
655 656


657 658 659
#-----------------------------------------------------------------------------
# Modules and CLI
#
660
option(Slicer_BUILD_CLI "Build Slicer CLI Plugins" ON)
661
IF(Slicer_USE_KWWIDGETS)
662
  option(Slicer_BUILD_MODULES "Build Slicer Modules" ON)
663
ENDIF()
664

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

667
IF(Slicer_USE_KWWIDGETS)
668
  include("${Slicer_CMAKE_DIR}/Slicer3ModulesMacros.cmake")
669
  
670
  IF(Slicer_BUILD_MODULES)
671
    add_subdirectory(Modules)
672
  else(Slicer_BUILD_MODULES)
673
    # if Slicer_BUILD_CLI is ON, we still need at least the CommandLineModule
674
    # so that we can have CLI, without all the other modules
675
    IF(Slicer_BUILD_CLI)
676
      add_subdirectory(Modules/CommandLineModule)
677
    ENDIF(Slicer_BUILD_CLI)
678
  ENDIF(Slicer_BUILD_MODULES)
679
ENDIF()
680 681 682 683

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

686
IF(Slicer_BUILD_MODULES OR Slicer_BUILD_QTLOADABLEMODULES)
687
  include("${Slicer_CMAKE_DIR}/Slicer3ModulesMacros.cmake")
688 689 690 691
  ADD_SUBDIRECTORY(Modules/EMSegment/Algorithm)
  ADD_SUBDIRECTORY(Modules/EMSegment/MRML)
  ADD_SUBDIRECTORY(Modules/EMSegment/Registration)
  ADD_SUBDIRECTORY(Modules/EMSegment/Graph)
692
ENDIF()
693

694 695 696
# 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
697
IF(Slicer_USE_KWWIDGETS)
698
  IF(Slicer_BUILD_MODULES)
699
    ADD_SUBDIRECTORY(Modules/EMSegment)
700
  ENDIF()
701 702
ENDIF()

703
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
704
# Qt Loadable Modules
705
#
706
IF(Slicer_USE_QT AND Slicer_BUILD_QTLOADABLEMODULES)
jcfr's avatar
jcfr committed
707
  add_subdirectory(QTModules)
708
ENDIF()
709

710 711 712 713
#-----------------------------------------------------------------------------
# Applications need to be built after Modules to capture the TractTracing in
# the correct ordering.
#
714
add_subdirectory(Applications)
715

716 717 718
#-----------------------------------------------------------------------------
# Testing
#
719
IF(Slicer_BUILD_TESTING)
720
  add_subdirectory(Testing)
721
ENDIF()
pieper's avatar
pieper committed
722

723
# Install testing data
andy's avatar
andy committed
724

725 726
install(DIRECTORY
  Testing
727
  DESTINATION ${Slicer_INSTALL_SHARE_DIR} COMPONENT Development
728 729 730