CMakeLists.txt 47 KB
Newer Older
1
cmake_minimum_required(VERSION 3.13.4)
2

3 4 5
#-----------------------------------------------------------------------------
# Enable C++11
#-----------------------------------------------------------------------------
6 7
set(_msg "Setting C++ standard")
message(STATUS "${_msg}")
8 9
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 11)
10
endif()
11 12
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
13
message(STATUS "${_msg} - C++${CMAKE_CXX_STANDARD}")
14 15 16
if(NOT CMAKE_CXX_STANDARD MATCHES "^(11|14|17)$")
  message(FATAL_ERROR "CMAKE_CXX_STANDARD must be set to 11, 14 or 17")
endif()
17

18 19
#-----------------------------------------------------------------------------
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" ${CMAKE_MODULE_PATH})
20
set(SUPERBUILD_TOPLEVEL_PROJECT Slicer)
21
list(APPEND EXTERNAL_PROJECT_ADDITIONAL_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild)
22 23
include(ExternalProject)
include(ExternalProjectDependency)
24
include(ExternalProjectDependencyForPython)
25
include(ExternalProjectGenerateProjectDescription)
26

27
#-----------------------------------------------------------------------------
28 29
if(APPLE)
  # Note: By setting CMAKE_OSX_* variables before any enable_language() or project() calls,
30
  #       we ensure that the bitness, and C++ standard library will be properly detected.
31
  include(SlicerInitializeOSXVariables)
32 33 34 35
  mark_as_superbuild(
    VARS CMAKE_OSX_ARCHITECTURES:STRING CMAKE_OSX_SYSROOT:PATH CMAKE_OSX_DEPLOYMENT_TARGET:STRING
    ALL_PROJECTS
    )
36 37

  set(CMAKE_MACOSX_RPATH 0)
38
  mark_as_superbuild(VARS CMAKE_MACOSX_RPATH:BOOL ALL_PROJECTS)
39 40
endif()

41 42 43 44 45
#-----------------------------------------------------------------------------
if(NOT DEFINED Slicer_VERSION_MAJOR)
  set(Slicer_VERSION_MAJOR "4")
endif()
if(NOT DEFINED Slicer_VERSION_MINOR)
jcfr's avatar
jcfr committed
46
  set(Slicer_VERSION_MINOR "11")
47 48 49 50
endif()
if(NOT DEFINED Slicer_VERSION_PATCH)
  set(Slicer_VERSION_PATCH "0")
endif()
51
project(Slicer VERSION "${Slicer_VERSION_MAJOR}.${Slicer_VERSION_MINOR}.${Slicer_VERSION_PATCH}")
52

53
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
54 55 56 57 58 59 60 61 62 63
# Update CMake module path
#------------------------------------------------------------------------------
set(CMAKE_MODULE_PATH
  ${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)

64
#-----------------------------------------------------------------------------
65
# http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/DevelopmentWithGit
66 67 68
#-----------------------------------------------------------------------------
include(SlicerCheckSourceTree)

69 70 71 72 73 74 75
#-----------------------------------------------------------------------------
# Superbuild Option - Enabled by default
#-----------------------------------------------------------------------------
option(Slicer_SUPERBUILD "Build ${PROJECT_NAME} and the projects it depends on." ON)
mark_as_advanced(Slicer_SUPERBUILD)
set(Slicer_BINARY_INNER_SUBDIR Slicer-build)

76 77 78 79 80 81
#-----------------------------------------------------------------------------
include(CTestUseLaunchers OPTIONAL)
if(${CTEST_USE_LAUNCHERS})
  message(STATUS "CTest launchers enabled")
endif()

jcfr's avatar
jcfr committed
82 83 84
#-----------------------------------------------------------------------------
# Sanity checks
#------------------------------------------------------------------------------
85
if(WIN32)
86 87 88 89
  set(${PROJECT_NAME}_ROOT_DIR_MAX_LENGTH 40)
  if(NOT ${PROJECT_NAME}_SUPERBUILD)
    string(LENGTH ${Slicer_BINARY_INNER_SUBDIR} _inner_subdir_length)
    math(EXPR ${PROJECT_NAME}_ROOT_DIR_MAX_LENGTH "${${PROJECT_NAME}_ROOT_DIR_MAX_LENGTH} + ${_inner_subdir_length}")
90
  endif()
91
  include(PreventDirWithTooManyChars)
92
endif()
jcfr's avatar
jcfr committed
93
include(PreventInSourceBuilds)
jcfr's avatar
jcfr committed
94
include(PreventInBuildInstalls)
95 96
include(PreventDirWithSpaces)
mark_as_superbuild(${PROJECT_NAME}_SKIP_DIR_WITH_SPACES_CHECK:BOOL)
97

98 99 100 101 102 103 104 105
#-----------------------------------------------------------------------------
# Overwrite default options
#-----------------------------------------------------------------------------
set(_overwrite_options_file ${Slicer_CMAKE_DIR}/SlicerOverwriteDefaultOptions.cmake)
if(EXISTS ${_overwrite_options_file})
  include(${_overwrite_options_file})
endif()

106 107 108
#-----------------------------------------------------------------------------
# Check if the linker will resolve symbols of underlinked libraries
#-----------------------------------------------------------------------------
109
if(UNIX AND NOT APPLE)
110 111 112 113 114 115 116 117
  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()

118
#-----------------------------------------------------------------------------
119
# Slicer Build and Release type
120
#-----------------------------------------------------------------------------
121 122
include(SlicerInitializeBuildType)
include(SlicerInitializeReleaseType)
123

124 125 126 127
#-----------------------------------------------------------------------------
# Set the header template which defines custom export/import macros
# for shared libraries
#-----------------------------------------------------------------------------
128
set(Slicer_EXPORT_HEADER_TEMPLATE "${Slicer_SOURCE_DIR}/CMake/qSlicerExport.h.in")
129
set(Slicer_LOGOS_RESOURCE "${Slicer_SOURCE_DIR}/Resources/qSlicer.qrc")
130

131
#-----------------------------------------------------------------------------
132
# Platform checks
133
#-----------------------------------------------------------------------------
134
include(SlicerBlockPlatformCheck)
135
mark_as_superbuild(Slicer_PLATFORM_CHECK:BOOL)
136 137 138 139

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

#-----------------------------------------------------------------------------
# Prerequisites
#-----------------------------------------------------------------------------
146
find_package(Subversion)
147
mark_as_superbuild(Subversion_SVN_EXECUTABLE)
148

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

155
find_package(Patch REQUIRED)
156
mark_as_superbuild(Patch_EXECUTABLE)
157

158
#-----------------------------------------------------------------------------
159
# Qt requirements
160
#-----------------------------------------------------------------------------
161
if(NOT DEFINED Slicer_REQUIRED_QT_VERSION)
162
  set(_required_qt_version "5.6.0")
163
  set(Slicer_REQUIRED_QT_VERSION ${_required_qt_version} CACHE STRING "Minimum required Qt version" FORCE)
164
endif()
165
mark_as_superbuild(Slicer_REQUIRED_QT_VERSION)
166 167 168 169 170

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

#-----------------------------------------------------------------------------
# Append the library version information to the library target properties.
#------------------------------------------------------------------------------
177 178
option(Slicer_WITH_LIBRARY_VERSION "Build with library version information" OFF)
mark_as_advanced(Slicer_WITH_LIBRARY_VERSION)
179
mark_as_superbuild(Slicer_WITH_LIBRARY_VERSION)
180 181
if(Slicer_WITH_LIBRARY_VERSION)
  set(Slicer_LIBRARY_PROPERTIES ${Slicer_LIBRARY_PROPERTIES}
182 183 184
    VERSION ${Slicer_VERSION_FULL}
    SOVERSION ${Slicer_VERSION}
  )
185
endif()
186 187

#-----------------------------------------------------------------------------
188
# General Slicer Options
189
#-----------------------------------------------------------------------------
190 191
include(CMakeDependentOption)

192
option(BUILD_TESTING "Test the project" ON)
193 194
mark_as_superbuild(BUILD_TESTING)

195
#option(WITH_MEMCHECK "Run tests through valgrind." OFF)
196 197
#mark_as_superbuild(WITH_MEMCHECK)

198
option(WITH_COVERAGE "Enable/Disable coverage" OFF)
199 200
mark_as_superbuild(WITH_COVERAGE)

201
option(Slicer_USE_VTK_DEBUG_LEAKS "Enable VTKs Debug Leaks functionality in both VTK and Slicer." ON)
202 203 204
set(VTK_DEBUG_LEAKS ${Slicer_USE_VTK_DEBUG_LEAKS})
mark_as_superbuild(VTK_DEBUG_LEAKS:BOOL)

205
option(Slicer_BUILD_DICOM_SUPPORT "Build Slicer with DICOM support" ON)
206 207
mark_as_superbuild(Slicer_BUILD_DICOM_SUPPORT)

208
option(Slicer_BUILD_DIFFUSION_SUPPORT "Build Slicer with diffusion (DWI, DTI) support" ON)
209 210
mark_as_superbuild(Slicer_BUILD_DIFFUSION_SUPPORT)

211
option(Slicer_BUILD_I18N_SUPPORT "Build Slicer with Internationalization support" OFF)
212
mark_as_superbuild(Slicer_BUILD_I18N_SUPPORT)
213

214 215
option(Slicer_BUILD_QTLOADABLEMODULES "Build Slicer QT Loadable Modules" ON)
mark_as_advanced(Slicer_BUILD_QTLOADABLEMODULES)
216 217
mark_as_superbuild(Slicer_BUILD_QTLOADABLEMODULES)

218
option(Slicer_USE_PYTHONQT "Integrate a python-QT interpreter into Slicer." ON)
219 220
mark_as_superbuild(Slicer_USE_PYTHONQT)

221 222 223
CMAKE_DEPENDENT_OPTION(
  Slicer_BUILD_QTSCRIPTEDMODULES "Build Slicer Python QT Modules" ON
  "Slicer_USE_PYTHONQT" OFF)
224
mark_as_advanced(Slicer_BUILD_QTSCRIPTEDMODULES)
225 226
mark_as_superbuild(Slicer_BUILD_QTSCRIPTEDMODULES)

227
option(Slicer_BUILD_CLI_SUPPORT "Build Slicer with CLI support" ON)
228
mark_as_superbuild(Slicer_BUILD_CLI_SUPPORT)
229 230 231 232
CMAKE_DEPENDENT_OPTION(
  Slicer_BUILD_CLI "Build Slicer CLI Plugins" ON
  "Slicer_BUILD_CLI_SUPPORT" OFF
  )
233 234

mark_as_superbuild(Slicer_BUILD_CLI)
235 236 237 238
CMAKE_DEPENDENT_OPTION(
  Slicer_BUILD_LEGACY_CLI "Build Slicer LEGACY_CLI Plugins" ON
  "Slicer_BUILD_CLI" OFF
  )
239

240 241 242
option(Slicer_BUILD_QT_DESIGNER_PLUGINS "Build Qt designer plugins" ON)
mark_as_superbuild(Slicer_BUILD_QT_DESIGNER_PLUGINS)

243
option(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT "Build Slicer extension manager" ON)
244 245
mark_as_superbuild(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT)

246
CMAKE_DEPENDENT_OPTION(Slicer_UPDATE_TRANSLATION "update translation" OFF "Slicer_BUILD_I18N_SUPPORT" OFF)
247
mark_as_advanced(Slicer_UPDATE_TRANSLATION)
248
mark_as_superbuild(Slicer_UPDATE_TRANSLATION)
249

250 251
set(Slicer_FORCED_WC_LAST_CHANGED_DATE "" CACHE STRING "Overwrite value of auto-discovered Slicer_WC_LAST_CHANGED_DATE (format: YYYY-MM-DD)")
mark_as_advanced(Slicer_FORCED_WC_LAST_CHANGED_DATE)
252
mark_as_superbuild(Slicer_FORCED_WC_LAST_CHANGED_DATE)
253

254 255
set(Slicer_FORCED_WC_REVISION "" CACHE STRING "Overwrite value of auto-discovered Slicer_WC_REVISION")
mark_as_advanced(Slicer_FORCED_WC_REVISION)
256
mark_as_superbuild(Slicer_FORCED_WC_REVISION)
257

258 259 260 261
option(Slicer_USE_FOLDERS "Organize build targets into folders" ON)
mark_as_superbuild(Slicer_USE_FOLDERS)
mark_as_advanced(Slicer_USE_FOLDERS)

262 263 264
#-----------------------------------------------------------------------------
# External projects related options
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
265
CMAKE_DEPENDENT_OPTION(
266
  Slicer_USE_PYTHONQT_WITH_OPENSSL "Enable PythonQt SSL support" ON
jcfr's avatar
jcfr committed
267
  "Slicer_USE_PYTHONQT" OFF)
268 269
mark_as_superbuild(Slicer_USE_PYTHONQT_WITH_OPENSSL)

270
CMAKE_DEPENDENT_OPTION(
271
  Slicer_USE_PYTHONQT_WITH_TCL "Enable PythonQt Tcl adapter layer" OFF
272
  "Slicer_USE_PYTHONQT" OFF)
273 274
mark_as_superbuild(Slicer_USE_PYTHONQT_WITH_TCL)

275 276 277
CMAKE_DEPENDENT_OPTION(
  Slicer_USE_NUMPY "Build Slicer with NumPy" ON
  "Slicer_USE_PYTHONQT" OFF)
278 279
mark_as_superbuild(Slicer_USE_NUMPY)

280 281
option(Slicer_USE_CTKAPPLAUNCHER "Configure ctkAppLauncher." ON)
mark_as_advanced(Slicer_USE_CTKAPPLAUNCHER)
282 283
mark_as_superbuild(Slicer_USE_CTKAPPLAUNCHER)

284 285
option(Slicer_USE_QtTesting    "Integrate QtTesting framework into Slicer." ON)
mark_as_advanced(Slicer_USE_QtTesting)
286
mark_as_superbuild(Slicer_USE_QtTesting)
287

288
option(Slicer_USE_SimpleITK "Build Slicer with SimpleITK support" ON)
289
mark_as_superbuild(Slicer_USE_SimpleITK)
290

291 292
option(Slicer_BUILD_ITKPython "Build Python wrapping for ITK" OFF)
mark_as_superbuild(Slicer_BUILD_ITKPython)
293 294 295 296
CMAKE_DEPENDENT_OPTION(
  Slicer_INSTALL_ITKPython "Install Slicer with Python wrapping for ITK" OFF
  "Slicer_BUILD_ITKPython" OFF)
mark_as_superbuild(Slicer_INSTALL_ITKPython)
297

298
option(Slicer_BUILD_PARAMETERSERIALIZER_SUPPORT "Build Slicer with parameter serializer support" ON)
299 300
mark_as_superbuild(Slicer_BUILD_PARAMETERSERIALIZER_SUPPORT)

301 302 303 304 305
set(_default_itk "5")
set(Slicer_ITK_VERSION_MAJOR ${_default_itk} CACHE STRING "The ITK major version (5).")
set_property(CACHE Slicer_ITK_VERSION_MAJOR PROPERTY STRINGS "5")
mark_as_superbuild(Slicer_ITK_VERSION_MAJOR)

306 307 308 309
set(_default_vtk "8")
set(Slicer_VTK_VERSION_MAJOR ${_default_vtk} CACHE STRING "VTK major version")
set_property(CACHE Slicer_VTK_VERSION_MAJOR PROPERTY STRINGS "8")
if(NOT "${Slicer_VTK_VERSION_MAJOR}" MATCHES "^(8)$")
310 311 312 313
  if("${Slicer_VTK_VERSION_MAJOR}" STREQUAL "9")
    set(Slicer_VTK_VERSION_MAJOR 8 CACHE STRING "The VTK major version (7 or 8)." FORCE)
    message(WARNING "Forcing Slicer_VTK_VERSION_MAJOR to 8 because VTK version was changed from 9.0 to 8.2. See http://vtk.1045678.n5.nabble.com/Discussion-OK-to-change-VTK-s-version-number-from-9-0-to-8-2-tt5748702.html")
  else()
314
    message(FATAL_ERROR "error: Slicer_VTK_VERSION_MAJOR must be 8.")
315
  endif()
jcfr's avatar
jcfr committed
316 317 318
endif()
mark_as_superbuild(Slicer_VTK_VERSION_MAJOR)

319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
#
# SimpleITK has large internal libraries, which take an extremely long
# time to link on windows when they are static. Creating shared
# SimpleITK internal libraries can reduce linking time. Also the size
# of the debug libraries are monstrous. Using shared libraries for
# debug, reduce disc requirements, and can improve linking
# times. However, these shared libraries take longer to load than the
# monolithic target from static libraries.
#
set( Slicer_USE_SimpleITK_SHARED_DEFAULT OFF)
string(TOUPPER "${CMAKE_BUILD_TYPE}" _CMAKE_BUILD_TYPE)
if(MSVC OR _CMAKE_BUILD_TYPE MATCHES "DEBUG")
  set(Slicer_USE_SimpleITK_SHARED_DEFAULT ON)
endif()
CMAKE_DEPENDENT_OPTION(Slicer_USE_SimpleITK_SHARED "Build SimpleITK with shared libraries. Reduces linking time, increases run-time load time." ${Slicer_USE_SimpleITK_SHARED_DEFAULT} "Slicer_USE_SimpleITK" OFF )
334
mark_as_superbuild(Slicer_USE_SimpleITK_SHARED)
335

336 337 338 339
#-----------------------------------------------------------------------------
# Install no development files by default, but allow the user to get
# them installed by setting Slicer_INSTALL_DEVELOPMENT to true.
#-----------------------------------------------------------------------------
340 341 342 343 344 345 346 347
#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()
348

349 350 351
#-----------------------------------------------------------------------------
# Documentation
#-----------------------------------------------------------------------------
352 353 354
option(Slicer_BUILD_DOCUMENTATION "Build documentation (Doxygen, sphinx, ...)" ON)
mark_as_advanced(Slicer_BUILD_DOCUMENTATION)
mark_as_superbuild(Slicer_BUILD_DOCUMENTATION)
355

356 357
if(Slicer_BUILD_DOCUMENTATION)
  find_package(Doxygen QUIET)
358

359 360
  if(DOXYGEN_DOT_FOUND)
    mark_as_superbuild(DOXYGEN_EXECUTABLE)
361

362 363 364 365 366 367 368 369 370
    set(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
     CACHE PATH "Where documentation archives should be stored")
    mark_as_advanced(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)
    mark_as_superbuild(DOCUMENTATION_ARCHIVES_OUTPUT_DIRECTORY)

    option(DOCUMENTATION_TARGET_IN_ALL "Include the custom target for building documentation in 'all'" OFF)
    mark_as_advanced(DOCUMENTATION_TARGET_IN_ALL)
    mark_as_superbuild(DOCUMENTATION_TARGET_IN_ALL)
  endif()
371
endif()
372

373 374 375
#-----------------------------------------------------------------------------
# CTestCustom
#-----------------------------------------------------------------------------
376 377 378
configure_file(
  CMake/CTestCustom.cmake.in
  ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
379 380
  COPYONLY
  )
381

382
#-----------------------------------------------------------------------------
383 384
# Additional CXX/C Flags
#-----------------------------------------------------------------------------
385 386 387 388
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)
389

390 391 392 393
#-----------------------------------------------------------------------------
# CMake Function(s) and Macro(s)
#-----------------------------------------------------------------------------
include(CMakeParseArguments)
394
include(SlicerMacroBuildScriptedModule)
395 396 397 398 399
include(SlicerMacroGetOperatingSystemArchitectureBitness)
if(Slicer_BUILD_I18N_SUPPORT)
  include(SlicerMacroTranslation)
endif()
include(SlicerFunctionInstallLibrary)
400
include(SlicerFunctionAddPythonQtResources)
401 402 403 404 405 406 407 408 409 410 411

#-----------------------------------------------------------------------------
# Internationalization
#-----------------------------------------------------------------------------
if(Slicer_BUILD_I18N_SUPPORT)
  set(Slicer_LANGUAGES
    "fr"
    )
  set_property(GLOBAL PROPERTY Slicer_LANGUAGES ${Slicer_LANGUAGES})
endif()

412
#-----------------------------------------------------------------------------
413
# Set Slicer_{C,CXX}_REQUIRED_FLAGS variables
414
#-----------------------------------------------------------------------------
415
include(SlicerBlockCXXRequiredFlags)
416

417
#-----------------------------------------------------------------------------
418
# Slicer application options
419
#-----------------------------------------------------------------------------
420
include(SlicerApplicationOptions)
421

422
#-----------------------------------------------------------------------------
423 424 425 426
# Slicer directories
#-----------------------------------------------------------------------------
include(SlicerDirectories)

427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
# SlicerExecutionModel output directories
if(Slicer_SUPERBUILD)
  set(_sem_output_dir ${CMAKE_BINARY_DIR}/${Slicer_BINARY_INNER_SUBDIR})
else()
  set(_sem_output_dir ${CMAKE_BINARY_DIR})
endif()
if(NOT DEFINED SlicerExecutionModel_DEFAULT_CLI_RUNTIME_OUTPUT_DIRECTORY)
  set(SlicerExecutionModel_DEFAULT_CLI_RUNTIME_OUTPUT_DIRECTORY ${_sem_output_dir}/${Slicer_CLIMODULES_BIN_DIR})
endif()
if(NOT DEFINED SlicerExecutionModel_DEFAULT_CLI_LIBRARY_OUTPUT_DIRECTORY)
  set(SlicerExecutionModel_DEFAULT_CLI_LIBRARY_OUTPUT_DIRECTORY ${_sem_output_dir}/${Slicer_CLIMODULES_LIB_DIR})
endif()
if(NOT DEFINED SlicerExecutionModel_DEFAULT_CLI_ARCHIVE_OUTPUT_DIRECTORY)
  set(SlicerExecutionModel_DEFAULT_CLI_ARCHIVE_OUTPUT_DIRECTORY ${_sem_output_dir}/${Slicer_CLIMODULES_LIB_DIR})
endif()

443 444
#-----------------------------------------------------------------------------
# Slicer version number
445
#-----------------------------------------------------------------------------
446
include(SlicerVersion)
447

448
#-----------------------------------------------------------------------------
449
# Extension directories
450
#-----------------------------------------------------------------------------
451 452 453 454
# 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}")
455

456 457 458 459 460 461 462 463
#-----------------------------------------------------------------------------
# Slicer OpenGL Options
#-----------------------------------------------------------------------------
if(UNIX AND NOT APPLE)
  set(OpenGL_GL_PREFERENCE "LEGACY")
  mark_as_superbuild(OpenGL_GL_PREFERENCE:STRING)
endif()

464
#-----------------------------------------------------------------------------
465
# Slicer VTK Options
466
#-----------------------------------------------------------------------------
467
set(_backend "OpenGL2")
468
set(Slicer_VTK_RENDERING_BACKEND "${_backend}" CACHE STRING "Rendering backend." FORCE)
jcfr's avatar
jcfr committed
469 470 471
mark_as_superbuild(Slicer_VTK_RENDERING_BACKEND)
set(Slicer_VTK_RENDERING_USE_${Slicer_VTK_RENDERING_BACKEND}_BACKEND 1)

472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
# Slicer build is only tested with Sequential and TBB. OpenMP might work.
# Use TBB by default only on Windows, as it has not been tested on other platforms.
if(WIN32)
  set(Slicer_DEFAULT_VTK_SMP_IMPLEMENTATION_TYPE "TBB")
else()
  set(Slicer_DEFAULT_VTK_SMP_IMPLEMENTATION_TYPE "Sequential")
endif()
set(Slicer_VTK_SMP_IMPLEMENTATION_TYPE ${Slicer_DEFAULT_VTK_SMP_IMPLEMENTATION_TYPE}
  CACHE STRING "Which multi-threaded parallelism implementation to use in VTK. Options are Sequential or TBB.")
set_property(CACHE Slicer_VTK_SMP_IMPLEMENTATION_TYPE
  PROPERTY
    STRINGS Sequential TBB)
mark_as_superbuild(Slicer_VTK_SMP_IMPLEMENTATION_TYPE)
if(${Slicer_VTK_SMP_IMPLEMENTATION_TYPE} STREQUAL "TBB")
  set(Slicer_USE_TBB TRUE)
else()
  set(Slicer_USE_TBB FALSE)
endif()

491 492
message(STATUS "Configuring VTK")
message(STATUS "  Slicer_VTK_RENDERING_BACKEND is ${Slicer_VTK_RENDERING_BACKEND}")
493
message(STATUS "  Slicer_VTK_SMP_IMPLEMENTATION_TYPE is ${Slicer_VTK_SMP_IMPLEMENTATION_TYPE}")
494 495
message(STATUS "  Slicer_VTK_VERSION_MAJOR is ${Slicer_VTK_VERSION_MAJOR}")

496 497 498
#-----------------------------------------------------------------------------
# Slicer_VTK_COMPONENTS
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
499 500 501 502 503 504
set(Slicer_VTK_COMPONENTS
  vtkFiltersExtraction
  vtkFiltersFlowPaths
  vtkFiltersGeometry
  vtkGUISupportQtOpenGL
  vtkGUISupportQtSQL
505
  vtkIOExport
jcfr's avatar
jcfr committed
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
  vtkIOImage
  vtkIOLegacy
  vtkIOPLY
  vtkIOXML
  vtkImagingMath
  vtkImagingMorphological
  vtkImagingStatistics
  vtkImagingStencil
  vtkInteractionImage
  vtkRenderingContext${Slicer_VTK_RENDERING_BACKEND}
  vtkRenderingQt
  vtkRenderingVolume${Slicer_VTK_RENDERING_BACKEND}
  vtkTestingRendering
  vtkViewsQt
  vtkzlib
  )
if(Slicer_USE_PYTHONQT)
  list(APPEND Slicer_VTK_COMPONENTS
    vtkWrappingPythonCore
525
    )
jcfr's avatar
jcfr committed
526 527 528 529
endif()
if(UNIX AND NOT APPLE)
  find_package(FontConfig QUIET)
  if(FONTCONFIG_FOUND)
530
    list(APPEND Slicer_VTK_COMPONENTS
jcfr's avatar
jcfr committed
531
      vtkRenderingFreeTypeFontConfig
532
      )
jcfr's avatar
jcfr committed
533 534
    if(TARGET vtkRenderingFreeTypeOpenGL)
      list(APPEND VTK_LIBRARIES vtkRenderingFreeTypeOpenGL)
535
    endif()
536 537 538
  endif()
endif()

539 540 541
#-----------------------------------------------------------------------------
# Qt - Slicer_REQUIRED_QT_MODULES
#-----------------------------------------------------------------------------
542
# Module name should be specified as they appear in FindQt5.cmake.
543 544
# For example, the module name associated with the variable QT_USE_QTXML is QTXML.
# Note that the modules will be installed when packaging.
545 546
  set(Slicer_REQUIRED_QT_MODULES
    Core Widgets
547
    Multimedia
548 549 550 551 552 553 554 555 556 557
    Network OpenGL
    PrintSupport # Required by "Annotations" module
    UiTools #no dll
    Xml XmlPatterns
    Svg Sql
    )
  find_package(Qt5 COMPONENTS Core QUIET)
    list(APPEND Slicer_REQUIRED_QT_MODULES
      WebEngine
      WebEngineWidgets
558
      WebChannel
559 560 561 562
      )
  if(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT)
    list(APPEND Slicer_REQUIRED_QT_MODULES Script)
  endif()
563 564 565
  if(Slicer_BUILD_I18N_SUPPORT)
    list(APPEND Slicer_REQUIRED_QT_MODULES LinguistTools) # no dll
  endif()
566 567 568
  if(BUILD_TESTING)
    list(APPEND Slicer_REQUIRED_QT_MODULES Test)
  endif()
569
list(APPEND Slicer_REQUIRED_QT_MODULES ${Slicer_ADDITIONAL_REQUIRED_QT_MODULES})
570

571 572
  set(QT_LIBRARIES)
  foreach(lib IN LISTS Slicer_REQUIRED_QT_MODULES)
573
    if(lib MATCHES "^(LinguistTools)$")
574 575
      continue()
    endif()
576 577 578
    list(APPEND QT_LIBRARIES Qt5::${lib})
  endforeach()

579 580 581 582 583 584
if(DEFINED Slicer_ADDITIONAL_REQUIRED_QT_MODULES)
  mark_as_superbuild(Slicer_ADDITIONAL_REQUIRED_QT_MODULES:STRING)
endif()

mark_as_superbuild(Slicer_USE_SYSTEM_QT:BOOL)

585 586 587 588 589 590
#-----------------------------------------------------------------------------
# Qt plugins (designer, imageformats, ...) relative directories
#-----------------------------------------------------------------------------
set(Slicer_QtPlugins_DIR "lib/QtPlugins")
set(Slicer_INSTALL_QtPlugins_DIR "${Slicer_INSTALL_ROOT}${Slicer_QtPlugins_DIR}")

591 592 593 594
#-----------------------------------------------------------------------------
# Qt
#-----------------------------------------------------------------------------
include(SlicerBlockFindQtAndCheckVersion)
595 596 597 598
  mark_as_superbuild(VARS Qt5_DIR LABELS "FIND_PACKAGE")

set(Slicer_HAVE_QT5 1)
    set(Slicer_HAVE_WEBKIT_SUPPORT 0)
599

600
#
601
# If qmake or Qt5Config are associated with a system location, explicitly mark Qt as such. Doing so
602 603 604 605 606 607
# will prevent system path from being prepended to PATH or (DY)LD_LIBRARY_PATH
# when generating the launcher settings and avoid system libraries symbols from
# conflicting with Slicer version of these libraries.
#
# See https://issues.slicer.org/view.php?id=3574
#
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
  foreach(_path IN ITEMS
      "/usr/lib/"
      "/usr/lib32/"
      "/usr/lib64/"
      "/usr/local/lib/"
      # homebrew
      "/usr/local/Cellar/lib/"
      # macport
      "/opt/lib"
      "/opt/local/lib"
      )
    if("${Qt5_DIR}" MATCHES "^${_path}")
      set(Slicer_USE_SYSTEM_QT ON)
      message(STATUS "")
      message(STATUS "Forcing Slicer_USE_SYSTEM_QT to ON (Qt5_DIR [${Qt5_DIR}] associated with a system location: ${_path})")
      message(STATUS "")
      break()
    endif()
  endforeach()
627

628
# Always use QVTKOpenGLWidget (instead of QVTKWidget)
629 630
set(Slicer_VTK_USE_QVTKOPENGLWIDGET 1)

631 632 633
#-----------------------------------------------------------------------------
# Testing
#-----------------------------------------------------------------------------
634 635
# 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
636

637 638
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1) # Do not add CTest default targets
include(CTest)
639

640 641 642 643 644
# 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}")
645
endif()
646
add_custom_target(Experimental ${CMAKE_CTEST_COMMAND} ${__conf_types} -D Experimental)
647

648 649 650 651 652 653 654 655 656 657
#-----------------------------------------------------------------------------
# ExternalData Object Stores configuration
#-----------------------------------------------------------------------------
set(ExternalData_OBJECT_STORES_DEFAULT "${Slicer_BINARY_DIR}/ExternalData/Objects")
if(DEFINED "ENV{ExternalData_OBJECT_STORES}")
  set(ExternalData_OBJECT_STORES_DEFAULT $ENV{ExternalData_OBJECT_STORES})
endif()
set(ExternalData_OBJECT_STORES "${ExternalData_OBJECT_STORES_DEFAULT}")
message(STATUS "Setting ExternalData_OBJECT_STORES to '${ExternalData_OBJECT_STORES}'")

658 659
set(Slicer_ExternalData_DATA_MANAGEMENT_TARGET ${PROJECT_NAME}Data)

660 661 662 663 664 665
#-----------------------------------------------------------------------------
# Get operating system, architecture and bitness
#-----------------------------------------------------------------------------
SlicerMacroGetOperatingSystemArchitectureBitness(VAR_PREFIX Slicer)
message(STATUS "Configuring ${Slicer_MAIN_PROJECT_APPLICATION_NAME} for [${Slicer_OS}-${Slicer_ARCHITECTURE}]")

666
#-----------------------------------------------------------------------------
667 668
# Superbuild script
#-----------------------------------------------------------------------------
669 670 671 672
if(Slicer_SUPERBUILD)
  include("${CMAKE_CURRENT_SOURCE_DIR}/SuperBuild.cmake")
  return()
endif()
673

674 675 676 677 678 679
foreach(dep QT ${Slicer_DEPENDENCIES})
  if(Slicer_USE_SYSTEM_${dep})
    message(STATUS "Using system ${dep}")
  endif()
endforeach()

680 681 682 683 684
#-----------------------------------------------------------------------------
# Folders
#-----------------------------------------------------------------------------
set_property(GLOBAL PROPERTY USE_FOLDERS ${Slicer_USE_FOLDERS})

685
#-----------------------------------------------------------------------------
686
# Clear SlicerTargets.cmake
687
#-----------------------------------------------------------------------------
688
file(WRITE "${Slicer_BINARY_DIR}/SlicerTargets.cmake" "")
689

690 691 692
#-----------------------------------------------------------------------------
# Output directories.
#------------------------------------------------------------------------------
693 694 695
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})
696

697
#-----------------------------------------------------------------------------
698
# Slicer Home
699
#------------------------------------------------------------------------------
700
set(Slicer_HOME "${Slicer_BINARY_DIR}")
701 702

#-----------------------------------------------------------------------------
703 704
# Avoid linker bug in Mac OS 10.5
# See http://wiki.finkproject.org/index.php/Fink:Packaging:Preparing_for_10.5#OpenGL_Bug
705
#
706 707 708 709
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()
710

711 712
#-----------------------------------------------------------------------------
# Slicer include and libraries subdirectory
713
#-----------------------------------------------------------------------------
714 715 716 717 718
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)
719

720 721 722 723 724 725 726 727
#-----------------------------------------------------------------------------
# ExternalData configuration for test data
#-----------------------------------------------------------------------------
list(APPEND ExternalData_URL_TEMPLATES "http://slicer.kitware.com/midas3/api/rest?method=midas.bitstream.download&checksum=%(hash)")
include(ExternalData)
set(Slicer_ExternalData_OBJECT_STORES ${ExternalData_OBJECT_STORES})
set(Slicer_ExternalData_URL_TEMPLATES ${ExternalData_URL_TEMPLATES})

728
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
729
# Testing
730
#-----------------------------------------------------------------------------
731
set(Slicer_LAUNCHER_EXECUTABLE ${Slicer_BINARY_DIR}/${Slicer_MAIN_PROJECT_APPLICATION_NAME}${CMAKE_EXECUTABLE_SUFFIX})
732
set(Slicer_LAUNCH_COMMAND ${Slicer_LAUNCHER_EXECUTABLE} --launch)
733

734 735 736 737 738
include(SlicerMacroConfigureModuleCxxTestDriver)
include(SlicerMacroSimpleTest)
include(SlicerMacroPythonTesting)
include(SlicerMacroConfigureGenericCxxModuleTests)
include(SlicerMacroConfigureGenericPythonModuleTests)
739

740
if(BUILD_TESTING)
741 742 743 744
  # The variable CXX_TEST_PATH should *NOT* be used when adding tests.
  # Instead the the $<TARGET_FILE:...> generator expression should be
  # considered. See r16586 for more details.
  set(CXX_TEST_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) # XXX
745 746

  configure_file(
747
    ${Slicer_SOURCE_DIR}/CTestConfig.cmake
748
    ${Slicer_BINARY_DIR}/${Slicer_BIN_DIR}/CTestConfig.cmake
749
    COPYONLY)
750 751

  add_subdirectory(CMake/Testing)
752
  add_subdirectory(Extensions/CMake/Testing)
753 754 755 756

  if(Slicer_BUILD_CLI_SUPPORT)
    set(SEM_LAUNCH_COMMAND ${Slicer_LAUNCH_COMMAND})
  endif()
757
endif()
hliu's avatar
hliu committed
758

759
#-----------------------------------------------------------------------------
760
# NOTE: How to include dependent packages ?
761
#-----------------------------------------------------------------------------
762 763 764 765 766 767 768

# Every Slicer sub project, library or module is responsible
# to call find_package (optionally specifying a list of components)
# and (if it applies) include the associated "use file".
#
# This means that moving forward most of the find_package calls listed below
# will be removed.
769

770 771 772
#-----------------------------------------------------------------------------
# VTK
#-----------------------------------------------------------------------------
jcfr's avatar
jcfr committed
773
find_package(VTK ${Slicer_VTK_VERSION_MAJOR} COMPONENTS ${Slicer_VTK_COMPONENTS} REQUIRED NO_MODULE)
jcfr's avatar
jcfr committed
774 775 776 777
if(NOT TARGET vtkGUISupportQt)
  message(FATAL_ERROR "error: VTK was not configured to use QT, you probably need "
                    "to recompile it with VTK_USE_GUISUPPORT ON, VTK_Group_Qt ON, "
                    "Note that Qt >= ${Slicer_REQUIRED_QT_VERSION} is *required*")
778 779
endif()
include(${VTK_USE_FILE})
780
set(VTK_RENDERING_BACKEND "${Slicer_VTK_RENDERING_BACKEND}")
781 782

#-----------------------------------------------------------------------------
783
# CTK
784
#-----------------------------------------------------------------------------
785 786
find_package(CTK REQUIRED)
include(${CTK_USE_FILE})
787

788
#-----------------------------------------------------------------------------
789
# Update CMake module path
790
#-----------------------------------------------------------------------------
791 792 793
set(CMAKE_MODULE_PATH
  ${CTK_CMAKE_DIR}
  ${CMAKE_MODULE_PATH}
794
  ${CTK_CMAKE_UTILITIES_DIR})
795

796 797 798
#-----------------------------------------------------------------------------
# Set Slicer_PYTHON_VERSION and Slicer_PYTHON_VERSION_DOT
#-----------------------------------------------------------------------------
799 800 801
if(Slicer_USE_PYTHONQT)
  find_package(PythonLibs REQUIRED)
  find_package(PythonInterp REQUIRED)
802 803
  # Extract python lib path
  get_filename_component(PYTHON_DIR_PATH ${PYTHON_EXECUTABLE} PATH)
804 805 806 807
  set(PYTHON_LIBRARY_PATH ${PYTHON_DIR_PATH}/../lib)
  if(WIN32)
    set(PYTHON_LIBRARY_PATH ${PYTHON_DIR_PATH})
  endif()
808
  ctkMacroSetPaths("${PYTHON_LIBRARY_PATH}")
809
  execute_process(
810 811 812
    COMMAND ${PYTHON_EXECUTABLE} -c "import sys; print sys.version[:3]"
    OUTPUT_VARIABLE Slicer_PYTHON_VERSION_DOT
    OUTPUT_STRIP_TRAILING_WHITESPACE)
813
  string(REGEX REPLACE "[.]" "" Slicer_PYTHON_VERSION ${Slicer_PYTHON_VERSION_DOT})
814
  message(STATUS "Configuring ${Slicer_MAIN_PROJECT_APPLICATION_NAME} with python ${Slicer_PYTHON_VERSION_DOT}")
815 816

  set(CTK_COMPILE_PYTHON_SCRIPTS_GLOBAL_TARGET_NAME "Slicer")
817
endif()
818

819
#-----------------------------------------------------------------------------
820 821
# PythonQt
#-----------------------------------------------------------------------------
822
if(Slicer_USE_PYTHONQT)
823 824 825 826
  # 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)
827 828 829
  link_directories(${PYTHONQT_INSTALL_DIR}/lib)
  include(ctkMacroWrapPythonQt)
  include(ctkMacroCompilePythonScript)
830

831
  # Enable qMRMLWidgets python wrapping
832
  set(MRMLWidgets_WRAP_PYTHON ON)
833
endif()
834

835
#-----------------------------------------------------------------------------
836 837
# Teem
#-----------------------------------------------------------------------------
838 839 840
# XXX Waiting teem provide a correct TeemConfig.cmake exporting targets, this is needed
#     to ensure the link_directories for teem is defined and avoid error like:
#     warning: libteem.so.1, needed by ../../../../bin/libvtkTeem.so, may conflict with libteem.so.2
841 842
find_package(Teem REQUIRED)
include(${Teem_USE_FILE})
843

844 845 846 847
#-----------------------------------------------------------------------------
# SlicerExecutionModel settings
#-----------------------------------------------------------------------------
set(SlicerExecutionModel_EXTRA_INCLUDE_DIRECTORIES "" CACHE INTERNAL "SlicerExecutionModel extra includes" FORCE)
848
set(SlicerExecutionModel_EXTRA_EXECUTABLE_TARGET_LIBRARIES "" CACHE INTERNAL "SlicerExecutionModel extra executable target libraries" FORCE)
849

850
#-----------------------------------------------------------------------------
851
# Set Slicer builtin libraries *_DIR variables
852
#-----------------------------------------------------------------------------
853
set(GenerateLM_DIR ${Slicer_BINARY_DIR}/Libs/GenerateLM)
854
set(vtkAddon_DIR ${Slicer_BINARY_DIR}/Libs/vtkAddon)
855
set(vtkITK_DIR ${Slicer_BINARY_DIR}/Libs/vtkITK)
856

857
#-----------------------------------------------------------------------------
858 859
# Set COVERAGE_{C,CXX}_FLAGS variables
#-----------------------------------------------------------------------------
860
include(SlicerBlockCXXCoverageFlags)
861 862

#-----------------------------------------------------------------------------
863
# Set ITK_REQUIRED_{C,CXX}_FLAGS variables
864
#-----------------------------------------------------------------------------
865
include(ITKPlatformSpecificChecks)
866 867 868

#-----------------------------------------------------------------------------
# Set CMAKE_{C,CXX}_FLAGS variables
869
#-----------------------------------------------------------------------------
870 871
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)
872

873 874 875 876
#-----------------------------------------------------------------------------
# Set the header template which defines custom export/import macros
# for shared libraries
#-----------------------------------------------------------------------------
877
set(QMRML_EXPORT_HEADER_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/Libs/MRML/Widgets/CMake/qMRMLExport.h.in")
878

879 880 881
#-----------------------------------------------------------------------------
# Configure testing scripts
#-----------------------------------------------------------------------------
882 883 884 885
set(files
  Utilities/Scripts/computeCodeCoverageLocally.sh
  Utilities/Scripts/computeCodeCoverageForOneTest.sh
  Utilities/Scripts/runExperimentalOffScreen.sh
886
  Utilities/Scripts/setupSlicerEnvironment.sh
887
  )
888 889
foreach(f ${files})
  configure_file(
890 891 892
    ${CMAKE_CURRENT_SOURCE_DIR}/${f}.in
    ${CMAKE_CURRENT_BINARY_DIR}/${f}
    )
893
endforeach()
894

895 896 897
#-----------------------------------------------------------------------------
# Includes
#-----------------------------------------------------------------------------
898
include_directories(
899
  ${CMAKE_CURRENT_SOURCE_DIR}/CMake
900 901
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}
902
  )
903

904
#-----------------------------------------------------------------------------
905
# Subdirectories
906 907
#-----------------------------------------------------------------------------

908 909 910
add_subdirectory(Libs)
add_subdirectory(Base)
add_subdirectory(Resources)
911
add_subdirectory(Utilities/Scripts)
912 913 914 915
if(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT)
  add_subdirectory(Utilities/Scripts/SlicerWizard)
  add_subdirectory(Utilities/Templates)
endif()
916

917
#-----------------------------------------------------------------------------
918
# Macro useful to build ModuleLogic, ModuleMRML and ModuleWidgets libraries
919
#-----------------------------------------------------------------------------
920 921 922 923 924 925
include(SlicerMacroBuildModuleQtLibrary)
include(SlicerMacroBuildModuleVTKLibrary)
include(SlicerMacroPythonWrapModuleVTKLibrary)
include(SlicerMacroBuildModuleLogic)
include(SlicerMacroBuildModuleMRML)
include(SlicerMacroBuildModuleWidgets)
926

927 928 929
#-----------------------------------------------------------------------------
# Slicer Core and GUI library
#-----------------------------------------------------------------------------
930
set(Slicer_CORE_LIBRARY qSlicerBaseQTCore)
931
set(Slicer_GUI_LIBRARY qSlicerBaseQTApp)
932

933
#-----------------------------------------------------------------------------
934
# Applications
935
#-----------------------------------------------------------------------------
936 937
add_subdirectory(Modules/Core)
add_subdirectory(Base/QTApp)
938
add_subdirectory(Modules)
939 940 941 942
add_subdirectory(
  ${Slicer_APPLICATIONS_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}/Applications
  )
943 944 945 946 947 948 949 950 951 952 953

#-----------------------------------------------------------------------------
set(Slicer_USE_FILE ${Slicer_BINARY_DIR}/UseSlicer.cmake)
configure_file(
  ${Slicer_SOURCE_DIR}/CMake/UseSlicer.cmake.in
  ${Slicer_USE_FILE} COPYONLY)

configure_file(
  ${Slicer_SOURCE_DIR}/CMake/SlicerConfigVersion.cmake.in
  ${Slicer_BINARY_DIR}/SlicerConfigVersion.cmake @ONLY)

954
set(Slicer_EXTENSION_GENERATE_CONFIG ${Slicer_SOURCE_DIR}/CMake/SlicerExtensionGenerateConfig.cmake)
955 956
set(Slicer_EXTENSION_CPACK ${Slicer_SOURCE_DIR}/CMake/SlicerExtensionCPack.cmake)

957
# --------------------------------------------------------------------------
958
# Bundle remote modules and extensions adding source directories.
959
# --------------------------------------------------------------------------
960 961 962

set(extensions_build_dir "${Slicer_BINARY_DIR}/E")

963
# Configure a no-op SlicerConfig for bundled projects
964
set(Slicer_DIR ${extensions_build_dir})
965 966 967
configure_file(
  ${Slicer_SOURCE_DIR}/CMake/SlicerConfig.cmake.in
  ${Slicer_DIR}/SlicerConfig.cmake @ONLY)
968

969
#
970 971 972 973
# Directories can be set in three ways:
#
# (1) Automatically by specifying the label 'REMOTE_MODULE' when
#     calling 'Slicer_Remote_Add' from SuperBuild.cmake.
974
#
975
# (2) Automatically by specifying the label 'REMOTE_EXTENSION' when
976 977
#     calling 'Slicer_Remote_Add' from SuperBuild.cmake.
#
978
# (3) Expicitly by configuring the project using the following syntax:
979
#  cmake -DSlicer_EXTENSION_SOURCE_DIRS:STRING=/path/to/ExtensionA;/path/to/ExtensionB /path/to/source/Slicer
980
#
981

982 983 984 985 986 987 988
#
# Support for "SuperBuild-type" extension:
#
# * An extension is considered to be of type "SuperBuild" if a directory
#   "<extension_dir>/SuperBuild" or "<extension_dir>/Superbuild" exists.
#   Corresponding directory is appended to EXTERNAL_PROJECT_ADDITIONAL_DIRS.
#
989 990 991
# * If variable "<extension_name>_EXTERNAL_PROJECT_EXCLUDE_ALL" is set to TRUE, corresponding SuperBuild directory
#   is not appended to EXTERNAL_PROJECT_ADDITIONAL_DIRS.
#
992 993 994 995 996
# * Associated external projects are globbed using expression of the form
#   "<extension_dir>/(SuperBuild|Superbuild)/External_*.cmake".
#
# * List of external project names is extracted from the "External_<projectName>.cmake"
#   files and appended to Slicer_DEPENDENCIES. This ensures they are build before Slicer inner build.
997 998
#   Setting variable "<extension_name>_EXTERNAL_PROJECT_DEPENDENCIES" to a list of <projectName> allows
#   to override the list of <projectName> appended to Slicer_DEPENDENCIES.
999 1000 1001 1002 1003 1004 1005 1006 1007
#
# * Variable Slicer_BUNDLED_EXTENSION_NAMES is updated with the names of external project
#   and passed to Slicer inner build. It is then used in SlicerCPack. to package associated
#   external projects if the cache variable <extensionName>_CPACK_INSTALL_CMAKE_PROJECTS
#   was defined in the extension sources.
#
# Corresponding logic is implemented in SuperBuild.cmake
#

1008
function(_add_extension_source_dir extension_source_dir what)
1009
  get_filename_component(extension_source_dir ${extension_source_dir} REALPATH)
1010
  get_filename_component(extension_source_dirname ${extension_source_dir} NAME_WE)
1011
  message(STATUS "--------------------------------------------------")
1012
  message(STATUS "Configuring ${what}: ${extension_source_dirname}")
1013 1014
  set(ExternalData_SOURCE_ROOT ${extension_source_dir})
  set(${extension_source_dirname}_SOURCE_DIR ${extension_source_dir})
1015
  set(${extension_source_dirname}_BINARY_DIR ${extensions_build_dir}/${extension_source_dirname})
1016 1017 1018 1019
  add_subdirectory(
    ${${extension_source_dirname}_SOURCE_DIR}
    ${${extension_source_dirname}_BINARY_DIR}
    )
1020 1021 1022 1023 1024 1025 1026
endfunction()

foreach(varname ${Slicer_EP_LABEL_REMOTE_MODULE})
  _add_extension_source_dir(${${varname}} "remote module")
endforeach()
foreach(varname ${Slicer_EP_LABEL_REMOTE_EXTENSION})
  _add_extension_source_dir(${${varname}} "remote extension")
1027
endforeach()
1028 1029 1030 1031
foreach(extension_source_dir ${Slicer_EXTENSION_SOURCE_DIRS})
  _add_extension_source_dir(${extension_source_dir} "extension directory")
endforeach()

1032
unset(Slicer_DIR)
1033

1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
# --------------------------------------------------------------------------
# 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
1044
  vtkSlicerVersionConfigureInternal.h
1045 1046 1047 1048 1049 1050 1051
  )
foreach(f ${files})
  configure_file(
    ${CMAKE_CURRENT_SOURCE_DIR}/CMake/${f}.in
    ${CMAKE_CURRENT_BINARY_DIR}/${f}
    )
endforeach()
1052 1053 1054

# Add target configuring 'vtkSlicerVersionConfigure.h' at build time.
include(SlicerConfigureVersionHeaderTarget)
1055
add_dependencies(SlicerBaseLogic SlicerConfigureVersionHeader)
1056
add_dependencies(MRMLCore SlicerConfigureVersionHeader)
1057 1058

list(APPEND files ${CMAKE_CURRENT_BINARY_DIR}/vtkSlicerVersionConfigure.h)
1059

1060
if(NOT Slicer_INSTALL_NO_DEVELOPMENT)
1061 1062
  install(
    FILES ${files}
1063 1064 1065 1066
    DESTINATION ${Slicer_INSTALL_INCLUDE_DIR} COMPONENT Development
    )
endif()

1067 1068
#-----------------------------------------------------------------------------
# Testing
1069
#-----------------------------------------------------------------------------
1070 1071 1072
if(BUILD_TESTING)
  add_subdirectory(Testing)
endif()
1073

1074
# Install testing data
1075 1076
if(NOT Slicer_INSTALL_NO_DEVELOPMENT)
  install(DIRECTORY
1077 1078 1079 1080 1081
    Testing
    DESTINATION ${Slicer_INSTALL_SHARE_DIR} COMPONENT Development
    PATTERN ".svn" EXCLUDE
    PATTERN "CMakeLists.txt" EXCLUDE
    )
1082
endif()
1083

1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
#-----------------------------------------------------------------------------
# Dynamic analysis
#-----------------------------------------------------------------------------
set(Slicer_VALGRIND_SUPPRESSIONS_FILE "${Slicer_SOURCE_DIR}/CMake/SlicerValgrind.supp")
get_property(Slicer_MAIN_PROJECT_APPLICATION_EXECUTABLE GLOBAL PROPERTY "${Slicer_MAIN_PROJECT_APPLICATION_NAME}_EXECUTABLE")
set(script "Utilities/Scripts/runValgrind.sh")
configure_file(
  ${CMAKE_CURRENT_SOURCE_DIR}/${script}.in
  ${CMAKE_CURRENT_BINARY_DIR}/${script}
  @ONLY
  )

1096
#-----------------------------------------------------------------------------
1097
# Documentation
1098
#-----------------------------------------------------------------------------
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
if(Slicer_BUILD_DOCUMENTATION)
  # Automatically generate documentation at build time
  set(all_arg)
  if(DOCUMENTATION_TARGET_IN_ALL)
    set(all_arg "ALL")
  endif()
  add_custom_target(doc ${all_arg})
  add_custom_target(doc-tarballs ${all_arg})

  add_subdirectory(Utilities/Doxygen)
  add_subdirectory(Utilities/Scripts/SlicerWizard/doc)
1110 1111
endif()

1112 1113 1114
#-----------------------------------------------------------------------------
# Install CMake modules
#-----------------------------------------------------------------------------
1115 1116 1117
if(NOT Slicer_INSTALL_NO_DEVELOPMENT)
  file(GLOB cmake_files "${CMAKE_CURRENT_SOURCE_DIR}/CMake/*.cmake")
  install(
1118 1119 1120 1121
    FILES ${cmake_files}
    DESTINATION ${Slicer_INSTALL_LIB_DIR}/CMake COMPONENT Development
    )

1122
  install(FILES
1123 1124
    ${Slicer_BINARY_DIR}/UseSlicer.cmake
    ${Slicer_BINARY_DIR}/SlicerConfig.cmake
1125
    ${Slicer_BINARY_DIR}/SlicerConfigVersion.cmake
1126 1127 1128
    DESTINATION ${Slicer_INSTALL_LIB_DIR}
    COMPONENT Development
    )
1129
endif()
1130

1131 1132 1133 1134 1135
#-----------------------------------------------------------------------------
# Create target to download data from the <Slicer_ExternalData_DATA_MANAGEMENT_TARGET> group.
# This must come after all tests have been added that reference the group, so we put it last.
ExternalData_Add_Target(${Slicer_ExternalData_DATA_MANAGEMENT_TARGET})

1136 1137 1138
#-----------------------------------------------------------------------------
# Create targets CopySlicerPython{Resource, Script}Files, CompileSlicerPythonFiles
if(Slicer_USE_PYTHONQT)
1139 1140 1141 1142 1143
  slicerFunctionAddPythonQtResourcesTargets(SlicerPythonResources)
  ctkFunctionAddCompilePythonScriptTargets(
    ${CTK_COMPILE_PYTHON_SCRIPTS_GLOBAL_TARGET_NAME}
    DEPENDS SlicerPythonResources
    )
1144 1145
endif()

1146 1147 1148 1149
#-----------------------------------------------------------------------------
# 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.
1150
add_subdirectory(CMake/LastConfigureStep)