CMakeLists.txt 93.4 KB
Newer Older
1
#/*============================================================================
Matt Clarkson's avatar
Matt Clarkson committed
2
#
3
#  NifTK: A software platform for medical image computing.
Matt Clarkson's avatar
Matt Clarkson committed
4
#
5
#  Copyright (c) University College London (UCL). All rights reserved.
Matt Clarkson's avatar
Matt Clarkson committed
6 7 8
#
#  This software is distributed WITHOUT ANY WARRANTY; without even
#  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 10 11
#  PURPOSE.
#
#  See LICENSE.txt in the top level directory for details.
Matt Clarkson's avatar
Matt Clarkson committed
12
#
13
#============================================================================*/
14

15 16 17
######################################################################
# Set the minimum CMake version.
######################################################################
18
set(NIFTK_CMAKE_MINIMUM_REQUIRED_VERSION 3.3)
19 20 21 22 23 24 25
cmake_minimum_required(VERSION ${NIFTK_CMAKE_MINIMUM_REQUIRED_VERSION})

##################################################################################
# Set some CMake Policies.
# See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details
##################################################################################

26
set(project_policies
27
  CMP0057 # Support new ``if()`` IN_LIST operator.
28 29
  CMP0063 # Honor visibility properties for all target types.
)
30 31 32 33 34
foreach(policy ${project_policies})
  if(POLICY ${policy})
    cmake_policy(SET ${policy} NEW)
  endif()
endforeach()
35

36
###########################################################################
37
# Precompiled headers
38
###########################################################################
39

40
option(NIFTK_USE_COTIRE "Use Cotire for compilation speed-up." OFF)
41 42
mark_as_advanced(NIFTK_USE_COTIRE)

43
if(NIFTK_USE_COTIRE)
44
  set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake ${CMAKE_MODULE_PATH})
45
  include(cotire)
46 47 48 49 50 51 52
  mark_as_advanced(COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_EXTENSIONS)
  mark_as_advanced(COTIRE_ADDITIONAL_PREFIX_HEADER_IGNORE_PATH)
  mark_as_advanced(COTIRE_DEBUG)
  mark_as_advanced(COTIRE_MAXIMUM_NUMBER_OF_UNITY_INCLUDES)
  mark_as_advanced(COTIRE_MINIMUM_NUMBER_OF_TARGET_SOURCES)
  mark_as_advanced(COTIRE_UNITY_SOURCE_EXCLUDE_EXTENSIONS)
  mark_as_advanced(COTIRE_VERBOSE)
53
endif()
Matt Clarkson's avatar
Matt Clarkson committed
54

55 56 57 58 59
######################################################################
# Organise module/plugin/etc projects better within the IDE.
######################################################################
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

Matt Clarkson's avatar
Matt Clarkson committed
60
######################################################################
61
# We have a super-build option. (Terminology comes from MITK/CTK).
Matt Clarkson's avatar
Matt Clarkson committed
62
######################################################################
63 64

option(BUILD_SUPERBUILD "Build NIFTK and the projects it depends on via SuperBuild.cmake." ON)
65
mark_as_advanced(BUILD_SUPERBUILD)
66 67 68 69 70

if (BUILD_SUPERBUILD)
  project(NIFTK-superbuild)
  set(NIFTK_SOURCE_DIR ${PROJECT_SOURCE_DIR})
  set(NIFTK_BINARY_DIR ${PROJECT_BINARY_DIR})
71
else()
72 73 74
  # Our version number. Edit this to generate a new version.
  # However, be warned, you need to set CMAKE_INSTALL_PREFIX manually.
  # Also, Trac 1592, version number must change if CTK changes significantly.
Matt Clarkson's avatar
Matt Clarkson committed
75
  project(NIFTK VERSION 18.05.5)
76
endif()
Matt Clarkson's avatar
Matt Clarkson committed
77 78

######################################################################
79
# Setting supported build types. Should ONLY be Release or Debug.
Matt Clarkson's avatar
Matt Clarkson committed
80 81
######################################################################

82 83 84
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Valid options are Release or Debug" FORCE)
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug")
85
endif()
Matt Clarkson's avatar
Matt Clarkson committed
86

87 88
if (NOT (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "Debug"))
  message(FATAL_ERROR "Build type \"${CMAKE_BUILD_TYPE}\" is not supported.")
89
endif()
Matt Clarkson's avatar
Matt Clarkson committed
90

91 92 93 94 95
if(WIN32)
  # Restrict the generated configuration to be what we configured above.
  # No point creating project files for build types that will not compile.
  # Note: it's set to FORCE so that both CMAKE_BUILD_TYPE and CMAKE_CONFIGURATION_TYPES match up.
  set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "Build configurations to generate." FORCE)
96
  mark_as_advanced(CMAKE_CONFIGURATION_TYPES)
97
endif()
98 99


100 101 102
#-----------------------------------------------------------------------------
# Additional MITK Options (also shown during superbuild)
#-----------------------------------------------------------------------------
Matt Clarkson's avatar
Matt Clarkson committed
103

104 105 106 107
macro(env_option name doc value)
  set(_value $ENV{${name}})
  if("${_value}" STREQUAL "")
    set(_value ${value})
108
  endif()
109 110
  option(${name} "${doc}" ${_value})
endmacro()
Matt Clarkson's avatar
Matt Clarkson committed
111

112 113 114 115 116
######################################################################
# Configure GUI options from the choice of applications.
# The user cannot be expected to know the component parts of apps.
######################################################################

117
include("${CMAKE_CURRENT_SOURCE_DIR}/MITK/Applications/Apps.cmake")
118
set(BUILD_GUI OFF)
119
mark_as_advanced(BUILD_GUI)
120 121 122 123 124 125
set(BUILD_NiftyView OFF)
mark_as_advanced(BUILD_NiftyView)
set(BUILD_NiftyIGI OFF)
mark_as_advanced(BUILD_NiftyIGI)
set(BUILD_NiftyMIDAS OFF)
mark_as_advanced(BUILD_NiftyMIDAS)
126 127
set(BUILD_NiftyMITK OFF)
mark_as_advanced(BUILD_NiftyMITK)
128 129

# Check each GUI application.
130
foreach(NIFTK_APP ${NIFTK_APPS})
131

132
  # extract option_name
133 134 135 136
  string(REPLACE "^^" "\\;" target_info ${NIFTK_APP})
  set(target_info_list ${target_info})
  list(GET target_info_list 1 option_name)
  list(GET target_info_list 0 app_name)
137

138
  if(${option_name})
139

140
    set(BUILD_GUI ON)
141

142
    if (${app_name} STREQUAL "NiftyView")
143
      set(BUILD_NiftyView ON)
144 145
    endif()

146
    if (${app_name} STREQUAL "NiftyIGI")
147
      set(BUILD_NiftyIGI ON)
148
    endif()
149

150
    if (${app_name} STREQUAL "NiftyMIDAS")
151
      set(BUILD_NiftyMIDAS ON)
152
    endif()
153

154 155
    if (${app_name} STREQUAL "NiftyMITK")
      set(BUILD_NiftyMITK ON)
156
    endif()
157
  endif()
158

159
endforeach()
160

Matt Clarkson's avatar
Matt Clarkson committed
161 162 163 164 165 166
######################################################################
# Options. These are set up front, so are available when configuring
# the SuperBuild, and hence they must also be passed to the normal
# build. So, look in CMake/Superbuild.cmake to see where they are
# passed to the main build of NifTK when doing the Superbuild.
######################################################################
167
option(BUILD_LEGACY_COMMAND_LINE_PROGRAMS "Build legacy command line applications." OFF)
168 169
option(BUILD_COMMAND_LINE_PROGRAMS "Build command line applications." ON)
option(BUILD_COMMAND_LINE_SCRIPTS "Build command line scripts in." ON)
170
option(BUILD_CAMINO "Build Camino." OFF)
171 172 173
option(BUILD_NiftyReg "Build NiftyReg." ON)
option(BUILD_NiftySim "Build NiftySim." ON)
option(BUILD_NiftySeg "Build NiftySeg." ON)
174
option(BUILD_Python "Build Python wrapping." OFF)
175
option(BUILD_PCL "Build PCL - Experimental." OFF)
176
option(BUILD_RTK "Build RTK - Experimental." OFF)
177
if(NOT APPLE AND BUILD_NiftyIGI)
178 179 180
  option(BUILD_VL "Build VisualizationLibrary - Experimental." ON)
else()
  option(BUILD_VL "Build VisualizationLibrary - Experimental." OFF)
181
  set(BUILD_VL OFF CACHE BOOL "Build VisualizationLibrary - Experimental." FORCE)
182 183
endif()

184
option(BUILD_PROTOTYPE "Build prototype code in NifTK/Prototype." OFF)
185
mark_as_advanced(BUILD_PROTOTYPE)
186 187
option(BUILD_SHARED_LIBS "Build NifTK with shared libraries." ON)
option(BUILD_TESTING "Build Unit tests." OFF)
188
option(BUILD_DISPLAY_TESTING "Build Unit tests that require a display window." OFF)
189
option(BUILD_UTILITIES "Build NifTK/Utilities." OFF)
190
option(BUILD_Caffe "Build Caffe." OFF)
191
option(NIFTK_CHECK_COVERAGE "Enable/Disable code coverage checking." OFF)
192
# the console window is normally shown only for debug builds. but can be explicitly enabled.
193
#if(CMAKE_BUILD_TYPE MATCHES "Debug")
194
  set(NIFTK_SHOW_CONSOLE_WINDOW_VAL ON)
195 196 197
#else()
#  set(NIFTK_SHOW_CONSOLE_WINDOW_VAL OFF)
#endif()
198 199 200 201 202 203
option(NIFTK_SHOW_CONSOLE_WINDOW "Use this to enable or disable the console window when starting GUI Applications on Windows" ${NIFTK_SHOW_CONSOLE_WINDOW_VAL})
option(NIFTK_BUILD_ALL_PLUGINS "Build all NIFTK plugins" OFF)
option(NIFTK_GENERATE_DOXYGEN_HELP "Use this to generate Doxygen help in GUI" OFF)
option(NIFTK_VERBOSE_COMPILER_WARNINGS "Add in all the warning flags that MITK does" OFF)
option(NIFTK_USE_FFTW "Use FFTW. Warning FFTW is GPL, so for binary external releases we can't use this. This is used for Kelvin's Fluid registration implementation." OFF)
option(NIFTK_USE_CUDA "Use CUDA. Experimental. " OFF)
204
option(NIFTK_DELAYLOAD_CUDA "(Windows only) If enabled the CUDA DLLs will be a soft delay-load dependency and NifTK can run without them." OFF)
205
option(NIFTK_NIFTYLINK_DEV "Build NiftyLink development branch" OFF)
206
option(NIFTK_RESOLVE_COMMAND_LINE_DEPENDENCIES "For make install, for command line apps, we compute all library dependencies and install them" ON)
Johannes Totz's avatar
Johannes Totz committed
207
option(BUILD_MESHING "Build meshing? Experimental, may nor may not work." OFF)
Matt Clarkson's avatar
Matt Clarkson committed
208

209 210 211
######################################################################
# Meshing module-related checks and options
######################################################################
212
include (CheckIncludeFiles)
213

214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
# Meshing components require CGAL, which is a bit fiddly to get right.
if(BUILD_MESHING)
  if(NOT MSVC)
    # On certain Linux variants, the Superbuild can build CGAL for you.
    # This depends on MPFR/GMP, so this header check here will issue a warning
    # if a required file is missing.
    # The Superbuild will then download a patched version of CGAL 4.4. It's
    # been modified only wrt to VTK 6 compatibility.
    CHECK_INCLUDE_FILES(mpfr.h NIFTK_MESHING_CAN_BUILD)
    if (NOT NIFTK_MESHING_CAN_BUILD)
      message(WARNING "Meshing depends on CGAL depends on MPFR but cannot find mpfr.h. Build will likely fail.")
    endif()
  else()
    # On Windows, the situation is significantly more complicated.
    # GMP will not compile in Visual Studio due to lack of C99 support and/or gcc-isms.
    # Therefore you need to:
    # 1. Build a Superbuild with BUILD_MESHING=OFF
    # 2. Download the Windows version of CGAL 4.4 (or newer?) that includes precompiled GMP/MPFR.
    # 3. Apply the VTK 6 patch from Utilities/cgal-vtk6.diff
    # 4. CMake-configure CGAL, enabling WITH_VTK=ON, explicitly pointing VTK_DIR to the correct Superbuild
    #    VTK from step 1, explicitly set BOOST_ROOT to the correct Superbuild Boost from step 1.
    #    BOOST_ROOT may not show up in the cmake gui, set it anyway.
    # 5. Explicitly define CMAKE_INSTALL_PREFIX to a local path of your choice, e.g. .../CGAL-4.4-install,
    #    making sure you only have slashes in the path, no back-slashes.
    # 6. Compile CGAL, and install it via the install target.
    # 7. Reconfigure NifTK, setting BUILD_MESHING=ON and defining CGAL_DIR to .../CGAL-4.4-install/lib/CGAL.
    # 8. Compile, etc. Should now work fine.
    # x. You will need to rebuild CGAL every time VTK or Boost changes.
    if(NOT CGAL_DIR)
      message(WARNING "Meshing depends on CGAL for which you need to explicitly define CGAL_DIR! Configure will probably fail.")
    endif()
245
  endif()
246
endif(BUILD_MESHING)
247

Matt Clarkson's avatar
Matt Clarkson committed
248
######################################################################
249
# Variables that get compiled into C++ code.
Matt Clarkson's avatar
Matt Clarkson committed
250
######################################################################
251
set(NIFTK_PLATFORM "NifTK" CACHE STRING "Full name of platform." FORCE )
252 253
set(NIFTK_LICENSE_SHORT_STRING "Licensed under BSD 3-clause open-source license." CACHE STRING "Short description of license" FORCE )
set(NIFTK_COPYRIGHT "Copyright (C) 2008-2018 University College London (UCL). All rights reserved." CACHE STRING "Copyright string." FORCE )
254
set(NIFTK_ORIGIN_URL "http://www.ucl.ac.uk/medical-image-computing" CACHE STRING "URL of originating institution." FORCE )
255 256 257 258 259 260 261 262
set(NIFTK_ORIGIN_SHORT_TEXT "CMIC" CACHE STRING "Short name of originating institution." FORCE)
set(NIFTK_ORIGIN_LONG_TEXT "Centre For Medical Image Computing" CACHE STRING "Full name of originating institution." FORCE)
set(NIFTK_USER_CONTACT "https://www.mailinglists.ucl.ac.uk/mailman/listinfo/niftk-users" CACHE STRING "Contact address for users." FORCE )
if(WIN32)
  set(NIFTK_BASE_NAME "NifTK" CACHE STRING "Base name for installation folder. Windows convention is upper case letters" FORCE )
else(WIN32)
  set(NIFTK_BASE_NAME "niftk" CACHE STRING "Base name for installation folder. Unix convention is lower case letters." FORCE )
endif(WIN32)
263
set(NIFTK_VERSION_STRING "${NIFTK_VERSION_MAJOR}.${NIFTK_VERSION_MINOR}.${NIFTK_VERSION_PATCH}" CACHE STRING "String to describe fully named version" FORCE)
264
set(NIFTK_DEPLOY_NAME "${NIFTK_BASE_NAME}-${NIFTK_VERSION_STRING}" CACHE STRING "String to describe deployed name" FORCE)
265
set(NIFTK_DOC_LOCATION "http://cmic.cs.ucl.ac.uk/NifTK/docs/" CACHE STRING "String to describe online documentation location for released versions only." FORCE)
266 267

# Further variables for the external project names and locations are defined
268
# in the external project CMake files under CMake/ExternalProjects.
269

270
set(NIFTK_EP_TARBALL_LOCATION "http://cmic.cs.ucl.ac.uk/platform/dependencies")
271

272
set(NIFTK_LOCATION_PROTOTYPE "https://cmicdev.cs.ucl.ac.uk/svn/cmic/trunk/NiftyPrototype" CACHE STRING  "Location of prototype code (internal access only)")
Matt Clarkson's avatar
Matt Clarkson committed
273 274 275 276

######################################################################
# Hide these variables from the user, unless they are 'advanced' :-)
######################################################################
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
mark_as_advanced(NIFTK_PLATFORM)
mark_as_advanced(NIFTK_LICENSE_SHORT_STRING)
mark_as_advanced(NIFTK_COPYRIGHT)
mark_as_advanced(NIFTK_ORIGIN_URL)
mark_as_advanced(NIFTK_ORIGIN_SHORT_TEXT)
mark_as_advanced(NIFTK_ORIGIN_LONG_TEXT)
mark_as_advanced(NIFTK_HELP_URL_TEXT)
mark_as_advanced(NIFTK_USER_CONTACT)
mark_as_advanced(NIFTK_BASE_NAME)
mark_as_advanced(NIFTK_VERSION_STRING)
mark_as_advanced(NIFTK_DEPLOY_NAME)
mark_as_advanced(NIFTK_SHOW_CONSOLE_WINDOW)
mark_as_advanced(NIFTK_BUILD_ALL_PLUGINS)
mark_as_advanced(NIFTK_CHECK_COVERAGE)
mark_as_advanced(NIFTK_VERBOSE_COMPILER_WARNINGS)
mark_as_advanced(NIFTK_GENERATE_DOXYGEN_HELP)
mark_as_advanced(NIFTK_LOCATION_PROTOTYPE)
mark_as_advanced(NIFTK_USE_FFTW)
mark_as_advanced(NIFTK_USE_CUDA)
296
mark_as_advanced(NIFTK_DELAYLOAD_CUDA)
297 298
mark_as_advanced(NIFTK_NIFTYLINK_DEV)
mark_as_advanced(BUILD_SHARED_LIBS)
299
mark_as_advanced(NIFTK_RESOLVE_COMMAND_LINE_DEPENDENCIES)
300
mark_as_advanced(BUILD_CAMINO)
301
mark_as_advanced(BUILD_PCL)
302
mark_as_advanced(BUILD_VL)
303
mark_as_advanced(BUILD_RTK)
304
mark_as_advanced(BUILD_MESHING)
305
mark_as_advanced(NIFTK_DOC_LOCATION)
306

307 308 309 310 311 312 313
######################################################################
# Make sure Git is available.
######################################################################
find_package(Git REQUIRED)
if (WIN32)
  set(GITCOMMAND ${GIT_EXECUTABLE})
endif()
Matt Clarkson's avatar
Matt Clarkson committed
314

315 316 317 318 319
######################################################################
# Check if Doxygen is available for the GUI help pages.
######################################################################
find_package(Doxygen)

Matt Clarkson's avatar
Matt Clarkson committed
320 321 322
######################################################################
# Setup the path to load CMake macros, and extra CMake files.
######################################################################
323
set(CMAKE_MODULE_PATH
Matt Clarkson's avatar
Matt Clarkson committed
324 325
    ${CMAKE_BINARY_DIR}
    ${CMAKE_SOURCE_DIR}/CMake
326
    ${CMAKE_SOURCE_DIR}/CMake/ExternalProjects
327
    ${CMAKE_SOURCE_DIR}/CMake/cuda
Matt Clarkson's avatar
Matt Clarkson committed
328 329 330 331
    ${CMAKE_MODULE_PATH}
   )

######################################################################
332
# Add in any functions/macros.
Matt Clarkson's avatar
Matt Clarkson committed
333 334
######################################################################
include(mitkMacroEmptyExternalProject)
335
include(mitkFunctionGetVersion)
336
include(mitkFunctionGetGccVersion)
Miklos Espak's avatar
Miklos Espak committed
337
include(mitkFunctionCheckCompilerFlags)
338 339
include(niftkMacroGetGitDateTime)
include(niftkMacroGetGitBranch)
340
include(niftkMacroBuildCLI)
341
include(niftkMacroGenerateCLIScript)
342 343
include(niftkMacroInstallCLIScript)
include(niftkMacroCreateCommandLineApplication)
344
include(niftkMacroCreateCommandLineScript)
345
include(niftkMacroCreateGuiApplication)
346
include(niftkMacroFixupCommandLineApps)
347
include(niftkMacroForcePluginCacheValue)
348
include(CMakePackageConfigHelpers)
Matt Clarkson's avatar
Matt Clarkson committed
349

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
include(mitkFunctionEnableBuildConfiguration)
include(mitkFunctionWhitelists)
include(mitkFunctionAddExternalProject)


# Standard CMake macros
#include(FeatureSummary)
include(CTestUseLaunchers)
#include(CMakeParseArguments)
#include(FindPackageHandleStandardArgs)

# MITK macros
include(mitkFunctionSuppressWarnings) # includes several functions
include(mitkMacroEmptyExternalProject)
#include(mitkFunctionGenerateProjectXml)

SUPPRESS_VC_DEPRECATED_WARNINGS()

Matt Clarkson's avatar
Matt Clarkson committed
368 369 370 371
######################################################################
# Test for some required system information. This came from old
# ITK CMake scripts, so I (Matt) am unsure if we still need it.
######################################################################
372 373
include(${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityC.cmake)
include(${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityCXX.cmake)
Matt Clarkson's avatar
Matt Clarkson committed
374

375

376 377 378 379 380 381 382 383 384 385 386 387 388 389
#-----------------------------------------------------------------------------
# Check miminum Mac OS X version
#-----------------------------------------------------------------------------
# The minimum supported Mac OS X version is 10.9. If you use a version less than 10.9, there is no guarantee that the build still works.
if(APPLE)
  exec_program(sw_vers ARGS -productVersion OUTPUT_VARIABLE osx_version)
  if (osx_version VERSION_LESS "10.10")
    message(WARNING "Detected OS X version \"${osx_version}\" is not supported anymore. Minimum required OS X version is 10.10 or greater.")
  endif()
  if (CMAKE_OSX_DEPLOYMENT_TARGET AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.10)
    message(WARNING "Detected OS X deployment target \"${CMAKE_OSX_DEPLOYMENT_TARGET}\" is not supported anymore. Minimum required OS X version is 10.10 or greater.")
  endif()
endif()

390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
#-----------------------------------------------------------------------------
# Check miminum compiler versions
#-----------------------------------------------------------------------------

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  # require at least gcc 4.7.3 as provided by ppa:ubuntu-toolchain-r/test for Ubuntu 12.04
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.3)
    message(FATAL_ERROR "GCC version must be at least 4.7.3
If you are using Ubuntu 12.04, you can easily install gcc and g++ 4.7.3 (or any later version available) in addition to your version ${CMAKE_CXX_COMPILER_VERSION}:
  sudo add-apt-repository ppa:ubuntu-toolchain-r/test
  sudo apt-get update
  sudo apt-get install gcc-4.7 g++-4.7
Make sure to explicitly specify these compilers when configuring MITK:
  CMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc-4.7
  CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++-4.7
For more information on the proposed PPA see the Toolchain Updates section of https://wiki.ubuntu.com/ToolChain.")
  endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  # require at least clang 3.4 as provided by Ubuntu 12.04
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.4)
    message(FATAL_ERROR "Clang version must be at least 3.4")
  endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
  # require at least clang 5.0
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
    message(FATAL_ERROR "Apple Clang version must be at least 5.0")
  endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  # require at least Visual Studio 2012
  if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17.0.61030.0)
    message(FATAL_ERROR "Microsoft Visual Studio 2012 Update 4 or newer required (MSVC 17.0.61030.0)")
  endif()
else()
  message(WARNING "You are using an unsupported compiler! Compilation has only been tested with Clang (Linux or Apple), GCC and MSVC.")
endif()

if(CMAKE_COMPILER_IS_GNUCXX)
  mitkFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
else()
  set(GCC_VERSION 0)
endif()

set(MITK_CXX_STANDARD 11)

set(CMAKE_CXX_EXTENSIONS 0)
set(CMAKE_CXX_STANDARD ${MITK_CXX_STANDARD})
set(CMAKE_CXX_STANDARD_REQUIRED 1)

# This is necessary to avoid problems with compile feature checks.
# CMAKE_CXX_STANDARD seems to only set the -std=c++11 flag for targets.
# However, compile flag checks also need to be done with -std=c++11.
# The MITK_CXX11_FLAG variable is also used for external projects
# build during the MITK super-build.
mitkFunctionCheckCompilerFlags("-std=c++11" MITK_CXX11_FLAG)
if(NOT MITK_CXX11_FLAG)
  # Older gcc compilers use -std=c++0x
  mitkFunctionCheckCompilerFlags("-std=c++0x" MITK_CXX11_FLAG)
endif()


450
######################################################################
451
# Setting build name based on local system details
452
######################################################################
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469

mitkFunctionGetVersion(${CMAKE_SOURCE_DIR} NIFTK)
niftkMacroGetGitDateTime(${CMAKE_SOURCE_DIR} NIFTK)
niftkMacroGetGitBranch(${CMAKE_SOURCE_DIR} NIFTK)

if(CMAKE_GENERATOR MATCHES Make AND NOT (CMAKE_GENERATOR MATCHES NMake) )

  find_program(UNAME NAMES uname)
  mark_as_advanced(UNAME)

  macro(getuname name flag)
    exec_program("${UNAME}" ARGS "${flag}" OUTPUT_VARIABLE "${name}")
  endmacro(getuname)

  getuname(osname -s)
  getuname(cpu    -m)

470 471 472 473 474 475 476
  if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
    set(CompilerName "gcc")
  elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
    set(CompilerName "clang")
  else()
    set(CompilerName "${CMAKE_CXX_COMPILER_ID}")
  endif()
477

478
  set(CTBN "${osname}-${cpu}-${CompilerName}-${CMAKE_CXX_COMPILER_VERSION}-${NIFTK_BRANCH_NAME}-${NIFTK_REVISION_SHORTID}")
479 480 481 482 483

else()

  set(CTBN "${CMAKE_GENERATOR}-${NIFTK_BRANCH_NAME}-${NIFTK_REVISION_SHORTID}")

484
endif()
485

486 487 488 489 490 491 492 493 494 495 496 497
# append a short release/debug tag, so we know which one is which on the dashboard.
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  set(CTBN "${CTBN}-Dbg")
else()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
  set(CTBN "${CTBN}-Rel")
else()
  # this should not happen. further above we check for Debug and Release and fail if it's neither.
  set(CTBN "${CTBN}-${CMAKE_BUILD_TYPE}")
endif()
endif()

498
string(REPLACE "\n" "" CTBN ${CTBN})
499
set(BUILDNAME ${CTBN} CACHE STRING "${CTBN}" FORCE)
500 501 502 503 504 505 506 507
set(CTEST_BUILD_NAME ${CTBN} CACHE STRING "${CTBN}" FORCE)
mark_as_advanced(BUILDNAME)
mark_as_advanced(CTEST_BUILD_NAME)

message("NifTK branch=${NIFTK_BRANCH_NAME}")
message("NifTK version=${NIFTK_REVISION_SHORTID}")
message("NifTK date=${NIFTK_DATE_TIME}")
message("NifTK build=${CTEST_BUILD_NAME}")
508

509 510 511 512 513 514
# Putting this here, so all subfolders have access to it.
if(CMAKE_COMPILER_IS_GNUCXX)
  mitkFunctionGetGccVersion(${CMAKE_CXX_COMPILER} GCC_VERSION)
  message("NifTK gcc=${GCC_VERSION}")
endif()

515 516 517 518
# -----------------------------------------
# Qt version related variables

if(APPLE)
519
  set(DESIRED_QT_VERSION 5 CACHE STRING "Pick a version of Qt to use: 4 or 5")
520
else()
521

522
  # For now, we stick with Qt 5.
523

524
  set(DESIRED_QT_VERSION 5 CACHE STRING "Pick a version of Qt to use: 4 or 5")
525

526 527 528
endif()

env_option(MITK_USE_QT "Use the Qt Company's Qt library" ON)
529
mark_as_advanced(MITK_USE_QT)
530
env_option(MITK_USE_BLUEBERRY "Use MITK's GUI plugin framework." ON)
531
mark_as_advanced(MITK_USE_BLUEBERRY)
532

533 534 535 536 537 538
set(MITK_DESIRED_QT_VERSION ${DESIRED_QT_VERSION})

if(MITK_USE_QT)
  # find the package at the very beginning, so that QT4_FOUND is available
  if(DESIRED_QT_VERSION MATCHES 4)
    set(MITK_QT4_MINIMUM_VERSION 4.7)
539
    set(MITK_QT4_COMPONENTS QtCore QtGui QtXml QtScript)
540
    if(BUILD_NiftyIGI)
541 542 543
      list(APPEND MITK_QT4_COMPONENTS QtNetwork)
    endif()
    find_package(Qt4 ${MITK_QT4_MINIMUM_VERSION} COMPONENTS ${MITK_QT4_COMPONENTS} REQUIRED)
544
    if(QT_FOUND)
545
      set(QT_USE_QTTEST 1)
546 547 548 549 550 551 552
      set(QT_USE_QTXML 1)
      set(QT_USE_QTXMLPATTERNS 1)
      set(QT_USE_PHONON 0)
      include(${QT_USE_FILE})
      set(MITK_USE_Qt4 TRUE)
      set(MITK_USE_Qt5 FALSE)
    endif()
553 554 555 556 557 558
  endif()
  if(DESIRED_QT_VERSION MATCHES 5)
    set(MITK_QT5_MINIMUM_VERSION 5.0.0)
    set(MITK_USE_Qt4 FALSE)
    set(MITK_USE_Qt5 TRUE)
    set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}" CACHE PATH "")
559
    mark_as_advanced(CMAKE_PREFIX_PATH)
560 561 562 563 564 565 566 567
    set(MITK_QT5_COMPONENTS Concurrent OpenGL PrintSupport Script Sql Svg Widgets WebKitWidgets Xml XmlPatterns UiTools Help)
    find_package(Qt5 ${MITK_QT5_MINIMUM_VERSION} COMPONENTS ${MITK_QT5_COMPONENTS} REQUIRED)
    if(Qt5_DIR)
      get_filename_component(_Qt5_DIR "${Qt5_DIR}/../../../" ABSOLUTE)
      list(FIND CMAKE_PREFIX_PATH "${_Qt5_DIR}" _result)
      if(_result LESS 0)
        set(CMAKE_PREFIX_PATH "${_Qt5_DIR};${CMAKE_PREFIX_PATH}" CACHE PATH "" FORCE)
      endif()
568
      set(NifTK_PREFIX_PATH ${_Qt5_DIR})
569 570 571 572 573 574 575
    endif()
  endif()
else()
  set(MITK_USE_Qt4 FALSE)
  set(MITK_USE_Qt5 FALSE)
endif()

576 577 578
# ------------------------------------------------------------------------
# Register external projects which can be build with the MITK superbuild
# system. Each mitkFunctionAddExternalProject() call registers an external
579
# project for which a ExternalProjects/<project>.cmake file must exist. The
580 581
# call also creates a MITK_USE_<project> variable (appearing in the CMake
# UI if the NO_CACHE option is *not* given).
582 583 584 585 586
#
# Although the options are called 'MITK_USE_*', they mean whether NifTK uses
# those projects. To avoid confusion, we mark these options advanced so that
# they do not appear in the CMake GUI. We expose the 'BUILD_*' options to the
# users and set the 'MITK_USE_*' options accordingly.
587 588

# -----------------------------------------
589
# The following external projects must be ordered according to their inter-dependencies.
590 591 592

set_property(GLOBAL PROPERTY MITK_EXTERNAL_PROJECTS "")
#mitkFunctionAddExternalProject(NAME Camino OFF ADVANCED)
Matt Clarkson's avatar
Matt Clarkson committed
593 594 595 596

mitkFunctionAddExternalProject(NAME ZLIB      OFF ADVANCED NO_PACKAGE NO_CACHE)
mitkFunctionAddExternalProject(NAME PCRE      OFF ADVANCED NO_PACKAGE)
mitkFunctionAddExternalProject(NAME SWIG      OFF ADVANCED NO_PACKAGE DEPENDS PCRE)
597
mitkFunctionAddExternalProject(NAME Python    OFF ADVANCED NO_PACKAGE DEPENDS ZLIB SWIG DOC "Use Python wrapping in NifTK")
Matt Clarkson's avatar
Matt Clarkson committed
598
mitkFunctionAddExternalProject(NAME Numpy     OFF ADVANCED NO_PACKAGE DEPENDS Python)
Matt Clarkson's avatar
Matt Clarkson committed
599

600 601 602
mitkFunctionAddExternalProject(NAME Boost     ON  ADVANCED)
mitkFunctionAddExternalProject(NAME Eigen     ON  ADVANCED)
mitkFunctionAddExternalProject(NAME OpenCV    OFF ADVANCED)
603
mitkFunctionAddExternalProject(NAME AprilTags OFF ADVANCED DEPENDS OpenCV Eigen)
604 605 606 607 608
mitkFunctionAddExternalProject(NAME ArUco     OFF ADVANCED DEPENDS OpenCV)
mitkFunctionAddExternalProject(NAME FLANN     OFF ADVANCED)

mitkFunctionAddExternalProject(NAME VL        OFF ADVANCED)
mitkFunctionAddExternalProject(NAME CGAL      OFF ADVANCED DEPENDS Boost)
609
mitkFunctionAddExternalProject(NAME NiftyLink OFF ADVANCED)
610 611 612
mitkFunctionAddExternalProject(NAME NiftySim  OFF ADVANCED NO_PACKAGE)
mitkFunctionAddExternalProject(NAME NiftySeg  OFF ADVANCED NO_PACKAGE DEPENDS Eigen)
mitkFunctionAddExternalProject(NAME NiftyReg  OFF ADVANCED NO_PACKAGE)
613
mitkFunctionAddExternalProject(NAME NifTKData OFF ADVANCED)
614

615 616
mitkFunctionAddExternalProject(NAME DCMTK     ON  ADVANCED)
mitkFunctionAddExternalProject(NAME GDCM      ON  ADVANCED)
617
mitkFunctionAddExternalProject(NAME HDF5      OFF ADVANCED NO_PACKAGE) # Needs to be built prior to ITK (used by Caffe)
618 619 620
mitkFunctionAddExternalProject(NAME ITK       ON  ADVANCED NO_CACHE DEPENDS GDCM)
mitkFunctionAddExternalProject(NAME SimpleITK OFF ADVANCED DEPENDS ITK GDCM SWIG)
mitkFunctionAddExternalProject(NAME VTK       ON  ADVANCED NO_CACHE)
621
mitkFunctionAddExternalProject(NAME PCL       OFF ADVANCED DEPENDS Boost Eigen FLANN VTK)
622 623
mitkFunctionAddExternalProject(NAME CTK       ON  ADVANCED DEPENDS QT ITK VTK DCMTK)
mitkFunctionAddExternalProject(NAME MITK      ON  ADVANCED NO_CACHE DEPENDS ITK VTK GDCM DCMTK CTK Eigen)
Matt Clarkson's avatar
Matt Clarkson committed
624

625 626
mitkFunctionAddExternalProject(NAME SlicerExecutionModel ON ADVANCED DEPENDS ITK)
mitkFunctionAddExternalProject(NAME RTK                  OFF ADVANCED DEPENDS ITK GDCM)
627

628 629
mitkFunctionAddExternalProject(NAME NiftyCal  OFF ADVANCED DEPENDS OpenCV AprilTags Eigen ITK)

630 631 632 633 634
mitkFunctionAddExternalProject(NAME OpenBLAS       OFF ADVANCED NO_PACKAGE)
mitkFunctionAddExternalProject(NAME ProtoBuf       OFF ADVANCED NO_PACKAGE)
mitkFunctionAddExternalProject(NAME ProtoBuf-CMake OFF ADVANCED NO_PACKAGE ProtoBuf)
mitkFunctionAddExternalProject(NAME gflags         OFF ADVANCED NO_PACKAGE)
mitkFunctionAddExternalProject(NAME glog           OFF ADVANCED NO_PACKAGE gflags)
635

636
set(_caffe_depends Boost ProtoBuf-CMake ProtoBuf glog gflags HDF5)
637 638 639
if(NOT APPLE)
  list(APPEND _caffe_depends OpenBLAS)
endif()
640
mitkFunctionAddExternalProject(NAME Caffe    OFF ADVANCED NO_PACKAGE DEPENDS ${_caffe_depends})
641

642 643 644
# -----------------------------------------
# Other MITK_USE_* options not related to external projects build via the NifTK superbuild

645
env_option(MITK_USE_OpenCL "Use OpenCL GPU-Computing library" ON)
646

647
if (BUILD_NiftyIGI)
648 649 650
  set(MITK_USE_AprilTags ON CACHE BOOL "" FORCE)
  set(MITK_USE_ArUco ON CACHE BOOL "" FORCE)
  set(MITK_USE_NiftyLink ON CACHE BOOL "" FORCE)
651
  set(MITK_USE_NiftyCal ON CACHE BOOL "" FORCE)
652
  set(MITK_USE_OpenCV ON CACHE BOOL "" FORCE)
653
  set(MITK_USE_HDF5 ON CACHE BOOL "" FORCE)
654 655 656 657
else()
  set(MITK_USE_AprilTags OFF CACHE BOOL "" FORCE)
  set(MITK_USE_ArUco OFF CACHE BOOL "" FORCE)
  set(MITK_USE_NiftyLink OFF CACHE BOOL "" FORCE)
658
  set(MITK_USE_NiftyCal OFF CACHE BOOL "" FORCE)
659
  set(MITK_USE_OpenCV OFF CACHE BOOL "" FORCE)
660
  set(MITK_USE_HDF5 OFF CACHE BOOL "" FORCE)
661 662
endif()

663 664 665 666 667 668
if (BUILD_PCL)
  set(MITK_USE_PCL ON CACHE BOOL "" FORCE)
else()
  set(MITK_USE_PCL OFF CACHE BOOL  "" FORCE)
endif()

669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
if (BUILD_NiftyReg)
  set(MITK_USE_NiftyReg ON CACHE BOOL "" FORCE)
else()
  set(MITK_USE_NiftyReg OFF CACHE BOOL "" FORCE)
endif()

if (BUILD_NiftySeg)
  set(MITK_USE_NiftySeg ON CACHE BOOL "" FORCE)
else()
  set(MITK_USE_NiftySeg OFF CACHE BOOL "" FORCE)
endif()

if (BUILD_NiftySim)
  set(MITK_USE_NiftySim ON CACHE BOOL "" FORCE)
else()
  set(MITK_USE_NiftySim OFF CACHE BOOL "" FORCE)
endif()

687 688 689 690 691 692
if (BUILD_VL)
  set(MITK_USE_VL ON CACHE BOOL "" FORCE)
else()
  set(MITK_USE_VL OFF CACHE BOOL "" FORCE)
endif()

693 694 695 696 697 698
if (BUILD_RTK)
  set(MITK_USE_RTK ON CACHE BOOL "" FORCE)
else()
  set(MITK_USE_RTK OFF CACHE BOOL "" FORCE)
endif()

699
if (BUILD_Caffe)
700
  set(MITK_USE_Caffe          ON CACHE BOOL "" FORCE)
701 702 703
  if (NOT APPLE)
    set(MITK_USE_OpenBLAS     ON CACHE BOOL "" FORCE)
  endif()
704 705
  set(MITK_USE_ProtoBuf       ON CACHE BOOL "" FORCE) 
  set(MITK_USE_ProtoBuf-CMake ON CACHE BOOL "" FORCE)
706 707
  set(MITK_USE_glog           ON CACHE BOOL "" FORCE)
  set(MITK_USE_gflags         ON CACHE BOOL "" FORCE)
708
  set(MITK_USE_HDF5           ON CACHE BOOL "" FORCE)
709
else()
710
  set(MITK_USE_Caffe          OFF CACHE BOOL "" FORCE)
711 712 713
  if (NOT APPLE)
    set(MITK_USE_OpenBLAS       OFF CACHE BOOL "" FORCE)
  endif()
714 715
  set(MITK_USE_ProtoBuf       OFF CACHE BOOL "" FORCE)
  set(MITK_USE_ProtoBuf-CMake OFF CACHE BOOL "" FORCE)
716 717
  set(MITK_USE_glog           OFF CACHE BOOL "" FORCE)
  set(MITK_USE_gflags         OFF CACHE BOOL "" FORCE)
718
  set(MITK_USE_HDF5           OFF CACHE BOOL "" FORCE)
719 720
endif()

721 722 723
######################################################################
# Python: Sanity check for supported Qt version. Only >= 5.3 is supported by CTK/PythonQt
######################################################################
724
if(MITK_USE_Qt5 AND BUILD_Python)
725 726 727 728 729
  set(minimum_required_python_qt5_version "5.3.0")
  find_package(Qt5 COMPONENTS Core REQUIRED)

  if(${Qt5Core_VERSION_STRING} VERSION_LESS ${minimum_required_python_qt5_version})
    message(WARNING "Can't build MITK Python with Qt version < ${minimum_required_python_qt5_version}. Disabling Python support")
730
    set(BUILD_Python OFF)
731 732 733 734
  endif()
endif()

######################################################################
735
# Python: Only Windows can't build Python in debug mode
736
######################################################################
737 738 739 740 741 742 743
if(BUILD_Python AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND WIN32)
  message(WARNING "Disabling Python support. Building MITK Python in debug mode on Windows is not supported.")
  set(BUILD_Python OFF)
endif()

if(BUILD_Python)
  set(MITK_USE_Python ON CACHE BOOL "Use Python wrapping in MITK" FORCE)
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
  if(NOT MITK_USE_Numpy)
    message("> Forcing MITK_USE_Numpy to ON because of MITK_USE_Python")
    set(MITK_USE_Numpy ON CACHE BOOL "Use Numpy" FORCE)
  endif()
  if(NOT MITK_USE_SimpleITK)
    message("> Forcing MITK_USE_SimpleITK to ON because of MITK_USE_Python")
    set(MITK_USE_SimpleITK ON CACHE BOOL "Use SimpleITK" FORCE)
  endif()
  if(NOT MITK_USE_SWIG)
    message("> Forcing MITK_USE_SWIG to ON because of MITK_USE_Python")
    set(MITK_USE_SWIG ON CACHE BOOL "Use SWIG" FORCE)
  endif()
  if(NOT MITK_USE_PCRE)
    message("> Forcing MITK_USE_PCRE to ON because of MITK_USE_Python")
    set(MITK_USE_PCRE ON CACHE BOOL "Use PCRE" FORCE)
  endif()
  if(NOT MITK_USE_ZLIB)
    message("> Forcing MITK_USE_ZLIB to ON because of MITK_USE_Python")
    set(MITK_USE_ZLIB ON CACHE BOOL "Use ZLIB" FORCE)
  endif()

765
  option(MITK_USE_SYSTEM_PYTHON "Use the system Python runtime" OFF)
766 767 768 769
  if(MITK_USE_SYSTEM_PYTHON)
    find_package(PythonLibs REQUIRED)
    find_package(PythonInterp REQUIRED)
  endif()
770 771 772 773 774 775 776 777

else()
  set(MITK_USE_Python OFF CACHE BOOL "Use Python wrapping in MITK" FORCE)
  set(MITK_USE_Numpy OFF CACHE BOOL "Use Numpy" FORCE)
  set(MITK_USE_SimpleITK OFF CACHE BOOL "Use SimpleITK" FORCE)
  set(MITK_USE_SWIG OFF CACHE BOOL "Use SWIG" FORCE)
  set(MITK_USE_PCRE OFF CACHE BOOL "Use PCRE" FORCE)
  set(MITK_USE_ZLIB OFF CACHE BOOL "Use ZLIB" FORCE)
778 779
endif()

780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
#-----------------------------------------------------------------------------
# Build configurations
#-----------------------------------------------------------------------------

set(_buildConfigs "Custom")

file(GLOB _buildConfigFiles CMake/BuildConfigurations/*.cmake)

foreach(_buildConfigFile ${_buildConfigFiles})
  get_filename_component(_buildConfigFile ${_buildConfigFile} NAME_WE)
  list(APPEND _buildConfigs ${_buildConfigFile})
endforeach()

set(MITK_BUILD_CONFIGURATION "Custom" CACHE STRING "Use pre-defined MITK configurations")
mark_as_advanced(MITK_BUILD_CONFIGURATION)
set_property(CACHE MITK_BUILD_CONFIGURATION PROPERTY STRINGS ${_buildConfigs})

mitkFunctionEnableBuildConfiguration()

mitkFunctionCreateWhitelistPaths(NifTK)
mitkFunctionFindWhitelists(NifTK)

Matt Clarkson's avatar
Matt Clarkson committed
802 803
######################################################################
# Configure Dart testing support.  This should be done before any
804
# message(FATAL_ERROR ...) commands are invoked.
Matt Clarkson's avatar
Matt Clarkson committed
805
######################################################################
806 807 808 809
include(${CMAKE_ROOT}/Modules/Dart.cmake)
mark_as_advanced(TCL_TCLSH DART_ROOT)
enable_testing()
if(BUILD_TESTING)
810
  configure_file(${CMAKE_SOURCE_DIR}/Documentation/Images/NifTKLogo.gif
Matt Clarkson's avatar
Matt Clarkson committed
811 812
                 ${CMAKE_BINARY_DIR}/Testing/HTML/TestingResults/Icons/Logo.gif
                 COPYONLY IMMEDIATE)
813 814
  set(BUILDNAME "${BUILDNAME}" CACHE STRING "Name of build on the dashboard")
  mark_as_advanced(BUILDNAME)
815

816
  # Setup file for setting custom ctest vars
817
  configure_file(CMake/CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake @ONLY)
818 819 820 821

  # Setup continuous test script
  CONFIGURE_FILE(CMake/CTestContinuous.cmake.in ${CMAKE_BINARY_DIR}/CTestContinuous.cmake @ONLY)

822
endif(BUILD_TESTING)
Matt Clarkson's avatar
Matt Clarkson committed
823 824 825 826 827

######################################################################
# Platform checks:
# Check availability of some standard API functions
######################################################################
828 829
include(${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
include(${CMAKE_ROOT}/Modules/CheckIncludeFiles.cmake)
830
CHECK_FUNCTION_EXISTS(mkstemps HAVE_MKSTEMPS)
831
CHECK_INCLUDE_FILES("sys/socket.h" HAVE_SYS_SOCKET_H)
832 833 834
if(HAVE_SYS_SOCKET_H)
  add_definitions("-DHAVE_SYS_SOCKET_H")
endif()
Matt Clarkson's avatar
Matt Clarkson committed
835 836 837 838 839

###########################################################################
# Set these compiler flags early, so it can be applied to all dependencies.
###########################################################################

840
set(NIFTK_ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags for NifTK only")
841
mark_as_advanced(NIFTK_ADDITIONAL_C_FLAGS)
842
set(NIFTK_ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags for NifTK only")
843
mark_as_advanced(NIFTK_ADDITIONAL_CXX_FLAGS)
Matt Clarkson's avatar
Matt Clarkson committed
844

845 846 847 848 849 850 851 852 853 854 855 856
set(MITK_ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags for MITK only")
mark_as_advanced(MITK_ADDITIONAL_C_FLAGS)
set(MITK_ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags for MITK only")
mark_as_advanced(MITK_ADDITIONAL_CXX_FLAGS)
set(CTK_ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags for CTK only")
mark_as_advanced(CTK_ADDITIONAL_C_FLAGS)
set(CTK_ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags for CTK only")
mark_as_advanced(CTK_ADDITIONAL_CXX_FLAGS)
set(OPENCV_ADDITIONAL_C_FLAGS "" CACHE STRING "Additional C Flags for OpenCV only")
mark_as_advanced(OPENCV_ADDITIONAL_C_FLAGS)
set(OPENCV_ADDITIONAL_CXX_FLAGS "" CACHE STRING "Additional CXX Flags for OpenCV only")
mark_as_advanced(OPENCV_ADDITIONAL_CXX_FLAGS)
857 858
set(OPENCV_WITH_CUDA OFF CACHE BOOL "Build OpenCV with CUDA support (takes a long time)")
mark_as_advanced(OPENCV_WITH_CUDA)
859 860
set(OPENCV_WITH_NONFREE OFF CACHE BOOL "Build OpenCV with nonfree library")
mark_as_advanced(OPENCV_WITH_NONFREE)
Matt Clarkson's avatar
Matt Clarkson committed
861

862 863 864
set(NIFTYSIM_USE_CUDA OFF CACHE BOOL "Build NiftySim with CUDA support")
mark_as_advanced(NIFTYSIM_USE_CUDA)

865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881
######################################################################
# GPL restricted options. These must default to off.
# Basically, a researcher/developer can turn them on and use them.
# But we cannot distribute binaries unless we distribute code
# under the GPL, which we do not want to do. So, do not distribute.
######################################################################
option(BUILD_ITKFFTW "Build ITK's FFTW - Not Supported, do not distribute, due to GPL restrictions." OFF)
mark_as_advanced(BUILD_ITKFFTW)
if(BUILD_ITKFFTW)
  message(WARNING "You have chosen to compile FFTW. This means the binary code, and all executables linked against it will be covered by GPL. This means if you distribute binaries, you must also distribute all the NifTK source code and all the FFTW source code using the GPL license. Hence this option is not supported by NifTK.")
endif(BUILD_ITKFFTW)

option(OPENCV_WITH_FFMPEG "Build OpenCV with FFMPEG support - Not Supported, do not distribute, due to GPL restrictions." OFF)
mark_as_advanced(OPENCV_WITH_FFMPEG)
if(OPENCV_WITH_FFMPEG)
  message(WARNING "You have chosen to compile FFmpeg support. This is not recommended. It is possible to distribute FFmpeg under LGPLv2.1, but only if you fully comply with the legal requirements, and specifically, as FFmpeg contains GPL code, do not compile GPL code into FFmpeg. If you compile GPL code into FFmpeg and distribute binaries, you must also distribute all the NifTK source code along with all the FFmpeg source code using the GPL license. Hence this option is not supported by NifTK.")
endif()
882

Matt Clarkson's avatar
Matt Clarkson committed
883 884 885 886 887
########################################################################
# Set NIFTK_INSTALL_PREFIX, and NIFTK_LINK_PREFIX, used in scripts.
# Note: DONT try changing CMAKE_INSTALL_PREFIX. Think of it as reserved.
########################################################################

888 889
get_filename_component(NIFTK_LINK_PREFIX ${CMAKE_INSTALL_PREFIX} PATH)
set(NIFTK_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
Matt Clarkson's avatar
Matt Clarkson committed
890 891 892 893

######################################################################
# Sanity Checks before doing Superbuild.
######################################################################
894 895 896 897 898
if(BUILD_GUI)
  if(NOT BUILD_SHARED_LIBS)
    message(FATAL_ERROR "If you wan't to build a GUI, you must use dynamic linking, turn BUILD_SHARED to ON.")
  endif(NOT BUILD_SHARED_LIBS)
endif(BUILD_GUI)
Matt Clarkson's avatar
Matt Clarkson committed
899

900 901 902
if(BUILD_GUI)
  set(NIFTK_GENERATE_DOXYGEN_HELP ON)
endif(BUILD_GUI)
Matt Clarkson's avatar
Matt Clarkson committed
903

904 905 906 907 908 909
########################################################################
# Simplest if we list ALL our include directories here.
# We need to reference the CMAKE_BINARY_DIR, as we generate stuff there.
########################################################################
set(NIFTK_INCLUDE_DIRS_BUILD_TREE
  ${CMAKE_BINARY_DIR}
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 936 937 938 939 940 941 942 943 944 945 946 947
  ${CMAKE_SOURCE_DIR}/Libraries/Common
  ${CMAKE_SOURCE_DIR}/Libraries/Common/Exceptions
  ${CMAKE_SOURCE_DIR}/Libraries/MIDAS
  ${CMAKE_SOURCE_DIR}/Libraries/VTK
  ${CMAKE_SOURCE_DIR}/Libraries/VTK/Common
  ${CMAKE_SOURCE_DIR}/Libraries/ITK
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/Common
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/BasicFilters
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/IO
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/Numerics
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/Pipelines
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/BoundaryShiftIntegral
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/BreastCancerImaging
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/CorticalThickness
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/RegistrationToolbox
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/RegistrationToolbox/Metrics
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/RegistrationToolbox/Methods
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/RegistrationToolbox/Transforms
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/RegistrationToolbox/Optimizers
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/RegistrationToolbox/Commands
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/RegistrationToolbox/Construction
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/RegistrationToolbox/Constraints
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/RegistrationToolbox/Filters
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/2D3DToolbox/Methods
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/2D3DToolbox/Optimizers
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/2D3DToolbox/Projection
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/2D3DToolbox/Metrics
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/2D3DToolbox/Commands
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/2D3DToolbox/xRay
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/2D3DToolbox/Transforms
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/Segmentation
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/Segmentation/MIDASMorphologicalEditor
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/Segmentation/MIDASIrregularVolumeEditor
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/Testing
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/Testing/RegistrationToolBox
  ${CMAKE_SOURCE_DIR}/Libraries/ITK/VesselToolbox
  ${CMAKE_SOURCE_DIR}/Libraries/ITKVTK/IO
  ${CMAKE_SOURCE_DIR}/Libraries/ITKIO
948
)
949 950
if (BUILD_MESHING)
  set(NIFTK_INCLUDE_DIRS_BUILD_TREE
951
    ${NIFTK_INCLUDE_DIRS_BUILD_TREE}
952
    ${CMAKE_SOURCE_DIR}/Libraries/Meshing
953
  )
954
endif (BUILD_MESHING)
955

Matt Clarkson's avatar
Matt Clarkson committed
956 957 958 959
######################################################################
# Find CUDA: Required by the Nifty packages
######################################################################

960 961 962
if(NIFTK_USE_CUDA)
  find_package(CUDA)
  if(CUDA_FOUND)
963
    set(NIFTK_INCLUDE_DIRS_BUILD_TREE ${NIFTK_INCLUDE_DIRS_BUILD_TREE} ${CUDA_TOOLKIT_INCLUDE})
964 965 966
    add_definitions(-D_USE_CUDA)
    set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-D_USE_CUDA")
    message("Found CUDA")
967
    if(APPLE)
Matt Clarkson's avatar
Matt Clarkson committed
968
      set(CMAKE_SHARED_LINKER_FLAGS "-F/Library/Frameworks ${CMAKE_SHARED_LINKER_FLAGS}")
969
    endif()
970 971 972 973
  else(CUDA_FOUND)
    message("Didn't find CUDA")
  endif(CUDA_FOUND)
endif(NIFTK_USE_CUDA)
Matt Clarkson's avatar
Matt Clarkson committed
974

975 976 977
######################################################################
# Find NVidia API: Required for NVidia SDI pipeline in IGI GUI
######################################################################
978 979 980
find_package(NVidiaAPI)
if(NVAPI_FOUND)
  message("Found NVidia API")
981 982 983 984 985 986 987
  if (CUDA_FOUND AND NIFTK_USE_CUDA)
    set(NIFTK_INCLUDE_DIRS_BUILD_TREE ${NIFTK_INCLUDE_DIRS_BUILD_TREE} ${NVAPI_INCLUDE_DIR})
    add_definitions(-D_USE_NVAPI)
  else()
    message("NVidia API disabled: need CUDA. Try NIFTK_USE_CUDA.")
    set(NVAPI_FOUND 0)
  endif()
988 989 990
else()
  message("Did not find NVidia API")
endif()
991

Matt Clarkson's avatar
Matt Clarkson committed
992 993
######################################################################
# Now, if required, do the SuperBuild
994
# If we are doing SuperBuild
Matt Clarkson's avatar
Matt Clarkson committed
995
#   We configure up to this point (see the return() statement)
996
#   and then we call SuperBuild.cmake, which builds all the
Matt Clarkson's avatar
Matt Clarkson committed
997 998 999 1000 1001 1002 1003 1004 1005 1006
#   dependencies as CMake ExternalProjects, and then also builds
#   NifTK as an ExternalProject. However instead of downloading
#   a tar file, you set the SOURCE_DIR to be THIS project, and force
#   the BUILD_SUPERBUILD flag to be off (to avoid infinite loop).
#
# If we are NOT doing superbuild, then the next statement has no
# effect, and the build goes on the same as before, as in version
# NifTK 2.2.0 and earlier.
######################################################################

1007 1008 1009 1010
if(BUILD_SUPERBUILD)
  include("CMake/SuperBuild.cmake")
  return()
endif(BUILD_SUPERBUILD)
Matt Clarkson's avatar
Matt Clarkson committed
1011

1012

Matt Clarkson's avatar
Matt Clarkson committed
1013 1014
######################################################################
# End of SuperBuild. Print out where the source and binary folders
1015
# are, just to make it really explicit... well, explicit to the user
Matt Clarkson's avatar
Matt Clarkson committed
1016 1017 1018
# that bothers to read these messages! :-)
######################################################################

1019 1020
message("CMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR}")
message("CMAKE_BINARY_DIR=${CMAKE_BINARY_DIR}")
Matt Clarkson's avatar
Matt Clarkson committed
1021

1022 1023 1024 1025 1026 1027 1028 1029
######################################################################
# Add additional entries to the CMAKE_MODULE_PATH, now all externals
# are already built.
######################################################################
set(CMAKE_MODULE_PATH
    ${aruco_DIR}/lib/cmake
    ${CMAKE_MODULE_PATH}
   )
1030

1031 1032 1033 1034 1035 1036
######################################################################
# Configure CMake files before we need to use them in the FIND_XXX.
#
# So, the variables NIFTK_BOOSTINSTALL etc.
# should be passed in on cmake command line, or set up using ccmake.
######################################################################
1037

1038 1039 1040 1041
find_package(aruco)
if(aruco_FOUND)
  configure_file(${CMAKE_SOURCE_DIR}/CMake/FindArUco.cmake ${CMAKE_BINARY_DIR}/FindArUco.cmake @ONLY)
endif()
1042 1043 1044 1045 1046 1047
configure_file(${CMAKE_SOURCE_DIR}/CMake/FindFFTW.cmake ${CMAKE_BINARY_DIR}/FindFFTW.cmake @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/CMake/FindNiftyReg.cmake ${CMAKE_BINARY_DIR}/FindNiftyReg.cmake @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/CMake/FindNiftySim.cmake ${CMAKE_BINARY_DIR}/FindNiftySim.cmake @ONLY)
configu