CMakeLists.txt 31.8 KB
Newer Older
1
#-----------------------------------------------------------------------------
2
cmake_minimum_required(VERSION 2.8.2)
3 4
#-----------------------------------------------------------------------------

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 38 39
#-----------------------------------------------------------------------------
# Set the header template which defines custom export/import macros
# for shared libraries
#-----------------------------------------------------------------------------
SET(Slicer_EXPORT_HEADER_TEMPLATE "${Slicer_SOURCE_DIR}/qSlicerExport.h.in")
SET(Slicer_LOGOS_RESOURCE "${Slicer_SOURCE_DIR}/Resources/qSlicerLogos.qrc")

40 41 42 43 44 45 46 47 48 49 50 51
#-----------------------------------------------------------------------------
# Update CMake module path
#------------------------------------------------------------------------------

SET(CMAKE_MODULE_PATH
  ${Slicer_SOURCE_DIR}/CMake
  ${Slicer_BINARY_DIR}/CMake
  ${CMAKE_MODULE_PATH}
  )
  
SET(Slicer_CMAKE_DIR "${Slicer_SOURCE_DIR}/CMake" CACHE INTERNAL "")

52 53 54 55 56 57 58 59 60 61 62 63
#-----------------------------------------------------------------------------
# CMake Function(s) and Macro(s)
#-----------------------------------------------------------------------------
INCLUDE(CMakeParseArguments)
INCLUDE(Slicer3PluginsMacros)
INCLUDE(SlicerMacroParseArguments)
INCLUDE(SlicerMacroBuildCLI)
INCLUDE(SlicerMacroEmptyExternalProject)
INCLUDE(SlicerFunctionCheckCompilerFlags)
INCLUDE(SlicerFunctionInstallLibrary)
INCLUDE(SlicerFunctionGetGccVersion)

jcfr's avatar
jcfr committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
#-----------------------------------------------------------------------------
# Platform check
#-----------------------------------------------------------------------------

SET(PLATFORM_CHECK true)

if(PLATFORM_CHECK)
  # See CMake/Modules/Platform/Darwin.cmake)
  #   6.x == Mac OSX 10.2 (Jaguar)
  #   7.x == Mac OSX 10.3 (Panther)
  #   8.x == Mac OSX 10.4 (Tiger)
  #   9.x == Mac OSX 10.5 (Leopard)
  #  10.x == Mac OSX 10.6 (Snow Leopard)
  if (DARWIN_MAJOR_VERSION LESS "8")
    message(FATAL_ERROR "Only Mac OSX >= 10.4 are supported !")
  endif()
endif()

#-----------------------------------------------------------------------------
# Determine endian type
#-----------------------------------------------------------------------------

INCLUDE(TestBigEndian)
test_big_endian(CMAKE_WORDS_BIGENDIAN)

#-----------------------------------------------------------------------------
# Prerequisites
#-----------------------------------------------------------------------------

FIND_PACKAGE(Subversion)
IF(NOT Subversion_FOUND)
  MESSAGE(FATAL_ERROR "error: Install SVN and try to re-configure")
ENDIF()

FIND_PACKAGE(Git)
IF(NOT GIT_FOUND)
  MESSAGE(FATAL_ERROR "error: Install Git and try to re-configure")
ENDIF()

103
SET(Slicer_REQUIRED_QT_VERSION "4.6.2")
jcfr's avatar
jcfr committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

#-----------------------------------------------------------------------------
# Superbuild Option - Enabled by default
#-----------------------------------------------------------------------------

OPTION(Slicer_SUPERBUILD "Build Slicer and the projects it depends on via SuperBuild.cmake." ON)
MARK_AS_ADVANCED(Slicer_SUPERBUILD)

#-----------------------------------------------------------------------------
# Build shared lib by default
#------------------------------------------------------------------------------
# option(BUILD_SHARED_LIBS "Build Slicer with shared libraries." ON)
SET(BUILD_SHARED_LIBS ON)

#-----------------------------------------------------------------------------
# Append the library version information to the library target properties.
#------------------------------------------------------------------------------
OPTION(Slicer_WITH_LIBRARY_VERSION "Build with library version information" OFF)
MARK_AS_ADVANCED(Slicer_WITH_LIBRARY_VERSION)
IF(Slicer_WITH_LIBRARY_VERSION)
  SET(Slicer_LIBRARY_PROPERTIES ${Slicer_LIBRARY_PROPERTIES}
    VERSION ${Slicer_VERSION_FULL}
    SOVERSION ${Slicer_VERSION}
  )
ENDIF()

#-----------------------------------------------------------------------------
# Additional Slicer Options
#-----------------------------------------------------------------------------
OPTION(BUILD_TESTING "Test the project" ON)
OPTION(WITH_MEMCHECK "Run tests through valgrind." OFF)
OPTION(WITH_COVERAGE "Enable/Disable coverage" OFF)
OPTION(Slicer_USE_VTK_DEBUG_LEAKS "Enable VTKs Debug Leaks functionality in both VTK and Slicer." ON)
OPTION(Slicer_BUILD_QTLOADABLEMODULES "Build Slicer QT Loadable Modules" ON)
MARK_AS_ADVANCED(Slicer_BUILD_QTLOADABLEMODULES)
139 140
OPTION(Slicer_BUILD_QTSCRIPTEDMODULES "Build Slicer Python QT Modules" ON)
MARK_AS_ADVANCED(Slicer_BUILD_QTSCRIPTEDMODULES)
jcfr's avatar
jcfr committed
141 142 143 144
OPTION(Slicer_BUILD_CLI       "Build Slicer CLI Plugins" ON)
OPTION(Slicer_USE_PYTHONQT    "Integrate a python-QT interpreter into Slicer." ON)
OPTION(Slicer_USE_PYTHONQT_WITH_TCL "Enable PythonQt Tcl adapter layer" ON)
#MARK_AS_ADVANCED(Slicer_USE_PYTHONQT_WITH_TCL)
145 146 147
OPTION(Slicer_USE_NUMPY       "Build Slicer with NumPy" ON)
#OPTION(Slicer_USE_WEAVE       "Build Slicer with Weave" OFF)
#MARK_AS_ADVANCED(Slicer_USE_WEAVE)
jcfr's avatar
jcfr committed
148 149 150 151
OPTION(Slicer_USE_BatchMake   "Build Slicer with BatchMake support." ON)
OPTION(Slicer_USE_MIDAS       "Build Slicer with MIDAS support." OFF)
OPTION(Slicer_USE_OPENIGTLINK "Build Slicer with OpenIGTLink support." ON)
OPTION(Slicer_USE_OPENCV      "Build Slicer with OpenCV support." OFF)
152
OPTION(Slicer_USE_CTKAPPLAUNCHER "Configure ctkAppLauncher." ON)
jcfr's avatar
jcfr committed
153
MARK_AS_ADVANCED(Slicer_USE_CTKAPPLAUNCHER)
154 155
SET(Slicer_VTK_GIT_REPOSITORY "github.com/Slicer/VTK.git" CACHE STRING "repository from which to get VTK")
MARK_AS_ADVANCED(Slicer_VTK_GIT_REPOSITORY)
156
SET(Slicer_VTK_GIT_TAG "origin/slicer-4.0-gamma" CACHE STRING "VTK git tag to use")
157
MARK_AS_ADVANCED(Slicer_VTK_GIT_TAG)
158
SET(Slicer_ITK_GIT_REPOSITORY "github.com/Slicer/ITK.git" CACHE STRING "repository from which to get ITK")
159
MARK_AS_ADVANCED(Slicer_ITK_GIT_REPOSITORY)
160 161
SET(Slicer_ITK_GIT_TAG "origin/slicer-4.0" CACHE STRING "ITK git tag to use")
MARK_AS_ADVANCED(Slicer_ITK_GIT_TAG)
jcfr's avatar
jcfr committed
162 163 164 165

# Slicer implicitly uses Qt
SET(Slicer_USE_QT ON CACHE INTERNAL "Build Slicer with Qt")

166 167 168 169 170 171 172 173 174 175 176 177 178 179
#-----------------------------------------------------------------------------
# Documentation
#-----------------------------------------------------------------------------

OPTION(DOCUMENTATION_TARGET_IN_ALL "Include the custom target for building documentation in 'all'" OFF)
MARK_AS_ADVANCED(DOCUMENTATION_TARGET_IN_ALL)

SET(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 CACHE PATH "Where documentation archives should be stored")
MARK_AS_ADVANCED(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)

# Attempt to discover Doxygen so that DOXYGEN_EXECUTABLE is set to an appropriate default value
FIND_PACKAGE(Doxygen QUIET)

180 181 182 183 184 185 186 187 188 189
#-----------------------------------------------------------------------------
# CTestCustom
#-----------------------------------------------------------------------------
IF(BUILD_TESTING)
  CONFIGURE_FILE(
    CMake/CTestCustom.cmake.in
    ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake 
    @ONLY)
ENDIF()

jcfr's avatar
jcfr committed
190
#-----------------------------------------------------------------------------
191 192 193 194 195 196 197 198
# Additional CXX/C Flags
#-----------------------------------------------------------------------------

SET(ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags")
MARK_AS_ADVANCED(ADDITIONAL_C_FLAGS)
SET(ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags")
MARK_AS_ADVANCED(ADDITIONAL_CXX_FLAGS)

199 200 201 202 203 204 205 206 207 208 209
#-----------------------------------------------------------------------------
# Set coverage Flags
#-----------------------------------------------------------------------------
IF(WITH_COVERAGE)
  IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    SET(coverage_flags "-g -fprofile-arcs -ftest-coverage -O0 -DNDEBUG")
    SET(COVERAGE_CXX_FLAGS ${coverage_flags})
    SET(COVERAGE_C_FLAGS ${coverage_flags})
  ENDIF()
ENDIF()

210 211 212
#-----------------------------------------------------------------------------
# Slicer C/CXX Flags
#-----------------------------------------------------------------------------
213 214
SET(Slicer_C_FLAGS "${CMAKE_C_FLAGS_INIT} ${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}")
SET(Slicer_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}")
215 216 217 218

IF(CMAKE_COMPILER_IS_GNUCXX)
  SET(cflags "-Wall -Wextra -Wpointer-arith -Winvalid-pch -Wcast-align -Wwrite-strings -D_FORTIFY_SOURCE=2")
  SlicerFunctionCheckCompilerFlags("-fdiagnostics-show-option" cflags)
219
  SlicerFunctionCheckCompilerFlags("-Wl,--no-undefined" cflags)
220 221 222 223 224
  
  slicerFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
  # With older version of gcc supporting the flag -fstack-protector-all, an extra dependency to libssp.so
  # is introduced. If gcc is smaller than 4.4.0 and the build type is Release let's not include the flag.
  # Doing so should allow to build package made for distribution using older linux distro.
225
  IF(GCC_VERSION VERSION_GREATER "4.4.0" OR (CMAKE_BUILD_TYPE STREQUAL "Debug" AND GCC_VERSION VERSION_LESS "4.4.0"))
226 227
    SlicerFunctionCheckCompilerFlags("-fstack-protector-all" cflags)
  ENDIF()
228 229 230 231
  IF(MINGW)
    # suppress warnings about auto imported symbols
    SET(Slicer_CXX_FLAGS "-Wl,--enable-auto-import ${Slicer_CXX_FLAGS}")
  ENDIF()
232 233

  # Note: -Wold-style-cast is too verbose
234
  #       Let's postpone the use of -Wsign-promo 
235
  SET(Slicer_C_FLAGS "${cflags} ${Slicer_C_FLAGS}")
236
  SET(Slicer_CXX_FLAGS "${cflags} -Wno-deprecated -Woverloaded-virtual -Wstrict-null-sentinel ${Slicer_CXX_FLAGS}")
237 238 239 240
ELSEIF(MSVC)
  SET(cflags "/Zm1000 /W3")
  SET(Slicer_C_FLAGS "${cflags} ${Slicer_C_FLAGS}")
  SET(Slicer_CXX_FLAGS "${cflags} /EHsc /GR ${Slicer_CXX_FLAGS}")
241 242
ENDIF()

243 244 245 246 247 248 249 250 251
#-----------------------------------------------------------------------------
# Slicer install directories
#------------------------------------------------------------------------------

SET(Slicer_INSTALL_BIN_DIR "bin")
SET(Slicer_INSTALL_LIB_DIR "lib/Slicer3")
SET(Slicer_INSTALL_INCLUDE_DIR "include/Slicer")
SET(Slicer_INSTALL_SHARE_DIR "share/Slicer")
SET(Slicer_INSTALL_ITKFACTORIES_DIR "${Slicer_INSTALL_LIB_DIR}/ITKFactories")
252
# Set to create Bundle in a directory
253
SET(Slicer_BUNDLE_LOCATION ".")
254

255
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
256 257 258 259 260 261 262 263
# Superbuild script
#-----------------------------------------------------------------------------

IF(Slicer_SUPERBUILD)
  INCLUDE("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake")
  RETURN()
ENDIF()

jcfr's avatar
jcfr committed
264 265
#-----------------------------------------------------------------------------
# Output directories.
jcfr's avatar
jcfr committed
266 267
#------------------------------------------------------------------------------

jcfr's avatar
jcfr committed
268 269 270
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Slicer_BINARY_DIR}/bin)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Slicer_BINARY_DIR}/bin)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Slicer_BINARY_DIR}/lib)
271

272 273 274
#-----------------------------------------------------------------------------
# Today date
#-----------------------------------------------------------------------------
275
INCLUDE(SlicerFunctionToday)
276 277
TODAY(Slicer_BUILDDATE)

jcfr's avatar
jcfr committed
278 279 280 281 282 283
#-----------------------------------------------------------------------------
# Slicer version number.
#-----------------------------------------------------------------------------

SET(Slicer_VERSION_MAJOR "4")
SET(Slicer_VERSION_MINOR "0")
284

jcfr's avatar
jcfr committed
285
IF(NOT Slicer_VERSION_PATCH)
286
  SET(Slicer_VERSION_PATCH "gamma-${Slicer_BUILDDATE}")
jcfr's avatar
jcfr committed
287
ENDIF()
288

jcfr's avatar
jcfr committed
289 290 291
SET(Slicer_VERSION      "${Slicer_VERSION_MAJOR}.${Slicer_VERSION_MINOR}")
SET(Slicer_VERSION_FULL "${Slicer_VERSION}.${Slicer_VERSION_PATCH}")

292
#-----------------------------------------------------------------------------
293
# Plugins and Modules install directories
jcfr's avatar
jcfr committed
294 295 296 297 298 299 300
#------------------------------------------------------------------------------

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")
301

jcfr's avatar
jcfr committed
302 303 304 305
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")
306

jcfr's avatar
jcfr committed
307
SET(Slicer_HOME "${Slicer_BINARY_DIR}")
308 309

#-----------------------------------------------------------------------------
310 311
# Disable the warnings that DevStudio 2005 emits wrt to sprintf, strcpu, etc.
#
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
# 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
          )
331 332 333 334
      ENDIF()
    ENDIF()
  ENDIF()
ENDIF()
335

336 337
# Disable warning C4996: [...] This function or variable may be unsafe. [...]
# To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details
338
IF(MSVC90)
339
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
340
ENDIF()
341

342
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
343 344
# Avoid linker bug in Mac OS 10.5
# See http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
345
#
346
IF(APPLE)
jcfr's avatar
jcfr committed
347 348
  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")
349
ENDIF()
350

351 352
#-----------------------------------------------------------------------------
# Slicer include and libraries subdirectory
353 354
#

355 356 357 358 359 360 361 362 363
SET(Slicer_Libs_LIBRARIES CACHE INTERNAL "Slicer Libs libraries" FORCE)
SET(Slicer_Base_LIBRARIES CACHE INTERNAL "Slicer Base libraries" FORCE)
SET(Slicer_Modules_LIBRARIES CACHE INTERNAL "Slicer Modules libraries" FORCE)
SET(Slicer_QTModules_LIBRARIES CACHE INTERNAL "Slicer QTModules libraries" FORCE)

SET(Slicer_Libs_INCLUDE_DIRS CACHE INTERNAL "Slicer Libs includes" FORCE)
SET(Slicer_Base_INCLUDE_DIRS CACHE INTERNAL "Slicer Base includes" FORCE)
SET(Slicer_Modules_INCLUDE_DIRS CACHE INTERNAL "Slicer Modules includes" FORCE)
SET(Slicer_QTModules_INCLUDE_DIRS CACHE INTERNAL "Slicer QTModules includes" FORCE)
pieper's avatar
pieper committed
364

365 366
#-----------------------------------------------------------------------------
# Get sytem name and architecture
jcfr's avatar
jcfr committed
367 368
#-----------------------------------------------------------------------------

369
SET(Slicer_BUILD NA)
370
INCLUDE(SlicerDiscoverSystemNameAndBits)
371
MESSAGE(STATUS "Slicer_BUILD:${Slicer_BUILD}")
372

373
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
374
# Testing
jcfr's avatar
jcfr committed
375
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
376
IF(BUILD_TESTING)
jcfr's avatar
jcfr committed
377 378 379
  
  SET(LAUNCH_EXE ${Slicer_BINARY_DIR}/Slicer3 --launch)
  
380
  ENABLE_TESTING()
jcfr's avatar
jcfr committed
381
  
382
  INCLUDE(CTest)
383 384 385 386 387
  INCLUDE(MIDAS)
  SET(MIDAS_REST_URL "http://midas.kitware.com/api/rest" CACHE STRING "The MIDAS server where testing data resides")
  SET(MIDAS_KEY_DIR "${Slicer_SOURCE_DIR}/Testing/Data")
  SET(MIDAS_DATA_DIR "${Slicer_BINARY_DIR}/MIDAS_Data")

388 389
  SET(CXX_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
  MARK_AS_ADVANCED(TCL_TCLSH DART_ROOT)
jcfr's avatar
jcfr committed
390 391
    
  CONFIGURE_FILE(
392
    ${Slicer_SOURCE_DIR}/CTestConfig.cmake
jcfr's avatar
jcfr committed
393 394 395
    ${Slicer_BINARY_DIR}/${Slicer_INSTALL_LIB_DIR}/CTestConfig.cmake 
    COPYONLY)
    
396
ENDIF()
hliu's avatar
hliu committed
397

398 399
#-----------------------------------------------------------------------------
# Since modules are KWWidgets based, unset there variables
400 401 402 403 404 405
# Since the module Logic is shared between QTModules and regular Modules,
# the associated BIN, LIB and INCLUDE directory shouldn't be unset
#UNSET(Slicer_INSTALL_MODULES_BIN_DIR)
#UNSET(Slicer_INSTALL_MODULES_LIB_DIR)
#UNSET(Slicer_INSTALL_MODULES_INCLUDE_DIR)
UNSET(Slicer_INSTALL_MODULES_SHARE_DIR)
406

407 408 409
# 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.
jcfr's avatar
jcfr committed
410 411 412
SET(SKIP_VTK_BUILD_SETTINGS_FILE 1)
SET(SKIP_ITK_BUILD_SETTINGS_FILE 1)
SET(SKIP_Teem_BUILD_SETTINGS_FILE 1)
413 414

#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
415 416 417
# Python
#-----------------------------------------------------------------------------

418
IF(Slicer_USE_PYTHONQT)
419 420
  FIND_PACKAGE(PythonLibs REQUIRED)
  FIND_PACKAGE(PythonInterp REQUIRED)
421
ENDIF()
422

423
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
424 425 426 427
# ITK
#-----------------------------------------------------------------------------
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})
428

jcfr's avatar
jcfr committed
429 430 431
#-----------------------------------------------------------------------------
# VTK
#-----------------------------------------------------------------------------
432 433
FIND_PACKAGE(VTK REQUIRED)
IF(NOT VTK_USE_QVTK)
434
  MESSAGE(FATAL_ERROR "error: VTK was not configured to use QT, you probably need to recompile it with VTK_USE_GUISUPPORT ON, VTK_USE_QVTK ON, DESIRED_QT_VERSION 4 and QT_QMAKE_EXECUTABLE set appropriatly. Note that Qt >= ${Slicer_REQUIRED_QT_VERSION} is *required*")
435
ENDIF()
436
INCLUDE(${VTK_USE_FILE})
437 438

#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
439
# Qt 
440
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
441
IF(Slicer_USE_QT)
442 443 444 445 446 447 448

  # Module name should be specified as they appear in FindQt4.cmake
  # For example, the module name associated with the variable QT_USE_QTXML is XML.
  SET(Slicer_REQUIRED_QT_MODULES CORE GUI NETWORK)
  IF(BUILD_TESTING)
    LIST(APPEND Slicer_REQUIRED_QT_MODULES TEST)
  ENDIF()
jcfr's avatar
jcfr committed
449
  
450
  INCLUDE(SlicerFindQtAndCheckVersion)
451
ENDIF()
452 453

#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
454 455 456 457 458
# CTK
#-----------------------------------------------------------------------------

IF(Slicer_USE_QT)
  FIND_PACKAGE(CTK REQUIRED)
459 460
  INCLUDE(${CTK_USE_FILE})
  # Update CMake module path
461 462 463 464 465
  SET(CMAKE_MODULE_PATH
    ${VTK_CMAKE_DIR}
    ${CTK_CMAKE_DIR} 
    ${CMAKE_MODULE_PATH} 
    ${CTK_CMAKE_UTILITIES_DIR})
466
ENDIF()
467

468
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
469 470
# PythonQt
#-----------------------------------------------------------------------------
471
IF(Slicer_USE_QT)
472
  IF(Slicer_USE_PYTHONQT)
473
    IF(NOT VTK_WRAP_PYTHON)
474
      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.")
475
    ENDIF()
476 477 478

    SET(PYTHONQT_INSTALL_DIR ${CTK_PYTHONQT_INSTALL_DIR})
    LINK_DIRECTORIES(${PYTHONQT_INSTALL_DIR}/lib)
479 480
    INCLUDE(ctkMacroWrapPythonQt)
    INCLUDE(ctkMacroCompilePythonScript)
481
    
482
    # Enable qMRMLWidgets python wrapping
483
    SET(qMRMLWidgets_WRAP_PYTHON ON)
484 485
  ENDIF()
ENDIF()
486

487
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
488 489 490 491
# Teem
#-----------------------------------------------------------------------------
FIND_PACKAGE(Teem REQUIRED)
INCLUDE(${Teem_USE_FILE})
492

493
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
494 495 496
# SlicerLibCurl
#-----------------------------------------------------------------------------
FIND_PACKAGE(SLICERLIBCURL REQUIRED)
497
INCLUDE(${SLICERLIBCURL_USE_FILE})
498

499 500 501 502 503
#-----------------------------------------------------------------------------
# LibArchive
#-----------------------------------------------------------------------------
FIND_PACKAGE(LibArchive REQUIRED)

504
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
505 506
# BatchMake
#-----------------------------------------------------------------------------
507
IF(Slicer_USE_BatchMake)
jcfr's avatar
jcfr committed
508 509
  FIND_PACKAGE(BatchMake REQUIRED)
  INCLUDE(${BatchMake_USE_FILE})
510
ENDIF()
511

512
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
513
# OpenIGTLink
514
#-----------------------------------------------------------------------------
515
IF(Slicer_USE_OPENIGTLINK)
jcfr's avatar
jcfr committed
516 517
  FIND_PACKAGE(OpenIGTLink REQUIRED)
  INCLUDE(${OpenIGTLink_USE_FILE})
518
ENDIF()
hliu's avatar
hliu committed
519

520
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
521 522
# OpenCV (Built in Slicer3-lib)
#-----------------------------------------------------------------------------
523
IF(Slicer_USE_OPENCV)
jcfr's avatar
jcfr committed
524
  FIND_PACKAGE(OpenCV REQUIRED)
525 526 527 528

  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})
529
  ENDIF()
530 531 532 533 534 535 536 537 538 539 540 541 542
  
  # 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})
jcfr's avatar
jcfr committed
543
  #INCLUDE(${OPENCV_USE_FILE})
544
ENDIF()
545

546 547
#-----------------------------------------------------------------------------
# Need some Tcl/Tk info
jcfr's avatar
jcfr committed
548
#-----------------------------------------------------------------------------
549 550 551 552 553 554 555 556 557
# 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
SET(TCL_TK_VERSION_DOT "8.4")
SET(TCL_TK_VERSION "84")
SET(INCR_TCL_VERSION_DOT "3.2")
SET(INCR_TCL_VERSION "32")
558

559
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
560 561 562 563 564 565 566
# Set Slicer buildin libraries *_DIR variables
#-----------------------------------------------------------------------------
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(vtkITK_DIR ${Slicer_BINARY_DIR}/Libs/vtkITK)
567

jcfr's avatar
jcfr committed
568
#-----------------------------------------------------------------------------
569
# Qt Loadable and Scripted Modules
jcfr's avatar
jcfr committed
570
#-----------------------------------------------------------------------------
571
IF(Slicer_USE_QT)
572
  IF(Slicer_BUILD_QTLOADABLEMODULES)
jcfr's avatar
jcfr committed
573 574 575 576
    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")
577
  ENDIF()
578 579 580 581 582 583
  IF(Slicer_BUILD_QTSCRIPTEDMODULES)
    SET(Slicer_INSTALL_QTSCRIPTEDMODULES_BIN_DIR "${Slicer_INSTALL_LIB_DIR}/QTScriptedModules")
    SET(Slicer_INSTALL_QTSCRIPTEDMODULES_LIB_DIR "${Slicer_INSTALL_LIB_DIR}/QTScriptedModules")
    SET(Slicer_INSTALL_QTSCRIPTEDMODULES_INCLUDE_DIR "${Slicer_INSTALL_INCLUDE_DIR}/QTScriptedModules")
    SET(Slicer_INSTALL_QTSCRIPTEDMODULES_SHARE_DIR "${Slicer_INSTALL_SHARE_DIR}/QTScriptedModules")
  ENDIF()
584
ENDIF()
jcfr's avatar
jcfr committed
585

586 587
# --------------------------------------------------------------------------
# Configure and install headers
jcfr's avatar
jcfr committed
588 589 590 591 592 593 594 595 596 597
# --------------------------------------------------------------------------
SET(files 
  vtkSlicerConfigure.h
  vtkSlicerVersionConfigure.h
  Scripts/runValgrind.sh
  Scripts/runValgrindForOneModule.sh
  Scripts/runValgrindForOneModuleWithSlicer4AndQT.sh
  Scripts/computeCodeCoverageLocally.sh
  Scripts/computeCodeCoverageForOneTest.sh
  Scripts/runExperimentalOffScreen.sh
598
  )
jcfr's avatar
jcfr committed
599 600 601 602 603 604
FOREACH(f ${files})
  CONFIGURE_FILE(
    ${CMAKE_CURRENT_SOURCE_DIR}/${f}.in
    ${CMAKE_CURRENT_BINARY_DIR}/${f}
    )
ENDFOREACH()
605 606

INSTALL(FILES 
607
  "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h"
608
  "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerVersionConfigure.h"
609
  DESTINATION ${Slicer_INSTALL_INCLUDE_DIR} COMPONENT Development
610
  )
611 612 613 614 615 616 617

#-----------------------------------------------------------------------------
# Set C/CXX Flags
#-----------------------------------------------------------------------------
SET(CMAKE_CXX_FLAGS ${Slicer_CXX_FLAGS} CACHE STRING "CMake C Flags" FORCE)
SET(CMAKE_C_FLAGS ${Slicer_C_FLAGS} CACHE STRING "CMake CXX Flags" FORCE)

618
#-----------------------------------------------------------------------------
619
# Generate SlicerVersion.txt
jcfr's avatar
jcfr committed
620
#-----------------------------------------------------------------------------
621

622
# Note that Slicer_BUILD is set above
623

624 625
SET(Slicer_WC_URL NA)
SET(Slicer_WC_REVISION 0)
626 627

# Case where Slicer is checkout using SVN
628
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.svn)
629
  Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} Slicer)
630
  CONFIGURE_FILE(
631
    ${CMAKE_CURRENT_SOURCE_DIR}/SlicerVersion.txt.in
632
    ${Slicer_HOME}/lib/Slicer3/SlicerVersion.txt
633 634 635 636
    )
ENDIF()

# Case where Slicer is checkout using Git-SVN
637 638
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/svn/refs/remotes)
  GIT_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} Slicer)
639
  CONFIGURE_FILE(
640 641
    ${CMAKE_CURRENT_SOURCE_DIR}/SlicerVersion.txt.in
    ${Slicer_HOME}/lib/Slicer3/SlicerVersion.txt
642 643 644
    )
ENDIF()

645

jcfr's avatar
jcfr committed
646 647 648 649 650 651 652 653 654
#-----------------------------------------------------------------------------
# Includes
#-----------------------------------------------------------------------------

INCLUDE_DIRECTORIES(
  "${CMAKE_CURRENT_SOURCE_DIR}"
  "${CMAKE_CURRENT_BINARY_DIR}"
  )
  
655
#-----------------------------------------------------------------------------
pieper's avatar
pieper committed
656
# Subdirectories
jcfr's avatar
jcfr committed
657 658 659 660 661
#-----------------------------------------------------------------------------

ADD_SUBDIRECTORY(Libs)
ADD_SUBDIRECTORY(Base)
ADD_SUBDIRECTORY(Resources)
662

663 664
#-----------------------------------------------------------------------------
# Module Logic
jcfr's avatar
jcfr committed
665
#-----------------------------------------------------------------------------
666

667
INCLUDE(SlicerMacroBuildModuleLogic)
668

669 670 671 672 673 674 675 676 677 678 679 680 681
# 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:
# 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()
  FILE(GLOB subsubdirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${subdir}/*)
  FOREACH(subsubdir ${subsubdirs})
    IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${subsubdir}/Logic)
      ADD_SUBDIRECTORY(${subsubdir}/Logic)
682 683
    ENDIF()
  ENDFOREACH()
684
ENDFOREACH()
685

686
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
687
# Qt Loadable Modules
jcfr's avatar
jcfr committed
688 689
#-----------------------------------------------------------------------------

690
IF(Slicer_USE_QT AND Slicer_BUILD_QTLOADABLEMODULES)
jcfr's avatar
jcfr committed
691
  ADD_SUBDIRECTORY(QTModules)
692
ENDIF()
693

694 695 696 697
IF(Slicer_USE_PYTHONQT AND Slicer_BUILD_QTSCRIPTEDMODULES)
  ADD_SUBDIRECTORY(QTScriptedModules)
ENDIF()

698
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
699 700 701 702
# Applications - Added after Modules to capture the TractTracing in the correct ordering.
#-----------------------------------------------------------------------------

ADD_SUBDIRECTORY(Applications)
703

704 705
#-----------------------------------------------------------------------------
# Testing
jcfr's avatar
jcfr committed
706 707
#-----------------------------------------------------------------------------

jcfr's avatar
jcfr committed
708
IF(BUILD_TESTING)
jcfr's avatar
jcfr committed
709
  ADD_SUBDIRECTORY(Testing)
710
ENDIF()
pieper's avatar
pieper committed
711

712
# Install testing data
andy's avatar
andy committed
713

jcfr's avatar
jcfr committed
714
INSTALL(DIRECTORY
715
  Testing
716
  DESTINATION ${Slicer_INSTALL_SHARE_DIR} COMPONENT Development
717 718 719 720 721
  PATTERN ".svn" EXCLUDE
  PATTERN "CMakeLists.txt" EXCLUDE
  )

#-----------------------------------------------------------------------------
722
# Launcher for slicer
jcfr's avatar
jcfr committed
723
#-----------------------------------------------------------------------------
724

725 726
# let's build the launcher for Kww, KwwAndQt and also QtOnly slicer ...
ADD_SUBDIRECTORY(Utilities/Launcher)
727

728
IF(Slicer_USE_QT)
729 730 731 732 733 734

  # 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})
735
      IF(QT_${qtlib}_LIBRARY_RELEASE AND APPLE)
736
          GET_FILENAME_COMPONENT(QT_FRAMEWORK_NAME_tmp ${QT_${qtlib}_LIBRARY_RELEASE} NAME)
737
          SET(Slicer_QT_FRAMEWORK_DIRS "lib/Qt/${QT_FRAMEWORK_NAME_tmp}/Versions/4:${Slicer_QT_FRAMEWORK_DIRS}")
738
      ENDIF()
739 740 741
    ENDFOREACH()
  ENDIF()

742
ENDIF(Slicer_USE_QT)
743

744
CONFIGURE_FILE(
745 746
  ${Slicer_SOURCE_DIR}/launch.tcl.in
  "${Slicer_BINARY_DIR}/${Slicer_INSTALL_LIB_DIR}/launch.tcl"
747 748
  )
INSTALL(
749
  FILES "${Slicer_BINARY_DIR}/${Slicer_INSTALL_LIB_DIR}/launch.tcl"
750
  DESTINATION ${Slicer_INSTALL_LIB_DIR}
751
  )
752

753 754
#-----------------------------------------------------------------------------
# Launcher for QTDesigner
jcfr's avatar
jcfr committed
755
#-----------------------------------------------------------------------------
756

757
IF(Slicer_USE_QT)
jcfr's avatar
jcfr committed
758
  ADD_SUBDIRECTORY(Utilities/Designer)
759
ENDIF()
760

761
#-----------------------------------------------------------------------------
762
# Package slicer
jcfr's avatar
jcfr committed
763 764 765
#-----------------------------------------------------------------------------

ADD_SUBDIRECTORY(Utilities/Package)
andy's avatar
andy committed
766

767
#-----------------------------------------------------------------------------
768
# Documentation
jcfr's avatar
jcfr committed
769 770
#-----------------------------------------------------------------------------

771
ADD_SUBDIRECTORY(Utilities/Doxygen)
andy's avatar
andy committed
772

jcfr's avatar
jcfr committed
773 774
# Add CMake directory so that install rules associated with *.cmake files are evaluated
ADD_SUBDIRECTORY(CMake)
775

776
#-----------------------------------------------------------------------------
777
# Set up for building against a Slicer build tree and a Slicer installation 
778
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
779
INCLUDE(${Slicer_SOURCE_DIR}/GenerateSlicerConfig.cmake)
780

jcfr's avatar
jcfr committed
781
CONFIGURE_FILE(${Slicer_SOURCE_DIR}/UseSlicer.cmake.in
782
  ${Slicer_BINARY_DIR}/UseSlicer.cmake COPYONLY IMMEDIATE)
783

jcfr's avatar
jcfr committed
784
INSTALL(FILES
785
  #   ${Slicer_BINARY_DIR}/Slicer3BuildSettings.cmake
786 787
  ${Slicer_BINARY_DIR}/UseSlicer.cmake
  ${Slicer_BINARY_DIR}/Utilities/SlicerConfig.cmake
788
  ${Slicer_BINARY_DIR}/lib/Slicer3/SlicerVersion.txt
789
  DESTINATION ${Slicer_INSTALL_LIB_DIR}
790 791
  COMPONENT Development
  )