CMakeLists.txt 43.2 KB
Newer Older
1
#-----------------------------------------------------------------------------
2
cmake_minimum_required(VERSION 2.8.4)
3
#-----------------------------------------------------------------------------
4 5 6 7 8 9
if(APPLE)
  # Note: By setting CMAKE_OSX_* variables before any enable_language() or project() calls,
  #       we ensure that the bitness will be properly detected.
  include(${CMAKE_SOURCE_DIR}/CMake/SlicerBlockSetCMakeOSXVariables.cmake)
endif()

10
project(Slicer)
11

12 13 14
#-----------------------------------------------------------------------------
# See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details
#-----------------------------------------------------------------------------
15
if(POLICY CMP0017)
16
  cmake_policy(SET CMP0017 OLD)
17
endif()
18

jcfr's avatar
jcfr committed
19 20 21 22 23 24 25 26 27 28 29 30
#-----------------------------------------------------------------------------
# Update CMake module path
#------------------------------------------------------------------------------
set(CMAKE_MODULE_PATH
  ${Slicer_SOURCE_DIR}/CMake
  ${Slicer_SOURCE_DIR}/Extensions/CMake
  ${CMAKE_MODULE_PATH}
  )

set(Slicer_CMAKE_DIR ${Slicer_SOURCE_DIR}/CMake)
set(Slicer_EXTENSIONS_CMAKE_DIR ${Slicer_SOURCE_DIR}/Extensions/CMake)

31 32 33 34 35 36
#-----------------------------------------------------------------------------
include(CTestUseLaunchers OPTIONAL)
if(${CTEST_USE_LAUNCHERS})
  message(STATUS "CTest launchers enabled")
endif()

37 38 39 40 41 42 43 44
#-----------------------------------------------------------------------------
# VAriable Slicer_LANGUAGES
#-----------------------------------------------------------------------------
set(Slicer_LANGUAGES
  "fr"
  )
set_property(GLOBAL PROPERTY Slicer_LANGUAGES ${Slicer_LANGUAGES})

jcfr's avatar
jcfr committed
45 46 47
#-----------------------------------------------------------------------------
# Sanity checks
#------------------------------------------------------------------------------
48
if(WIN32)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  option(Slicer_SKIP_ROOT_DIR_MAX_LENGTH_CHECK "Skip root directory length check" OFF)
  mark_as_advanced(Slicer_SKIP_ROOT_DIR_MAX_LENGTH_CHECK)
  if(NOT Slicer_SKIP_ROOT_DIR_MAX_LENGTH_CHECK)
    set(root_directory_max_length 40)
    string(LENGTH "${CMAKE_CURRENT_SOURCE_DIR}" n)
    if(n GREATER ${root_directory_max_length})
      message(
        FATAL_ERROR
        "Source tree directory of ${PROJECT_NAME} is too deep (${n} > ${root_directory_max_length})."
        "Please use a shorter root directory for the ${PROJECT_NAME} source tree."
        )
    endif()
    string(LENGTH "${CMAKE_CURRENT_BINARY_DIR}" n)
    if(n GREATER ${root_directory_max_length})
      message(
        FATAL_ERROR
        "Binary tree directory of ${PROJECT_NAME} is too deep (${n} > ${root_directory_max_length})."
        "Please use a shorter root directory for the ${PROJECT_NAME} binary tree."
        )
    endif()
69 70
  endif()
endif()
jcfr's avatar
jcfr committed
71
include(PreventInSourceBuilds)
jcfr's avatar
jcfr committed
72
include(PreventInBuildInstalls)
jcfr's avatar
jcfr committed
73

74 75 76 77 78 79 80
if(NOT DEFINED Slicer_SKIP_DIR_WITH_SPACES_CHECK)
  set(Slicer_SKIP_DIR_WITH_SPACES_CHECK FALSE)
endif()
if(NOT Slicer_SKIP_DIR_WITH_SPACES_CHECK)
  include(PreventDirWithSpaces)
endif()

81 82 83 84 85 86 87 88
#-----------------------------------------------------------------------------
# Overwrite default options
#-----------------------------------------------------------------------------
set(_overwrite_options_file ${Slicer_CMAKE_DIR}/SlicerOverwriteDefaultOptions.cmake)
if(EXISTS ${_overwrite_options_file})
  include(${_overwrite_options_file})
endif()

89 90 91
#-----------------------------------------------------------------------------
# Check if the linker will resolve symbols of underlinked libraries
#-----------------------------------------------------------------------------
92
if(UNIX AND NOT APPLE)
93 94 95 96 97 98 99 100
  include(SlicerLinkerAsNeededFlagCheck)
  if(Slicer_LINKER_NO_AS_NEEDED_FLAG_REQUIRED)
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-as-needed"
      CACHE STRING "Flags used by the linker"
      FORCE)
  endif()
endif()

101 102 103 104 105 106 107 108 109 110 111
#-----------------------------------------------------------------------------
# Set a default build type if none was specified
#-----------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "Setting build type to 'Debug' as none was specified.")
  set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
  # Set the possible values of build type for cmake-gui
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
    "MinSizeRel" "RelWithDebInfo")
endif()

112 113 114 115
#-----------------------------------------------------------------------------
# Set the header template which defines custom export/import macros
# for shared libraries
#-----------------------------------------------------------------------------
116
set(Slicer_EXPORT_HEADER_TEMPLATE "${Slicer_SOURCE_DIR}/CMake/qSlicerExport.h.in")
117
set(Slicer_LOGOS_RESOURCE "${Slicer_SOURCE_DIR}/Resources/qSlicer.qrc")
118

119 120 121
#-----------------------------------------------------------------------------
# CMake Function(s) and Macro(s)
#-----------------------------------------------------------------------------
122
include(CMakeDependentOption)
123
include(CMakeParseArguments)
124 125
include(Slicer3PluginsMacros)
include(SlicerMacroExtractRepositoryInfo)
126
include(SlicerMacroGetOperatingSystemArchitectureBitness)
127 128
include(SlicerMacroParseArguments)
include(SlicerMacroEmptyExternalProject)
129
include(SlicerMacroTranslation)
130
include(SlicerFunctionInstallLibrary)
131

132
#-----------------------------------------------------------------------------
133
# Platform checks
134
#-----------------------------------------------------------------------------
135
include(SlicerBlockPlatformCheck)
136 137 138 139

#-----------------------------------------------------------------------------
# Determine endian type
#-----------------------------------------------------------------------------
140
include(TestBigEndian)
141 142 143 144 145
test_big_endian(CMAKE_WORDS_BIGENDIAN)

#-----------------------------------------------------------------------------
# Prerequisites
#-----------------------------------------------------------------------------
146 147 148 149
find_package(Subversion)
if(NOT Subversion_FOUND)
  message(FATAL_ERROR "error: Install SVN and try to re-configure")
endif()
150

151 152 153 154
find_package(Git)
if(NOT GIT_FOUND)
  message(FATAL_ERROR "error: Install Git and try to re-configure")
endif()
155

156 157 158
#-----------------------------------------------------------------------------
# Qt - Slicer_REQUIRED_QT_VERSION
#-----------------------------------------------------------------------------
159
if(NOT DEFINED Slicer_REQUIRED_QT_VERSION)
160
  set(Slicer_REQUIRED_QT_VERSION "4.7.4" CACHE STRING "Exact required Qt version" FORCE)
161
endif()
162 163 164 165

#-----------------------------------------------------------------------------
# Superbuild Option - Enabled by default
#-----------------------------------------------------------------------------
166 167
option(Slicer_SUPERBUILD "Build Slicer and the projects it depends on via SuperBuild.cmake." ON)
mark_as_advanced(Slicer_SUPERBUILD)
168

169 170
set(Slicer_BINARY_INNER_SUBDIR Slicer-build)

171 172 173 174
#-----------------------------------------------------------------------------
# Build shared lib by default
#------------------------------------------------------------------------------
# option(BUILD_SHARED_LIBS "Build Slicer with shared libraries." ON)
175
set(BUILD_SHARED_LIBS ON)
176 177 178 179

#-----------------------------------------------------------------------------
# Append the library version information to the library target properties.
#------------------------------------------------------------------------------
180 181 182 183
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}
184 185 186
    VERSION ${Slicer_VERSION_FULL}
    SOVERSION ${Slicer_VERSION}
  )
187
endif()
188 189

#-----------------------------------------------------------------------------
190
# General Slicer Options
191
#-----------------------------------------------------------------------------
192 193 194 195
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)
196
option(Slicer_BUILD_DICOM_SUPPORT "Build Slicer with DICOM support" ON)
197
option(Slicer_BUILD_DIFFUSION_SUPPORT "Build Slicer with diffusion (DWI, DTI) support" ON)
198 199
option(Slicer_BUILD_QTLOADABLEMODULES "Build Slicer QT Loadable Modules" ON)
mark_as_advanced(Slicer_BUILD_QTLOADABLEMODULES)
200
option(Slicer_USE_PYTHONQT "Integrate a python-QT interpreter into Slicer." ON)
201 202 203
CMAKE_DEPENDENT_OPTION(
  Slicer_BUILD_QTSCRIPTEDMODULES "Build Slicer Python QT Modules" ON
  "Slicer_USE_PYTHONQT" OFF)
204
mark_as_advanced(Slicer_BUILD_QTSCRIPTEDMODULES)
205 206 207 208 209
option(Slicer_BUILD_CLI_SUPPORT "Build Slicer with CLI support" ON)
CMAKE_DEPENDENT_OPTION(
  Slicer_BUILD_CLI "Build Slicer CLI Plugins" ON
  "Slicer_BUILD_CLI_SUPPORT" OFF
  )
210 211 212 213
CMAKE_DEPENDENT_OPTION(
  Slicer_BUILD_LEGACY_CLI "Build Slicer LEGACY_CLI Plugins" ON
  "Slicer_BUILD_CLI" OFF
  )
214
option(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT "Build Slicer extension manager" ON)
215 216
option(Slicer_UPDATE_TRANSLATION "update translation" OFF )
mark_as_advanced(Slicer_UPDATE_TRANSLATION)
217

218 219 220
set(Slicer_FORCED_WC_REVISION "" CACHE STRING "Overwrite value of auto-discovered Slicer_WC_REVISION")
mark_as_advanced(Slicer_FORCED_WC_REVISION)

221 222 223
#-----------------------------------------------------------------------------
# External projects related options
#-----------------------------------------------------------------------------
224 225 226 227 228 229
CMAKE_DEPENDENT_OPTION(
  Slicer_USE_PYTHONQT_WITH_TCL "Enable PythonQt Tcl adapter layer" ON
  "Slicer_USE_PYTHONQT" OFF)
CMAKE_DEPENDENT_OPTION(
  Slicer_USE_NUMPY "Build Slicer with NumPy" ON
  "Slicer_USE_PYTHONQT" OFF)
230 231 232
# option(Slicer_USE_BatchMake   "Build Slicer with BatchMake support." ON)
set(Slicer_USE_BatchMake OFF CACHE INTERNAL "Build Slicer with BatchMake support." FORCE)
option(Slicer_USE_MIDAS       "Build Slicer with MIDAS support." OFF)
233
option(Slicer_USE_OpenIGTLink "Build Slicer with OpenIGTLink support." ON)
234 235
option(Slicer_USE_CTKAPPLAUNCHER "Configure ctkAppLauncher." ON)
mark_as_advanced(Slicer_USE_CTKAPPLAUNCHER)
236 237
option(Slicer_USE_QtTesting    "Integrate QtTesting framework into Slicer." ON)
mark_as_advanced(Slicer_USE_QtTesting)
238

239 240
set(ITK_VERSION_MAJOR 3 CACHE STRING "Choose the expected ITK major version to build Slicer (3 or 4).")
# Set the possible values of ITK major version for cmake-gui
241
set_property(CACHE ITK_VERSION_MAJOR PROPERTY STRINGS "3" "4")
242 243 244
if(NOT "${ITK_VERSION_MAJOR}" STREQUAL "3" AND NOT "${ITK_VERSION_MAJOR}" STREQUAL "4")
  set(ITK_VERSION_MAJOR 3 CACHE STRING "Choose the expected ITK major version to build Slicer (3 or 4)." FORCE)
  message(WARNING "Setting ITK_VERSION_MAJOR to '3' as an valid value was specified.")
245 246 247 248 249 250 251 252 253 254 255
endif()

set(USE_ITKv3 OFF)
set(USE_ITKv4 ON)
if(${ITK_VERSION_MAJOR} STREQUAL "3")
  set(USE_ITKv3 ON)
  set(USE_ITKv4 OFF)
endif()

CMAKE_DEPENDENT_OPTION(Slicer_USE_SimpleITK "Build Slicer with SimpleITK support" OFF "USE_ITKv4" OFF)

256
#-----------------------------------------------------------------------------
257 258
# The following option has been added for conveniency so that "extension-like"
# module can be enabled/disabled at the superbuild level.
259
CMAKE_DEPENDENT_OPTION(
260
  Slicer_BUILD_BRAINSTOOLS "Build the BRAINS subset of registration and segmentation tools." ON
261
  "Slicer_BUILD_CLI_SUPPORT AND Slicer_BUILD_CLI" OFF)
262
mark_as_advanced(Slicer_BUILD_BRAINSTOOLS)
263

264 265
CMAKE_DEPENDENT_OPTION(
  Slicer_BUILD_ChangeTrackerPy "Build ChangeTrackerPy." ON
266
  "Slicer_BUILD_CLI_SUPPORT AND Slicer_BUILD_QTSCRIPTEDMODULES" OFF)
267 268 269 270
mark_as_advanced(Slicer_BUILD_ChangeTrackerPy)

CMAKE_DEPENDENT_OPTION(
  Slicer_BUILD_EMSegment "Build EMSegment." ON
271
  "Slicer_BUILD_BRAINSTOOLS AND Slicer_BUILD_QTLOADABLEMODULES AND Slicer_USE_PYTHONQT" OFF)
272 273
mark_as_advanced(Slicer_BUILD_EMSegment)

274
CMAKE_DEPENDENT_OPTION(
275
  Slicer_BUILD_OpenIGTLinkIF "Build OpenIGTLinkIF." ON
276 277 278
  "Slicer_BUILD_QTLOADABLEMODULES AND Slicer_USE_OpenIGTLink" OFF)
mark_as_advanced(CLEAR Slicer_BUILD_OpenIGTLinkIF)

279 280 281 282 283 284 285 286
option(Slicer_BUILD_MULTIVOLUME_SUPPORT "Build MultiVolume support." ON)
mark_as_advanced(Slicer_BUILD_MULTIVOLUME_SUPPORT)
CMAKE_DEPENDENT_OPTION(
  Slicer_BUILD_MultiVolumeImporter "Build MultiVolumeImporter." ON
  "Slicer_BUILD_QTSCRIPTEDMODULES AND Slicer_BUILD_MULTIVOLUME_SUPPORT" OFF)
mark_as_advanced(Slicer_BUILD_MultiVolumeImporter)
CMAKE_DEPENDENT_OPTION(
  Slicer_BUILD_MultiVolumeExplorer "Build MultiVolumeExplorer." ON
287
  "Slicer_BUILD_QTLOADABLEMODULES AND Slicer_BUILD_MULTIVOLUME_SUPPORT AND Slicer_USE_PYTHONQT" OFF)
288
mark_as_advanced(Slicer_BUILD_MultiVolumeExplorer)
289

290 291 292 293 294
CMAKE_DEPENDENT_OPTION(
  Slicer_BUILD_SlicerWebGLExport "Build SlicerWebGLExport." ON
  "Slicer_BUILD_QTSCRIPTEDMODULES" OFF)
mark_as_advanced(Slicer_BUILD_SlicerWebGLExport)

hjohnson's avatar
hjohnson committed
295 296 297 298 299
## This does not yet build cleanly in the slicer environment, so turn off by default
CMAKE_DEPENDENT_OPTION(Slicer_BUILD_DWIConvert "Build DWIConvert." OFF
  "Slicer_BUILD_DICOM_SUPPORT" OFF)
mark_as_advanced(Slicer_BUILD_DWIConvert)

300 301 302 303
#-----------------------------------------------------------------------------
# Install no development files by default, but allow the user to get
# them installed by setting Slicer_INSTALL_DEVELOPMENT to true.
#-----------------------------------------------------------------------------
304 305 306 307 308 309 310 311
#option(Slicer_INSTALL_DEVELOPMENT "Install Slicer extension development files." OFF)
#mark_as_advanced(Slicer_INSTALL_DEVELOPMENT)
set(Slicer_INSTALL_DEVELOPMENT OFF)
if(NOT Slicer_INSTALL_DEVELOPMENT)
  set(Slicer_INSTALL_NO_DEVELOPMENT 1)
else()
  set(Slicer_INSTALL_NO_DEVELOPMENT 0)
endif()
312

313 314 315
#-----------------------------------------------------------------------------
# Documentation
#-----------------------------------------------------------------------------
316 317
option(DOCUMENTATION_TARGET_IN_ALL "Include the custom target for building documentation in 'all'" OFF)
mark_as_advanced(DOCUMENTATION_TARGET_IN_ALL)
318

319
set(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
320
 CACHE PATH "Where documentation archives should be stored")
321
mark_as_advanced(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
322 323

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

326 327 328
#-----------------------------------------------------------------------------
# CTestCustom
#-----------------------------------------------------------------------------
329 330
if(BUILD_TESTING)
  configure_file(
331
    CMake/CTestCustom.cmake.in
332
    ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
333
    @ONLY)
334
endif()
335

336
#-----------------------------------------------------------------------------
337 338
# Additional CXX/C Flags
#-----------------------------------------------------------------------------
339 340 341 342
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)
343

344
#-----------------------------------------------------------------------------
345
# Set Slicer_{C,CXX}_REQUIRED_FLAGS variables
346
#-----------------------------------------------------------------------------
347
include(SlicerBlockCXXRequiredFlags)
348

349 350 351 352 353 354 355 356
#-----------------------------------------------------------------------------
# Organization name
#-----------------------------------------------------------------------------
set(Slicer_ORGANIZATION_DOMAIN "www.na-mic.org" CACHE INTERNAL "Organization domain")
set(Slicer_ORGANIZATION_NAME "NA-MIC" CACHE INTERNAL "Organization name")

set(SLICER_REVISION_SPECIFIC_USER_SETTINGS_FILEBASENAME "")

357 358 359
#-----------------------------------------------------------------------------
# Main application
#-----------------------------------------------------------------------------
360 361 362 363 364
if (NOT DEFINED Slicer_MAIN_PROJECT)
  set(Slicer_MAIN_PROJECT SlicerApp CACHE INTERNAL "Main project name")
endif()
if (NOT DEFINED ${Slicer_MAIN_PROJECT}_APPLICATION_NAME)
  set(${Slicer_MAIN_PROJECT}_APPLICATION_NAME Slicer CACHE INTERNAL "Main application name")
365 366
else()
  set(SlicerApp_APPLICATION_NAME Slicer)
367
endif()
368 369 370

set(Slicer_MAIN_PROJECT_APPLICATION_NAME ${${Slicer_MAIN_PROJECT}_APPLICATION_NAME})

371 372 373
#-----------------------------------------------------------------------------
# Slicer version number.
#-----------------------------------------------------------------------------
374
set(Slicer_VERSION_MAJOR "4")
jcfr's avatar
jcfr committed
375
set(Slicer_VERSION_MINOR "2")
finetjul's avatar
finetjul committed
376
set(Slicer_VERSION_PATCH "0")
377
# Releases define a tweak level
jcfr's avatar
jcfr committed
378
#set(Slicer_VERSION_TWEAK 0)
jcfr's avatar
jcfr committed
379
#set(Slicer_VERSION_RC 0)
380

381 382 383 384
SlicerMacroExtractRepositoryInfo(VAR_PREFIX Slicer) # Used to configure vtkSlicerVersionConfigure.h.in
string(REGEX REPLACE ".*([0-9][0-9][0-9][0-9]\\-[0-9][0-9]\\-[0-9][0-9]).*" "\\1"
  Slicer_BUILDDATE "${Slicer_WC_LAST_CHANGED_DATE}")

385 386 387 388
if(NOT Slicer_FORCED_WC_REVISION STREQUAL "")
  set(Slicer_WC_REVISION "${Slicer_FORCED_WC_REVISION}")
endif()

389 390 391
if(NOT DEFINED Slicer_VERSION_TWEAK)
  # if it's not a release, use the date as a tweak
  set(Slicer_VERSION_TWEAK "${Slicer_BUILDDATE}")
392 393
endif()

394 395
set(Slicer_VERSION      "${Slicer_VERSION_MAJOR}.${Slicer_VERSION_MINOR}")
set(Slicer_VERSION_FULL "${Slicer_VERSION}.${Slicer_VERSION_PATCH}")
jcfr's avatar
jcfr committed
396
if(Slicer_VERSION_RC)
finetjul's avatar
finetjul committed
397 398
  set(Slicer_VERSION_FULL "${Slicer_VERSION_FULL}-rc${Slicer_VERSION_RC}")
endif()
jcfr's avatar
jcfr committed
399
if(Slicer_VERSION_TWEAK GREATER 0)
finetjul's avatar
finetjul committed
400
  set(Slicer_VERSION_FULL "${Slicer_VERSION_FULL}-${Slicer_VERSION_TWEAK}")
401
endif()
402
message(STATUS "Building Slicer version [${Slicer_VERSION_FULL}]")
403

404
#-----------------------------------------------------------------------------
405 406
# Slicer sub-directories
#-----------------------------------------------------------------------------
407
set(Slicer_BIN_DIR "bin")
408 409 410
set(Slicer_LIB_DIR "lib/Slicer-${Slicer_VERSION_MAJOR}.${Slicer_VERSION_MINOR}")
set(Slicer_INCLUDE_DIR "include/Slicer-${Slicer_VERSION_MAJOR}.${Slicer_VERSION_MINOR}")
set(Slicer_SHARE_DIR "share/Slicer-${Slicer_VERSION_MAJOR}.${Slicer_VERSION_MINOR}")
411
set(Slicer_ITKFACTORIES_DIR "${Slicer_LIB_DIR}/ITKFactories")
412
set(Slicer_QM_DIR "${Slicer_BIN_DIR}/Translations")
413

414 415 416
if(Slicer_BUILD_CLI_SUPPORT)
  # NOTE: Make sure to update vtkSlicerApplicationLogic::GetModuleShareDirectory()
  #       if the following variables are changed.
417

418
  set(Slicer_CLIMODULES_SUBDIR "cli-modules")
419

420 421 422 423
  set(Slicer_CLIMODULES_BIN_DIR "${Slicer_LIB_DIR}/${Slicer_CLIMODULES_SUBDIR}")
  set(Slicer_CLIMODULES_LIB_DIR "${Slicer_LIB_DIR}/${Slicer_CLIMODULES_SUBDIR}")
  set(Slicer_CLIMODULES_SHARE_DIR "${Slicer_SHARE_DIR}/${Slicer_CLIMODULES_SUBDIR}")
endif()
424

425 426 427
#-----------------------------------------------------------------------------
# Slicer install directories
#-----------------------------------------------------------------------------
428
set(Slicer_INSTALL_ROOT "./")
429
set(Slicer_BUNDLE_LOCATION "${Slicer_MAIN_PROJECT_APPLICATION_NAME}.app/Contents")
430 431 432 433
# NOTE: Make sure to update vtkSlicerApplicationLogic::IsEmbeddedModule if
#       the following variables are changed.
set(Slicer_EXTENSIONS_DIRBASENAME "Extensions")
set(Slicer_EXTENSIONS_DIRNAME "${Slicer_EXTENSIONS_DIRBASENAME}-${Slicer_WC_REVISION}")
434
if(APPLE)
435
  set(Slicer_INSTALL_ROOT "${Slicer_BUNDLE_LOCATION}/") # Set to create Bundle
436
endif()
437

438 439 440 441
set(Slicer_INSTALL_BIN_DIR "${Slicer_INSTALL_ROOT}${Slicer_BIN_DIR}")
set(Slicer_INSTALL_LIB_DIR "${Slicer_INSTALL_ROOT}${Slicer_LIB_DIR}")
set(Slicer_INSTALL_INCLUDE_DIR "${Slicer_INSTALL_ROOT}${Slicer_INCLUDE_DIR}")
set(Slicer_INSTALL_SHARE_DIR "${Slicer_INSTALL_ROOT}${Slicer_SHARE_DIR}")
442
set(Slicer_INSTALL_ITKFACTORIES_DIR "${Slicer_INSTALL_LIB_DIR}/ITKFactories")
443
set(Slicer_INSTALL_QM_DIR "${Slicer_INSTALL_ROOT}${Slicer_QM_DIR}")
444

445 446 447 448 449 450
if(Slicer_BUILD_CLI_SUPPORT)
  set(Slicer_INSTALL_CLIMODULES_BIN_DIR "${Slicer_INSTALL_ROOT}${Slicer_CLIMODULES_BIN_DIR}")
  if(APPLE)
    # HACK - On Mac OSX, since all libraries are fixed using the same "install_name" (specifying the
    # location of the dependent libraries relatively to the location of Slicer executable), it
    # is required for CLI executable to be located at same depth as Slicer executable.
451
    # See also Slicer/CMake/SlicerCPackBundleFixup.cmake.in
452
    #
453
    # A more elegant solution would be to create a "Slicer.framework" on which both "${Slicer_MAIN_PROJECT_APPLICATION_NAME}.app"
454 455 456 457 458 459 460 461 462
    # and the plugins/extensions (or loadable bundles) would depend on.
    #
    # NOTE: Make sure to update 'qSlicerCLIExecutableModuleFactory.cxx' if
    #       the following variable is changed.
    set(Slicer_INSTALL_CLIMODULES_BIN_DIR "${Slicer_INSTALL_ROOT}/${Slicer_CLIMODULES_SUBDIR}")
  endif()
  set(Slicer_INSTALL_CLIMODULES_LIB_DIR "${Slicer_INSTALL_ROOT}${Slicer_CLIMODULES_LIB_DIR}")
  set(Slicer_INSTALL_CLIMODULES_SHARE_DIR "${Slicer_INSTALL_ROOT}${Slicer_CLIMODULES_SHARE_DIR}")
endif()
463

464 465 466 467 468
#-----------------------------------------------------------------------------
# Qt - Slicer_REQUIRED_QT_MODULES
#-----------------------------------------------------------------------------
# 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.
469
set(Slicer_REQUIRED_QT_MODULES CORE GUI NETWORK UITOOLS XML WEBKIT SVG SQL)
470 471 472
if(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT)
  list(APPEND Slicer_REQUIRED_QT_MODULES SCRIPT)
endif()
473 474 475
if(BUILD_TESTING)
  list(APPEND Slicer_REQUIRED_QT_MODULES TEST)
endif()
476

477 478 479 480 481 482
#-----------------------------------------------------------------------------
# Qt plugins (designer, imageformats, ...) relative directories
#-----------------------------------------------------------------------------
set(Slicer_QtPlugins_DIR "lib/QtPlugins")
set(Slicer_INSTALL_QtPlugins_DIR "${Slicer_INSTALL_ROOT}${Slicer_QtPlugins_DIR}")

483 484 485 486 487 488
#-----------------------------------------------------------------------------
# Testing
#-----------------------------------------------------------------------------
if(BUILD_TESTING)
  # NOTE: For CTEST_USE_LAUNCHER to work, it's required to include CTest at the superbuild level.
  #       See http://www.kitware.com/blog/home/post/11
489

490 491 492 493 494 495 496 497 498 499 500 501
  set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1) # Do not add CTest default targets
  include(CTest)

  # Add Experimental target - Adapted from CTestTargets.cmake
  set(__conf_types "")
  if(CMAKE_CONFIGURATION_TYPES)
    # We need to pass the configuration type on the test command line.
    set(__conf_types -C "${CMAKE_CFG_INTDIR}")
  endif()
  add_custom_target(Experimental ${CMAKE_CTEST_COMMAND} ${__conf_types} -D Experimental)
endif()

502
#-----------------------------------------------------------------------------
503 504
# Superbuild script
#-----------------------------------------------------------------------------
505 506 507 508
if(Slicer_SUPERBUILD)
  include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake")
  return()
endif()
509

510 511 512
#-----------------------------------------------------------------------------
# CMake Function(s) and Macro(s)
#-----------------------------------------------------------------------------
513 514 515
if(Slicer_BUILD_CLI_SUPPORT)
  include(SlicerMacroBuildCLI)
endif()
516

517
# Clear SlicerTargets.cmake
518
file(WRITE "${Slicer_BINARY_DIR}/SlicerTargets.cmake"
519
  "# Generated by CMake, do not edit!")
520

521 522 523
#-----------------------------------------------------------------------------
# Output directories.
#------------------------------------------------------------------------------
524 525 526
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Slicer_BINARY_DIR}/${Slicer_BIN_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${Slicer_BINARY_DIR}/${Slicer_BIN_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${Slicer_BINARY_DIR}/${Slicer_LIB_DIR})
527

528
#-----------------------------------------------------------------------------
529
# Slicer Home
530
#------------------------------------------------------------------------------
531
set(Slicer_HOME "${Slicer_BINARY_DIR}")
532 533

#-----------------------------------------------------------------------------
534 535
# Avoid linker bug in Mac OS 10.5
# See http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
536
#
537 538 539 540
if(APPLE)
  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")
endif()
541

542 543
#-----------------------------------------------------------------------------
# Slicer include and libraries subdirectory
544 545
#

546 547 548 549 550
set(Slicer_Base_LIBRARIES CACHE INTERNAL "Slicer Base libraries" FORCE)
set(Slicer_Base_INCLUDE_DIRS CACHE INTERNAL "Slicer Base includes" FORCE)
set(Slicer_ModuleLogic_INCLUDE_DIRS CACHE INTERNAL "Slicer Module logic includes" FORCE)
set(Slicer_ModuleMRML_INCLUDE_DIRS CACHE INTERNAL "Slicer Module MRML includes" FORCE)
set(Slicer_ModuleWidgets_INCLUDE_DIRS CACHE INTERNAL "Slicer Module Widgets includes" FORCE)
551

552
#-----------------------------------------------------------------------------
553
# Get operating system, architecture and bitness
554
#-----------------------------------------------------------------------------
555 556
SlicerMacroGetOperatingSystemArchitectureBitness(VAR_PREFIX Slicer)
message(STATUS "Configuring Slicer for ${Slicer_OS}-${Slicer_ARCHITECTURE}")
557

558 559 560 561 562 563 564 565 566
#-----------------------------------------------------------------------------
# ExternalData configuration for test data
#-----------------------------------------------------------------------------
list(APPEND ExternalData_URL_TEMPLATES "http://slicer.kitware.com/midas3/api/rest?method=midas.bitstream.download&checksum=%(hash)")
set(ExternalData_OBJECT_STORES ${Slicer_BINARY_DIR}/ExternalData/Objects)
include(ExternalData)
set(Slicer_ExternalData_OBJECT_STORES ${ExternalData_OBJECT_STORES})
set(Slicer_ExternalData_URL_TEMPLATES ${ExternalData_URL_TEMPLATES})

567
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
568
# Testing
569
#-----------------------------------------------------------------------------
570
set(Slicer_LAUNCHER_EXECUTABLE ${Slicer_BINARY_DIR}/${Slicer_MAIN_PROJECT_APPLICATION_NAME}${CMAKE_EXECUTABLE_SUFFIX})
571
set(Slicer_LAUNCH_COMMAND ${Slicer_LAUNCHER_EXECUTABLE} --launcher-no-splash --launch)
572

573
if(BUILD_TESTING)
574
  include(SlicerMacroSimpleTest)
575 576 577
  include(SlicerMacroPythonTesting)
  include(SlicerMacroConfigureGenericCxxModuleTests)
  include(SlicerMacroConfigureGenericPythonModuleTests)
578

579 580 581 582 583 584 585 586
  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")

  set(CXX_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

  configure_file(
587
    ${Slicer_SOURCE_DIR}/CTestConfig.cmake
588
    ${Slicer_BINARY_DIR}/${Slicer_BIN_DIR}/CTestConfig.cmake
589
    COPYONLY)
590 591

  add_subdirectory(CMake/Testing)
592
endif()
hliu's avatar
hliu committed
593

594
#-----------------------------------------------------------------------------
595 596
# ITK
#-----------------------------------------------------------------------------
597
set(expected_ITK_VERSION_MAJOR ${ITK_VERSION_MAJOR})
598
find_package(ITK REQUIRED)
599 600 601 602 603 604 605 606 607
if(${ITK_VERSION_MAJOR} VERSION_LESS ${expected_ITK_VERSION_MAJOR})
  # Note: Since ITKv3 doesn't include a ITKConfigVersion.cmake file, let's check the version
  #       explicitly instead of passing the version as an argument to find_package() command.
  message(FATAL_ERROR "Could not find a configuration file for package \"ITK\" that is compatible "
                      "with requested version \"${expected_ITK_VERSION_MAJOR}\".\n"
                      "The following configuration files were considered but not accepted:\n"
                      "  ${ITK_CONFIG}, version: ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}\n")
endif()

608 609 610 611
if(${ITK_VERSION_MAJOR} GREATER 3)
  set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
  list(APPEND ITK_LIBRARIES ITKFactoryRegistration)
endif()
612
include(${ITK_USE_FILE})
613

614 615 616
#-----------------------------------------------------------------------------
# VTK
#-----------------------------------------------------------------------------
617 618
find_package(VTK REQUIRED)
if(NOT VTK_USE_QVTK)
619 620 621 622
  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*")
623 624
endif()
include(${VTK_USE_FILE})
625 626

#-----------------------------------------------------------------------------
627
# CTK
628
#-----------------------------------------------------------------------------
629 630
find_package(CTK REQUIRED)
include(${CTK_USE_FILE})
631

632 633 634 635
#-----------------------------------------------------------------------------
# QtTesting
#-----------------------------------------------------------------------------
if(Slicer_USE_QtTesting)
benjamin.long's avatar
benjamin.long committed
636
  set(QtTesting_INSTALL_DIR ${CTK_QtTesting_INSTALL_DIR})
637 638 639 640
  set(QtTesting_DIR ${CTK_QtTesting_DIR})
  find_package(QtTesting REQUIRED)
endif()

641
#-----------------------------------------------------------------------------
642
# qMidasAPI
643
#-----------------------------------------------------------------------------
644
if(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT)
645 646
  find_package(qMidasAPI REQUIRED)
  include(${qMidasAPI_USE_FILE})
647
endif()
648

649
#-----------------------------------------------------------------------------
650
# Qt
651
#-----------------------------------------------------------------------------
652
include(SlicerBlockFindQtAndCheckVersion)
653

654
#-----------------------------------------------------------------------------
655
# Update CMake module path
656
#-----------------------------------------------------------------------------
657
set(CMAKE_MODULE_PATH
658
  ${VTK_CMAKE_DIR}
659 660
  ${CTK_CMAKE_DIR}
  ${CMAKE_MODULE_PATH}
661
  ${CTK_CMAKE_UTILITIES_DIR})
662

663 664 665
#-----------------------------------------------------------------------------
# Set Slicer_PYTHON_VERSION and Slicer_PYTHON_VERSION_DOT
#-----------------------------------------------------------------------------
666 667 668
if(Slicer_USE_PYTHONQT)
  find_package(PythonLibs REQUIRED)
  find_package(PythonInterp REQUIRED)
669 670
  # Extract python lib path
  get_filename_component(PYTHON_DIR_PATH ${PYTHON_EXECUTABLE} PATH)
671 672 673 674
  set(PYTHON_LIBRARY_PATH ${PYTHON_DIR_PATH}/../lib)
  if(WIN32)
    set(PYTHON_LIBRARY_PATH ${PYTHON_DIR_PATH})
  endif()
675
  ctkMacroSetPaths("${PYTHON_LIBRARY_PATH}")
676
  execute_process(
677 678 679
    COMMAND ${PYTHON_EXECUTABLE} -c "import sys; print sys.version[:3]"
    OUTPUT_VARIABLE Slicer_PYTHON_VERSION_DOT
    OUTPUT_STRIP_TRAILING_WHITESPACE)
680 681 682
  string(REGEX REPLACE "[.]" "" Slicer_PYTHON_VERSION ${Slicer_PYTHON_VERSION_DOT})
  message(STATUS "Configuring Slicer with python ${Slicer_PYTHON_VERSION_DOT}")
endif()
683

684
#-----------------------------------------------------------------------------
685 686
# PythonQt
#-----------------------------------------------------------------------------
687 688
if(Slicer_USE_PYTHONQT)
  if(NOT VTK_WRAP_PYTHON)
689 690
    message(FATAL_ERROR "Since Slicer_USE_PYTHONQT is ON, VTK_WRAP_PYTHON is expected to be ON. "
                        "Re-configure VTK with python wrapping.")
691 692 693
  endif()

  include(vtkMacroKitPythonWrap)
694

695
  set(PYTHONQT_INSTALL_DIR ${CTK_PYTHONQT_INSTALL_DIR})
696 697 698 699
  # Find PythonQt package so that PYTHONQT_USE_RELEASE_PYTHON_FALLBACK is defined
  # See https://github.com/commontk/PythonQt/issues/7
  # and https://github.com/commontk/PythonQt/issues/8
  find_package(PythonQt REQUIRED)
700 701 702
  link_directories(${PYTHONQT_INSTALL_DIR}/lib)
  include(ctkMacroWrapPythonQt)
  include(ctkMacroCompilePythonScript)
703

704
  # Enable qMRMLWidgets python wrapping
705
  set(MRMLWidgets_WRAP_PYTHON ON)
706
endif()
707

708
#-----------------------------------------------------------------------------
709 710
# Teem
#-----------------------------------------------------------------------------
711 712
find_package(Teem REQUIRED)
include(${Teem_USE_FILE})
713

714
#-----------------------------------------------------------------------------
715 716
# SlicerLibCurl
#-----------------------------------------------------------------------------
717 718
find_package(SLICERLIBCURL REQUIRED)
include(${SLICERLIBCURL_USE_FILE})
719

720 721 722
#-----------------------------------------------------------------------------
# LibArchive
#-----------------------------------------------------------------------------
723 724 725 726 727 728 729 730 731 732
set(LibArchive_INCLUDE_DIR ${LibArchive_DIR}/include)
if(WIN32)
  set(LibArchive_LIBRARY ${LibArchive_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}archive.lib)
elseif(APPLE)
  # HACK Since fixup extension expects the library to contain the full path, let's make sure the non-installed
  # version of the library is used. Ideally, the project shouldn't be installed and a LibArchiveConfig.cmake
  # should be created.
  set(LibArchive_LIBRARY ${LibArchive_DIR}/../LibArchive-build/libarchive/${CMAKE_SHARED_LIBRARY_PREFIX}archive${CMAKE_SHARED_LIBRARY_SUFFIX})
else()
  set(LibArchive_LIBRARY ${LibArchive_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}archive${CMAKE_SHARED_LIBRARY_SUFFIX})
733
endif()
734 735 736 737 738
foreach(var LibArchive_LIBRARY LibArchive_INCLUDE_DIR)
  if(NOT EXISTS "${${var}}")
    message(FATAL_ERROR "error: ${var} corresponds to an inexistant file or directory. [${${var}}]")
  endif()
endforeach()
739

740
#-----------------------------------------------------------------------------
741 742
# BatchMake
#-----------------------------------------------------------------------------
743 744 745 746
if(Slicer_USE_BatchMake)
  find_package(BatchMake REQUIRED)
  include(${BatchMake_USE_FILE})
endif()
747

748
#-----------------------------------------------------------------------------
749
# OpenIGTLink
750
#-----------------------------------------------------------------------------
751
if(Slicer_USE_OpenIGTLink)
752 753 754
  find_package(OpenIGTLink REQUIRED)
  include(${OpenIGTLink_USE_FILE})
endif()
hliu's avatar
hliu committed
755

756 757 758 759
#-----------------------------------------------------------------------------
# SlicerExecutionModel settings
#-----------------------------------------------------------------------------
set(SlicerExecutionModel_EXTRA_INCLUDE_DIRECTORIES "" CACHE INTERNAL "SlicerExecutionModel extra includes" FORCE)
760
set(SlicerExecutionModel_EXTRA_EXECUTABLE_TARGET_LIBRARIES "" CACHE INTERNAL "SlicerExecutionModel extra executable target libraries" FORCE)
761

762
#-----------------------------------------------------------------------------
763 764
# Set Slicer buildin libraries *_DIR variables
#-----------------------------------------------------------------------------
765 766
set(GenerateLM_DIR ${Slicer_BINARY_DIR}/Libs/GenerateLM)
set(vtkITK_DIR ${Slicer_BINARY_DIR}/Libs/vtkITK)
767

jcfr's avatar
jcfr committed
768
#-----------------------------------------------------------------------------
769
# Qt Loadable and Scripted Modules relative directories
770
#-----------------------------------------------------------------------------
771 772 773 774 775 776 777 778 779 780 781

# NOTE: Make sure to update vtkSlicerApplicationLogic::GetModuleShareDirectory()
#       if the following variables are changed.

set(Slicer_QTLOADABLEMODULES_SUBDIR "qt-loadable-modules")

set(Slicer_QTLOADABLEMODULES_BIN_DIR "${Slicer_LIB_DIR}/${Slicer_QTLOADABLEMODULES_SUBDIR}")
set(Slicer_QTLOADABLEMODULES_LIB_DIR "${Slicer_LIB_DIR}/${Slicer_QTLOADABLEMODULES_SUBDIR}")
set(Slicer_QTLOADABLEMODULES_PYTHON_LIB_DIR "${Slicer_LIB_DIR}/${Slicer_QTLOADABLEMODULES_SUBDIR}/Python")
set(Slicer_QTLOADABLEMODULES_INCLUDE_DIR "${Slicer_INCLUDE_DIR}/${Slicer_QTLOADABLEMODULES_SUBDIR}")
set(Slicer_QTLOADABLEMODULES_SHARE_DIR "${Slicer_SHARE_DIR}/${Slicer_QTLOADABLEMODULES_SUBDIR}")
782 783 784 785 786 787

set(Slicer_INSTALL_QTLOADABLEMODULES_BIN_DIR "${Slicer_INSTALL_ROOT}${Slicer_QTLOADABLEMODULES_BIN_DIR}")
set(Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR "${Slicer_INSTALL_ROOT}${Slicer_QTLOADABLEMODULES_LIB_DIR}")
set(Slicer_INSTALL_QTLOADABLEMODULES_PYTHON_LIB_DIR "${Slicer_INSTALL_ROOT}${Slicer_QTLOADABLEMODULES_PYTHON_LIB_DIR}")
set(Slicer_INSTALL_QTLOADABLEMODULES_INCLUDE_DIR "${Slicer_INSTALL_ROOT}${Slicer_QTLOADABLEMODULES_INCLUDE_DIR}")
set(Slicer_INSTALL_QTLOADABLEMODULES_SHARE_DIR "${Slicer_INSTALL_ROOT}${Slicer_QTLOADABLEMODULES_SHARE_DIR}")
788

789
if(Slicer_USE_PYTHONQT)
790 791 792 793 794 795
  set(Slicer_QTSCRIPTEDMODULES_SUBDIR "qt-scripted-modules")

  set(Slicer_QTSCRIPTEDMODULES_BIN_DIR "${Slicer_LIB_DIR}/${Slicer_QTSCRIPTEDMODULES_SUBDIR}")
  set(Slicer_QTSCRIPTEDMODULES_LIB_DIR "${Slicer_LIB_DIR}/${Slicer_QTSCRIPTEDMODULES_SUBDIR}")
  set(Slicer_QTSCRIPTEDMODULES_INCLUDE_DIR "${Slicer_INCLUDE_DIR}/${Slicer_QTSCRIPTEDMODULES_SUBDIR}")
  set(Slicer_QTSCRIPTEDMODULES_SHARE_DIR "${Slicer_SHARE_DIR}/${Slicer_QTSCRIPTEDMODULES_SUBDIR}")
796

797 798 799 800
  set(Slicer_INSTALL_QTSCRIPTEDMODULES_BIN_DIR "${Slicer_INSTALL_ROOT}${Slicer_QTSCRIPTEDMODULES_BIN_DIR}")
  set(Slicer_INSTALL_QTSCRIPTEDMODULES_LIB_DIR "${Slicer_INSTALL_ROOT}${Slicer_QTSCRIPTEDMODULES_LIB_DIR}")
  set(Slicer_INSTALL_QTSCRIPTEDMODULES_INCLUDE_DIR "${Slicer_INSTALL_ROOT}${Slicer_QTSCRIPTEDMODULES_INCLUDE_DIR}")
  set(Slicer_INSTALL_QTSCRIPTEDMODULES_SHARE_DIR "${Slicer_INSTALL_ROOT}${Slicer_QTSCRIPTEDMODULES_SHARE_DIR}")
801
endif()
jcfr's avatar
jcfr committed
802

803
#-----------------------------------------------------------------------------
804 805
# Set COVERAGE_{C,CXX}_FLAGS variables
#-----------------------------------------------------------------------------
806
include(SlicerBlockCXXCoverageFlags)
807 808

#-----------------------------------------------------------------------------
809
# Set ITK_REQUIRED_{C,CXX}_FLAGS variables
810
#-----------------------------------------------------------------------------
811
include(ITKPlatformSpecificChecks)
812 813 814

#-----------------------------------------------------------------------------
# Set CMAKE_{C,CXX}_FLAGS variables
815
#-----------------------------------------------------------------------------
816 817
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_INIT} ${Slicer_REQUIRED_C_FLAGS} ${ITK_REQUIRED_C_FLAGS} ${COVERAGE_C_FLAGS} ${ADDITIONAL_C_FLAGS}" CACHE STRING "CMake C Flags" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_INIT} ${Slicer_REQUIRED_CXX_FLAGS} ${ITK_REQUIRED_CXX_FLAGS} ${COVERAGE_CXX_FLAGS} ${ADDITIONAL_CXX_FLAGS}" CACHE STRING "CMake CXX Flags" FORCE)
818

819 820 821 822
#-----------------------------------------------------------------------------
# Set the header template which defines custom export/import macros
# for shared libraries
#-----------------------------------------------------------------------------
823
set(QMRML_EXPORT_HEADER_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/Libs/MRML/Widgets/CMake/qMRMLExport.h.in")
824

825 826 827
#-----------------------------------------------------------------------------
# Configure testing scripts
#-----------------------------------------------------------------------------
828 829 830 831 832 833 834
set(files
  Utilities/Scripts/runValgrind.sh
  Utilities/Scripts/runValgrindForOneModule.sh
  Utilities/Scripts/runValgrindForOneModuleWithSlicer4AndQT.sh
  Utilities/Scripts/computeCodeCoverageLocally.sh
  Utilities/Scripts/computeCodeCoverageForOneTest.sh
  Utilities/Scripts/runExperimentalOffScreen.sh
835
  Utilities/Scripts/setupSlicerEnvironment.sh
836
  )
837 838
foreach(f ${files})
  configure_file(
839 840 841
    ${CMAKE_CURRENT_SOURCE_DIR}/${f}.in
    ${CMAKE_CURRENT_BINARY_DIR}/${f}
    )
842
endforeach()
843

844 845 846
#-----------------------------------------------------------------------------
# Includes
#-----------------------------------------------------------------------------
847
include_directories(
848
  ${CMAKE_CURRENT_SOURCE_DIR}/CMake
849 850
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}
851
  )
852

853
#-----------------------------------------------------------------------------
854
# Subdirectories
855 856
#-----------------------------------------------------------------------------

857 858 859
add_subdirectory(Libs)
add_subdirectory(Base)
add_subdirectory(Resources)
860

861
#-----------------------------------------------------------------------------
862
# Macro useful to build ModuleLogic, ModuleMRML and ModuleWidgets libraries
863
#-----------------------------------------------------------------------------
864 865 866 867 868 869
include(SlicerMacroBuildModuleQtLibrary)
include(SlicerMacroBuildModuleVTKLibrary)
include(SlicerMacroPythonWrapModuleVTKLibrary)
include(SlicerMacroBuildModuleLogic)
include(SlicerMacroBuildModuleMRML)
include(SlicerMacroBuildModuleWidgets)
870

871 872 873
#-----------------------------------------------------------------------------
# Slicer Core and GUI library
#-----------------------------------------------------------------------------
874
set(Slicer_CORE_LIBRARY qSlicerBaseQTCore)
875
set(Slicer_GUI_LIBRARY qSlicerBaseQTApp)
876

877
#-----------------------------------------------------------------------------
878
# Applications
879
#-----------------------------------------------------------------------------
880 881
add_subdirectory(Modules/Core)
add_subdirectory(Base/QTApp)
882
add_subdirectory(Modules)
883
if (NOT Slicer_APPLICATIONS_DIR)
884 885 886 887 888 889
  add_subdirectory(Applications)
else()
  add_subdirectory(${Slicer_APPLICATIONS_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}/Applications
    )
endif()
890

891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
# --------------------------------------------------------------------------
# Bundle extension(s)
# --------------------------------------------------------------------------
# List of extension source directories can be passed at configuration time
# using the following syntax:
#  cmake -DSlicer_EXTENSION_SOURCE_DIRS:STRING=/path/to/ExtensionA;/path/to/ExtensionB /path/to/source/Slicer
foreach(extension_source_dir ${Slicer_EXTENSION_SOURCE_DIRS})
  get_filename_component(extension_source_dirname ${extension_source_dir} NAME_WE)
  message(STATUS "Configuring extension: ${extension_source_dirname}")
  set(ExternalData_SOURCE_ROOT ${extension_source_dir})
  set(${extension_source_dirname}_SOURCE_DIR ${extension_source_dir})
  set(${extension_source_dirname}_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/Extensions/${extension_source_dirname})
  add_subdirectory(
    ${${extension_source_dirname}_SOURCE_DIR}
    ${${extension_source_dirname}_BINARY_DIR}
    )
endforeach()

909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
# --------------------------------------------------------------------------
# Recover the QM output directories
# --------------------------------------------------------------------------
get_property(Slicer_QM_OUTPUT_DIRS GLOBAL PROPERTY Slicer_QM_OUTPUT_DIRS)

# --------------------------------------------------------------------------
# Configure and install headers
# --------------------------------------------------------------------------

set(files
  vtkSlicerConfigure.h
  vtkSlicerVersionConfigure.h
  )
foreach(f ${files})
  configure_file(
    ${CMAKE_CURRENT_SOURCE_DIR}/CMake/${f}.in
    ${CMAKE_CURRENT_BINARY_DIR}/${f}
    )
endforeach()
if(NOT Slicer_INSTALL_NO_DEVELOPMENT)
  install(FILES
    "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerConfigure.h"
    "${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerVersionConfigure.h"
    DESTINATION ${Slicer_INSTALL_INCLUDE_DIR} COMPONENT Development
    )
endif()

936 937
#-----------------------------------------------------------------------------
# Testing
938 939
#-----------------------------------------------------------------------------

940 941 942
if(BUILD_TESTING)
  add_subdirectory(Testing)
endif()
943

944
# Install testing data
945

946 947
if(NOT Slicer_INSTALL_NO_DEVELOPMENT)
  install(DIRECTORY
948 949 950 951 952
    Testing
    DESTINATION ${Slicer_INSTALL_SHARE_DIR} COMPONENT Development
    PATTERN ".svn" EXCLUDE
    PATTERN "CMakeLists.txt" EXCLUDE
    )
953
endif()
954 955

#-----------------------------------------------------------------------------
956
# Documentation
957 958
#-----------------------------------------------------------------------------

959
add_subdirectory(Utilities/Doxygen)
960

961 962 963
if(NOT Slicer_INSTALL_NO_DEVELOPMENT)
  file(GLOB cmake_files "${CMAKE_CURRENT_SOURCE_DIR}/CMake/*.cmake")
  install(
964 965 966 967
    FILES ${cmake_files}
    DESTINATION ${Slicer_INSTALL_LIB_DIR}/CMake COMPONENT Development
    )

968
  install(FILES
969 970
    ${Slicer_BINARY_DIR}/UseSlicer.cmake
    ${Slicer_BINARY_DIR}/SlicerConfig.cmake
971
    ${Slicer_BINARY_DIR}/SlicerConfigVersion.cmake
972 973 974
    DESTINATION ${Slicer_INSTALL_LIB_DIR}
    COMPONENT Development
    )
975
endif()
976

977 978 979 980
#-----------------------------------------------------------------------------
# The commands in this directory are intended to be executed as
# the end of the whole configuration process, as a "last step".
# This directory is typically the last add_subdirectory in the main CMakeLists.txt.
981
add_subdirectory(CMake/LastConfigureStep)
982