CMakeLists.txt 9.72 KB
Newer Older
1
cmake_minimum_required(VERSION 3.8...3.12 FATAL_ERROR)
2 3 4 5 6 7 8
foreach(policy
    CMP0083 # CMake 3.14
    )
  if(POLICY ${policy})
    cmake_policy(SET ${policy} NEW)
  endif()
endforeach()
9

10 11 12 13
if(CMAKE_SYSTEM_NAME STREQUAL "Android" AND CMAKE_VERSION VERSION_LESS 3.7)
  message(FATAL_ERROR "CMake 3.7 or above is required to build for Android")
endif()

14 15 16 17 18 19 20
if (POLICY CMP0063)
  cmake_policy(SET CMP0063 NEW)
endif ()
if (POLICY CMP0065)
  cmake_policy(SET CMP0065 NEW)
endif ()

21
project(VTK)
22

23 24
set(vtk_cmake_dir "${VTK_SOURCE_DIR}/CMake")
list(INSERT CMAKE_MODULE_PATH 0 "${vtk_cmake_dir}")
25

26 27 28 29
if (APPLE)
  include(vtkApple)
endif ()

Ken Martin's avatar
Ken Martin committed
30 31 32 33 34
# must be before the following iOS / Android
include(vtkVersion)
set(VTK_VERSION
    "${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION}")

35 36 37 38 39 40 41 42 43 44 45 46 47 48
option(VTK_IOS_BUILD "Build vtk.framework for iOS" OFF)
mark_as_advanced(VTK_IOS_BUILD)
if (VTK_IOS_BUILD)
  include(vtkiOS)
  return()
endif()

option(VTK_ANDROID_BUILD "Build VTK for Android" OFF)
mark_as_advanced(VTK_ANDROID_BUILD)
if (VTK_ANDROID_BUILD)
  include(vtkAndroid)
  return()
endif()

49
include(vtkCompilerChecks)
50
include(vtkCompilerPlatformFlags)
51
include(vtkCompilerExtraFlags)
52
include(vtkInitializeBuildType)
53
include(vtkSupportMacros)
54
include(vtkDownload)
55
include(vtkTesting)
56
include(vtkDirectories)
57
include(vtkMobileDevices)
58
include(vtkCrossCompiling)
59
include(vtkWrapSettings)
60
include(vtkObjectFactory)
61
include(vtkCMakeBackports)
62

63 64 65 66
# Setup compiler flags for dynamic analysis
# Should be included after vtkTesting
include(vtkCompilerDynamicAnalysisFlags)

67 68
#-----------------------------------------------------------------------------
# Do we want examples built?
69
option(VTK_BUILD_EXAMPLES "Build VTK examples." OFF)
70

71
set(VTK_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
72 73
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
74

75 76
#-----------------------------------------------------------------------------
# Add the Remote Subdirectory
77
#add_subdirectory(Remote)
78

79 80
#-----------------------------------------------------------------------------
# Does VTK require support for 64 bit file systems
81
include(CheckCXXSourceRuns)
82
file(READ "${vtk_cmake_dir}/vtkRequireLargeFilesSupport.cxx"
83
  VTK_REQUIRE_LARGE_FILE_SUPPORT_FILE)
84
check_cxx_source_runs("${VTK_REQUIRE_LARGE_FILE_SUPPORT_FILE}"
85
  CMAKE_REQUIRE_LARGE_FILE_SUPPORT "Support for 64 bit file systems")
86
set(VTK_REQUIRE_LARGE_FILE_SUPPORT ${CMAKE_REQUIRE_LARGE_FILE_SUPPORT})
87

88
#-----------------------------------------------------------------------------
89
# Provide compatibility options.
90
option(VTK_LEGACY_REMOVE "Remove all legacy code completely." OFF)
91 92
option(VTK_LEGACY_SILENT "Silence all legacy code messages." OFF)
mark_as_advanced(VTK_LEGACY_REMOVE VTK_LEGACY_SILENT)
93

94 95
# Tell VTK source files they are being built inside VTK.
add_definitions(-DVTK_IN_VTK)
96

97
include(CheckTypeSize)
Ken Martin's avatar
Ken Martin committed
98

99 100 101 102 103
# Kits bundle multiple modules together into a single library, this
# is used to dramatically reduce the number of generated libraries.
option(VTK_ENABLE_KITS "Build VTK using kits instead of modules." OFF)
mark_as_advanced(VTK_ENABLE_KITS)

104 105 106 107 108 109 110 111
option(VTK_USE_MPI "Support MPI" OFF)

set(VTK_BUILD_TESTING "DEFAULT"
  CACHE STRING "Build all modules by default")
set_property(CACHE VTK_BUILD_TESTING
  PROPERTY
    STRINGS "ON;OFF;DEFAULT")

112 113
include(vtkEncodeString)

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
set(vtk_requested_modules)
set(vtk_rejected_modules)
if (VTK_WRAP_PYTHON)
  list(APPEND vtk_requested_modules
    VTK::WrappingPythonCore
    VTK::WrappingTools
    VTK::PythonInterpreter)
else ()
  list(APPEND vtk_rejected_modules
    VTK::Python)
endif ()
if (VTK_WRAP_JAVA)
  list(APPEND vtk_requested_modules
    VTK::Java
    VTK::WrappingTools)
else ()
  list(APPEND vtk_rejected_modules
    VTK::Java)
endif ()
if (VTK_USE_MPI)
  set(VTK_GROUP_ENABLE_MPI ON)
else ()
  # Reject `VTK::mpi`, but allow those which happen to be part of the group to
  # be built.
138
  set(_vtk_module_group_default_MPI "DONT_WANT")
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
  list(APPEND vtk_rejected_modules
    VTK::mpi)
endif ()

if (VTK_BUILD_TESTING)
  list(APPEND vtk_requested_modules
    # Required for just about all VTK tests.
    VTK::TestingCore)
endif ()

list(APPEND vtk_requested_modules
  # Required for just about everything.
  VTK::CommonCore
  VTK::CommonDataModel
  # Required for wrapping with hierarchy files.
  VTK::WrappingTools)

if (vtk_requested_modules)
  list(REMOVE_DUPLICATES vtk_requested_modules)
endif ()
if (vtk_rejected_modules)
  list(REMOVE_DUPLICATES vtk_rejected_modules)
endif ()

set_property(GLOBAL
  PROPERTY
    "_vtk_module_autoinit_include" "\"vtkAutoInit.h\"")

option(VTK_BUILD_ALL_MODULES "Build all modules by default" OFF)
mark_as_advanced(VTK_BUILD_ALL_MODULES)

# Turn on these groups by default.
set(_vtk_module_group_default_StandAlone "WANT")
set(_vtk_module_group_default_Rendering "WANT")

include(vtkModule)
175
set(vtk_source_directories
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
  "${CMAKE_CURRENT_SOURCE_DIR}/Accelerators"
  "${CMAKE_CURRENT_SOURCE_DIR}/Charts"
  "${CMAKE_CURRENT_SOURCE_DIR}/Common"
  "${CMAKE_CURRENT_SOURCE_DIR}/Domains"
  "${CMAKE_CURRENT_SOURCE_DIR}/Filters"
  "${CMAKE_CURRENT_SOURCE_DIR}/Geovis"
  "${CMAKE_CURRENT_SOURCE_DIR}/GUISupport"
  "${CMAKE_CURRENT_SOURCE_DIR}/Imaging"
  "${CMAKE_CURRENT_SOURCE_DIR}/Infovis"
  "${CMAKE_CURRENT_SOURCE_DIR}/Interaction"
  "${CMAKE_CURRENT_SOURCE_DIR}/IO"
  "${CMAKE_CURRENT_SOURCE_DIR}/Parallel"
  "${CMAKE_CURRENT_SOURCE_DIR}/Rendering"
  "${CMAKE_CURRENT_SOURCE_DIR}/Testing"
  "${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty"
  "${CMAKE_CURRENT_SOURCE_DIR}/Utilities"
  "${CMAKE_CURRENT_SOURCE_DIR}/Views"
  "${CMAKE_CURRENT_SOURCE_DIR}/Web"
  "${CMAKE_CURRENT_SOURCE_DIR}/Wrapping")
195 196
vtk_module_find_modules(vtk_module_files ${vtk_source_directories})
vtk_module_find_kits(vtk_kit_files ${vtk_source_directories})
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
vtk_module_scan(
  MODULE_FILES        ${vtk_module_files}
  KIT_FILES           ${vtk_kit_files}
  REQUEST_MODULES     ${vtk_requested_modules}
  REJECT_MODULES      ${vtk_rejected_modules}
  PROVIDES_MODULES    vtk_modules
  PROVIDES_KITS       vtk_kits
  REQUIRES_MODULES    vtk_required_modules
  UNRECOGNIZED_MODULES vtk_unrecognized_modules
  WANT_BY_DEFAULT     "${VTK_BUILD_ALL_MODULES}"
  ENABLE_TESTS        "${VTK_BUILD_TESTING}")

if (vtk_required_modules OR vtk_unrecognized_modules)
  message(FATAL_ERROR
    "The following modules were requested or required, but not found: "
    "${vtk_required_modules};${vtk_unrecognized_modules}.")
endif ()

215 216 217 218 219 220
list(FIND vtk_modules "VTK::Python" vtk_python_idx)
if (NOT vtk_python_idx EQUAL "-1")
  include(vtkModuleWrapPython)
  vtk_module_python_default_destination(VTK_PYTHON_SITE_PACKAGES_SUFFIX)
endif ()

221 222 223
set(vtk_cmake_destination
  "${CMAKE_INSTALL_LIBDIR}/cmake/vtk-${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}")

224 225
option(VTK_ENABLE_KITS "Enable kits compilation" OFF)
mark_as_advanced(VTK_ENABLE_KITS)
226

227 228 229 230 231 232 233 234
option(VTK_USE_EXTERNAL "Use external copies of third party libraries by default" OFF)
mark_as_advanced(VTK_USE_EXTERNAL)

vtk_module_build(
  MODULES             ${vtk_modules}
  KITS                ${vtk_kits}
  INSTALL_EXPORT      VTK
  HEADERS_DESTINATION "include/vtk-${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}"
235
  CMAKE_DESTINATION   "${vtk_cmake_destination}"
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
  LIBRARY_NAME_SUFFIX "${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}"
  VERSION             "${VTK_VERSION}"
  SOVERSION           "1"
  TEST_DATA_TARGET    VTKData
  BUILD_WITH_KITS     "${VTK_ENABLE_KITS}"
  USE_EXTERNAL        "${VTK_USE_EXTERNAL}"
  TEST_INPUT_DATA_DIRECTORY   "${CMAKE_CURRENT_SOURCE_DIR}/Testing"
  TEST_OUTPUT_DATA_DIRECTORY  "${CMAKE_CURRENT_BINARY_DIR}/ExternalData/Testing")
include(vtkModuleJson)
vtk_module_json(
  MODULES ${vtk_modules}
  OUTPUT  "modules.json")
include(vtkModuleGraphviz)
vtk_module_graphviz(
  MODULES ${vtk_modules}
  KIT_CLUSTERS ON
  PRIVATE_DEPENDENCIES OFF
  OUTPUT  "modules.dot")

ExternalData_Add_Target(VTKData)
256 257 258 259 260 261 262 263 264 265
# Create target to download data from the VTKData group.  This must come after
# all tests have been added that reference the group, so we put it last.
if(VTK_DATA_EXCLUDE_FROM_ALL)
  set_property(TARGET VTKData PROPERTY EXCLUDE_FROM_ALL 1)
  if(BUILD_TESTING AND NOT VTK_DATA_EXCLUDE_FROM_ALL_NO_WARNING)
    message(WARNING "VTK_DATA_EXCLUDE_FROM_ALL is ON so test data "
      "(needed because BUILD_TESTING is ON) may not be available "
      "without manually building the 'VTKData' target.")
  endif()
endif()
266 267 268 269 270 271 272

if (VTK_WRAP_PYTHON)
  vtk_module_wrap_python(
    MODULES         ${vtk_modules}
    INSTALL_EXPORT  VTK
    PYTHON_PACKAGE  "vtkmodules"
    MODULE_DESTINATION  "${VTK_PYTHON_SITE_PACKAGES_SUFFIX}"
273
    CMAKE_DESTINATION   "${vtk_cmake_destination}"
274 275
    WRAPPED_MODULES vtk_python_wrapped_modules
    TARGET          VTK::vtkpythonmodules)
276

277
  add_subdirectory(Wrapping/Python)
278 279
endif ()

280 281 282 283
if (VTK_WRAP_JAVA)
  add_subdirectory(Wrapping/Java)
endif ()

284
set(vtk_cmake_build_dir
285 286
  "${CMAKE_CURRENT_BINARY_DIR}/${vtk_cmake_destination}")
include(vtkInstallCMakePackage)
287

288 289 290 291 292
configure_file(
  "${vtk_cmake_dir}/CTestCustom.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake"
  @ONLY)

293 294 295 296 297
option(VTK_BUILD_EXAMPLES "Build VTK examples." OFF)
if (VTK_BUILD_EXAMPLES)
  add_subdirectory(Examples)
endif ()

298 299 300 301
if(BUILD_TESTING)
  add_subdirectory(Testing/Install)
endif()

302
# The doxygen documentation needs to be aware of all modules.
303 304
option(VTK_BUILD_DOCUMENTATION "Build the VTK documentation" OFF)
if(VTK_BUILD_DOCUMENTATION)
305 306 307
  add_subdirectory(Utilities/Doxygen)
endif()

308 309 310 311 312 313 314
# If python wrapping and testing is enabled then add driver scripts to run
# tests.  Note: Many pythong tests used to be automatically converted from TCL
# scripts. Hence the name vtkTclTest2Py
if(BUILD_TESTING AND VTK_WRAP_PYTHON)
  add_subdirectory(Utilities/vtkTclTest2Py)
endif()

315 316
# TODO: The VTKCompileTools package.
# TODO: HeaderTest exclusions for memcheck.
317

318 319 320
#-----------------------------------------------------------------------------
# Do this at the end so the all variables it uses are setup.
include(vtkBuildPath)