1# Figure out which languages are being wrapped, and add them to the list. 2if(BUILD_TESTING) 3 set(_test_languages "Cxx") 4 if(VTK_WRAP_PYTHON) 5 list(APPEND _test_languages "Python") 6 endif() 7 if(VTK_WRAP_TCL) 8 list(APPEND _test_languages "Tcl") 9 endif() 10 if(VTK_WRAP_JAVA) 11 list(APPEND _test_languages "Java") 12 endif() 13else() 14 set(_test_languages "") 15endif() 16 17#---------------------------------------------------------------------- 18# Load the module DAG. 19 20# Remove old ${vtk-module}.*.cmake files generated for enabled modules. 21# These will be re-written on currently enabled modules. 22file(GLOB module_files "${VTK_MODULES_DIR}/*.cmake") 23if (module_files) 24 file(REMOVE ${module_files}) 25endif() 26 27# This is a little hackish, but define the rendering backend if none was passed 28# in for the first CMake invocation for modules that depend on the backend 29# chosen. 30if(NOT DEFINED VTK_RENDERING_BACKEND) 31 set(VTK_RENDERING_BACKEND "OpenGL") 32 set(_backend_set_for_first_cmake TRUE) 33endif() 34 35# Assess modules, and tests in the repository. 36vtk_module_search(${_test_languages}) 37 38# Need to ensure the state is restored so that cache variable defaults can be 39# added if necessary on the first CMake run, offering up the choice of backend. 40if(_backend_set_for_first_cmake) 41 unset(VTK_RENDERING_BACKEND) 42endif() 43 44# Now include the module group logic. 45include(vtkGroups) 46 47# Now figure out which rendering backend to use. 48include(vtkBackends) 49 50# Validate the module DAG. 51macro(vtk_module_check vtk-module _needed_by stack) 52 if(NOT ${vtk-module}_DECLARED) 53 message(FATAL_ERROR "No such module \"${vtk-module}\" needed by \"${_needed_by}\"") 54 endif() 55 if(check_started_${vtk-module} AND NOT check_finished_${vtk-module}) 56 # We reached a module while traversing its own dependencies recursively. 57 set(msg "") 58 foreach(entry ${stack}) 59 set(msg " ${entry} =>${msg}") 60 if("${entry}" STREQUAL "${vtk-module}") 61 break() 62 endif() 63 endforeach() 64 message(FATAL_ERROR "Module dependency cycle detected:\n ${msg} ${vtk-module}") 65 elseif(NOT check_started_${vtk-module}) 66 # Traverse dependencies of this module. Mark the start and finish. 67 set(check_started_${vtk-module} 1) 68 foreach(dep IN LISTS ${vtk-module}_DEPENDS) 69 vtk_module_check(${dep} ${vtk-module} "${vtk-module};${stack}") 70 endforeach() 71 set(check_finished_${vtk-module} 1) 72 endif() 73endmacro() 74 75foreach(vtk-module ${VTK_MODULES_ALL}) 76 vtk_module_check("${vtk-module}" "" "") 77endforeach() 78 79#---------------------------------------------------------------------- 80 81# Provide an option for all modules. 82option(VTK_BUILD_ALL_MODULES "Request to build all modules" OFF) 83mark_as_advanced(VTK_BUILD_ALL_MODULES) 84 85include(CMakeDependentOption) 86cmake_dependent_option(VTK_BUILD_ALL_MODULES_FOR_TESTS 87 "Enable modules as needed for testing all the enabled modules" OFF 88 "BUILD_TESTING" OFF) 89mark_as_advanced(VTK_BUILD_ALL_MODULES_FOR_TESTS) 90 91# Provide an option for each module. 92foreach(vtk-module ${VTK_MODULES_ALL}) 93 if(NOT ${vtk-module}_IS_TEST) 94 option(Module_${vtk-module} "Request building ${vtk-module}" 95 ${${vtk-module}_DEFAULT}) 96 mark_as_advanced(Module_${vtk-module}) 97 if(${vtk-module}_EXCLUDE_FROM_ALL) 98 set(${vtk-module}_IN_ALL 0) 99 else() 100 set(${vtk-module}_IN_ALL ${VTK_BUILD_ALL_MODULES}) 101 endif() 102 endif() 103endforeach() 104 105# Follow dependencies. 106macro(vtk_module_enable vtk-module _needed_by) 107 if(NOT Module_${vtk-module}) 108 list(APPEND ${vtk-module}_NEEDED_BY ${_needed_by}) 109 endif() 110 if(NOT ${vtk-module}_ENABLED) 111 set(${vtk-module}_ENABLED 1) 112 foreach(dep IN LISTS ${vtk-module}_DEPENDS) 113 vtk_module_enable(${dep} ${vtk-module}) 114 endforeach() 115 foreach(imp IN LISTS ${vtk-module}_IMPLEMENTATIONS) 116 vtk_module_enable(${imp} ${vtk-module}) 117 endforeach() 118 119 # If VTK_BUILD_ALL_MODULES_FOR_TESTS is true, then and then 120 # alone do we include the test modules in building build the dependency 121 # graph for enabled modules (BUG #13297). 122 if (VTK_BUILD_ALL_MODULES_FOR_TESTS) 123 foreach(test IN LISTS ${vtk-module}_TESTED_BY) 124 vtk_module_enable(${test} "") 125 endforeach() 126 elseif (BUILD_TESTING) 127 # identify vtkTesting<> dependencies on the test module and enable them. 128 # this ensures that core testing modules such as vtkTestingCore, 129 # vtkTestingRendering which many test modules depend on, are automatically 130 # enabled. 131 foreach(test IN LISTS ${vtk-module}_TESTED_BY) 132 foreach(test-depends IN LISTS ${test}_DEPENDS) 133 if (test-depends MATCHES "^vtkTesting.*") 134 vtk_module_enable(${test-depends} "") 135 endif() 136 endforeach() 137 endforeach() 138 endif() 139 endif() 140endmacro() 141 142foreach(vtk-module ${VTK_MODULES_ALL}) 143 if(Module_${vtk-module} OR ${vtk-module}_IN_ALL) 144 vtk_module_enable("${vtk-module}" "") 145 elseif(${vtk-module}_REQUEST_BY) 146 vtk_module_enable("${vtk-module}" "${${vtk-module}_REQUEST_BY}") 147 endif() 148endforeach() 149 150foreach(vtk-module ${VTK_MODULES_ALL}) 151 # Exclude modules that exist only to test this module 152 # from the report of modules that need this one. They 153 # are enabled exactly because this module is enabled. 154 if(${vtk-module}_NEEDED_BY AND ${vtk-module}_TESTED_BY) 155 list(REMOVE_ITEM ${vtk-module}_NEEDED_BY "${${vtk-module}_TESTED_BY}") 156 endif() 157endforeach() 158 159# Build final list of enabled modules. 160set(VTK_MODULES_ENABLED "") 161set(VTK_MODULES_DISABLED "") 162foreach(vtk-module ${VTK_MODULES_ALL}) 163 if(${vtk-module}_ENABLED) 164 list(APPEND VTK_MODULES_ENABLED ${vtk-module}) 165 else() 166 list(APPEND VTK_MODULES_DISABLED ${vtk-module}) 167 endif() 168endforeach() 169 170if (NOT VTK_BUILD_ALL_MODULES_FOR_TESTS) 171 # If VTK_BUILD_ALL_MODULES_FOR_TESTS is OFF, it implies that we didn't add any 172 # test modules to the dependecy graph. We now add the test modules for all 173 # enabled modules iff the all the test dependecies are already satisfied 174 # (BUG #13297). 175 foreach(vtk-module IN LISTS VTK_MODULES_ENABLED) 176 foreach(test IN LISTS ${vtk-module}_TESTED_BY) 177 # if all test-dependencies are satisfied, enable it. 178 set (missing_dependencis) 179 foreach(test-depends IN LISTS ${test}_DEPENDS) 180 list(FIND VTK_MODULES_ENABLED ${test-depends} found) 181 if (found EQUAL -1) 182 list(APPEND missing_dependencis ${test-depends}) 183 endif() 184 endforeach() 185 if (NOT missing_dependencis) 186 vtk_module_enable(${test} "") 187 list(APPEND VTK_MODULES_ENABLED ${test}) 188 else() 189 message(STATUS 190 "Disable test module ${test} since required modules are not enabled: ${missing_dependencis}") 191 endif() 192 endforeach() 193 endforeach() 194endif() 195 196list(SORT VTK_MODULES_ENABLED) # Deterministic order. 197list(SORT VTK_MODULES_DISABLED) # Deterministic order. 198 199# Order list to satisfy dependencies. 200include(CMake/TopologicalSort.cmake) 201topological_sort(VTK_MODULES_ENABLED "" _DEPENDS) 202set(vtk_modules_and_kits ${VTK_MODULES_ENABLED}) 203if(VTK_ENABLE_KITS) 204 set(vtk_kits) 205 foreach(module IN LISTS VTK_MODULES_ENABLED) 206 if(${module}_KIT) 207 set(kit ${${module}_KIT}) 208 # Set kit management variables. 209 set(_${kit}_is_kit 1) 210 list(APPEND _${kit}_modules ${module}) 211 list(APPEND vtk_kits ${kit}) 212 list(APPEND ${kit}_KIT_DEPENDS ${module}) 213 else() 214 set(kit ${module}) 215 endif() 216 217 # The module graph is modified so that any M1 -> M2 dependency, if ${M2_KIT} 218 # is set, an edge is added for M1 -> ${M2_KIT}, however, if ${M1_KIT} is the 219 # same as ${M2_KIT}, the kit dependency is ignored. 220 221 foreach(dep IN LISTS ${module}_DEPENDS) 222 if(${dep}_KIT) 223 # Ignore self dependencies. 224 if(NOT kit STREQUAL ${dep}_KIT) 225 # Depend on the dependency's kit. 226 list(APPEND ${module}_KIT_DEPENDS ${${dep}_KIT}) 227 endif() 228 endif() 229 230 # Keep the original dependency. 231 list(APPEND ${module}_KIT_DEPENDS ${dep}) 232 endforeach() 233 endforeach() 234 235 # Put all kits in the list (if they are not dependencies of any module, they 236 # will be dropped otherwise). 237 list(APPEND vtk_modules_and_kits ${vtk_kits}) 238 239 # Sort all modules and kits. 240 topological_sort(vtk_modules_and_kits "" _KIT_DEPENDS) 241endif() 242 243 244# Report what will be built. 245set(_modules_enabled_alpha "${VTK_MODULES_ENABLED}") 246list(SORT _modules_enabled_alpha) 247list(REMOVE_ITEM _modules_enabled_alpha vtkWrappingJava vtkWrappingPythonCore) 248list(LENGTH _modules_enabled_alpha _length) 249message(STATUS "Enabled ${_length} modules:") 250foreach(vtk-module ${_modules_enabled_alpha}) 251 if(NOT ${vtk-module}_IS_TEST) 252 if(Module_${vtk-module}) 253 set(_reason ", requested by Module_${vtk-module}.") 254 elseif(${vtk-module}_IN_ALL) 255 set(_reason ", requested by VTK_BUILD_ALL_MODULES.") 256 else() 257 set(_needed_by "${${vtk-module}_NEEDED_BY}") 258 list(SORT _needed_by) 259 list(LENGTH _needed_by _length) 260 if(_length GREATER "1") 261 set(_reason ", needed by ${_length} modules:") 262 foreach(dep ${_needed_by}) 263 set(_reason "${_reason}\n ${dep}") 264 endforeach() 265 else() 266 set(_reason ", needed by ${_needed_by}.") 267 endif() 268 endif() 269 if(VTK_ENABLE_KITS AND ${vtk-module}_KIT) 270 set(_kit " (kit: ${${vtk-module}_KIT})") 271 else() 272 set(_kit) 273 endif() 274 message(STATUS " * ${vtk-module}${_kit}${_reason}") 275 endif() 276endforeach() 277 278# Hide options for modules that will build anyway. 279foreach(vtk-module ${VTK_MODULES_ALL}) 280 if(NOT ${vtk-module}_IS_TEST) 281 if(${vtk-module}_IN_ALL OR ${vtk-module}_NEEDED_BY) 282 set_property(CACHE Module_${vtk-module} PROPERTY TYPE INTERNAL) 283 else() 284 set_property(CACHE Module_${vtk-module} PROPERTY TYPE BOOL) 285 endif() 286 endif() 287endforeach() 288 289if(NOT VTK_MODULES_ENABLED) 290 message(WARNING "No modules enabled!") 291 file(REMOVE "${VTK_BINARY_DIR}/VTKTargets.cmake") 292 return() 293endif() 294 295file(WRITE "${VTK_BINARY_DIR}/VTKTargets.cmake" 296 "# Generated by CMake, do not edit!") 297 298macro(verify_vtk_module_is_set) 299 if("" STREQUAL "${vtk-module}") 300 message(FATAL_ERROR "CMake variable vtk-module is not set") 301 endif() 302endmacro() 303 304macro(init_module_vars) 305 verify_vtk_module_is_set() 306 set(${vtk-module}-targets VTKTargets) 307 set(${vtk-module}-targets-install "${VTK_INSTALL_PACKAGE_DIR}/VTKTargets.cmake") 308 set(${vtk-module}-targets-build "${VTK_BINARY_DIR}/VTKTargets.cmake") 309endmacro() 310 311# VTK_WRAP_PYTHON_MODULES can be used to explicitly control which modules 312# get Python wrapped (no automatic dependency support is provided at this 313# time). If it has been set mark the modules in the list as such. 314# Note any wrap exclude entries in the module.cmake will take precedence 315# If entry has not been set default to VTK_MODULES_ENABLED. 316if(VTK_WRAP_PYTHON) 317 if(NOT VTK_WRAP_PYTHON_MODULES) 318 set(VTK_WRAP_PYTHON_MODULES ${VTK_MODULES_ENABLED}) 319 endif() 320endif() 321 322macro(_vtk_build_module _module) 323 set(vtk-module ${_module}) 324 325 if(NOT ${_module}_IS_TEST) 326 init_module_vars() 327 else() 328 set(vtk-module ${${_module}_TESTS_FOR}) 329 endif() 330 331 include("${${_module}_SOURCE_DIR}/vtk-module-init.cmake" OPTIONAL) 332 add_subdirectory("${${_module}_SOURCE_DIR}" "${${_module}_BINARY_DIR}") 333endmacro() 334 335# Build all modules. 336foreach(kit IN LISTS vtk_modules_and_kits) 337 if(_${kit}_is_kit) 338 set(_vtk_build_as_kit ${kit}) 339 set(kit_srcs) 340 foreach(kit_module IN LISTS _${kit}_modules) 341 list(APPEND kit_srcs $<TARGET_OBJECTS:${kit_module}Objects>) 342 endforeach() 343 344 configure_file("${_VTKModuleMacros_DIR}/vtkKit.cxx.in" 345 "${CMAKE_CURRENT_BINARY_DIR}/${kit}Kit.cxx" @ONLY) 346 add_library(${kit} "${CMAKE_CURRENT_BINARY_DIR}/${kit}Kit.cxx" ${kit_srcs}) 347 get_property(kit_libs GLOBAL 348 PROPERTY 349 ${kit}_LIBS) 350 set(kit_priv) 351 set(kit_pub) 352 set(is_priv) 353 foreach(lib IN LISTS kit_libs) 354 if(lib STREQUAL LINK_PUBLIC) 355 set(is_priv 0) 356 elseif(lib STREQUAL LINK_PRIVATE) 357 set(is_priv 1) 358 else() 359 if(${lib}_KIT) 360 set(lib ${${lib}_KIT}) 361 endif() 362 if(is_priv) 363 list(APPEND kit_priv ${lib}) 364 else() 365 list(APPEND kit_pub ${lib}) 366 endif() 367 endif() 368 endforeach() 369 if(kit_priv) 370 list(REMOVE_DUPLICATES kit_priv) 371 list(REMOVE_ITEM kit_priv ${kit}) 372 endif() 373 if(kit_pub) 374 list(REMOVE_DUPLICATES kit_pub) 375 list(REMOVE_ITEM kit_pub ${kit}) 376 endif() 377 target_link_libraries(${kit} 378 LINK_PRIVATE ${kit_priv} 379 LINK_PUBLIC ${kit_pub}) 380 vtk_target(${kit}) 381 else() 382 if(VTK_ENABLE_KITS) 383 set(_vtk_build_as_kit ${${kit}_KIT}) 384 else() 385 set(_vtk_build_as_kit) 386 endif() 387 _vtk_build_module(${kit}) 388 endif() 389endforeach() 390unset(vtk-module) 391 392#---------------------------------------------------------------------- 393# Generate VTKConfig* files 394 395# Construct version numbers for VTKConfigVersion.cmake. 396SET(_VTK_VERSION_MAJOR ${VTK_MAJOR_VERSION}) 397SET(_VTK_VERSION_MINOR ${VTK_MINOR_VERSION}) 398SET(_VTK_VERSION_PATCH ${VTK_BUILD_VERSION}) 399 400# Create list of available modules and libraries. 401set(VTK_CONFIG_MODULES_ENABLED "") 402foreach(vtk-module ${VTK_MODULES_ENABLED}) 403 if(NOT ${vtk-module}_IS_TEST) 404 list(APPEND VTK_CONFIG_MODULES_ENABLED ${vtk-module}) 405 endif() 406endforeach() 407 408# Generate VTKConfig.cmake for the build tree. 409set(VTK_CONFIG_CODE " 410set(VTK_MODULES_DIR \"${VTK_MODULES_DIR}\")") 411set(VTK_CONFIG_CMAKE_DIR "${VTK_SOURCE_DIR}/CMake") 412set(VTK_CONFIG_TARGETS_CONDITION " AND NOT VTK_BINARY_DIR") 413set(VTK_CONFIG_TARGETS_FILE "${VTK_BINARY_DIR}/VTKTargets.cmake") 414set(VTK_CONFIG_MODULE_API_FILE "${VTK_SOURCE_DIR}/CMake/vtkModuleAPI.cmake") 415# Target used to ensure VTKConfig is load just once 416set(VTK_COMMON_TARGET vtkCommonCore) 417configure_file(CMake/VTKConfig.cmake.in VTKConfig.cmake @ONLY) 418 419# Generate VTKConfig.cmake for the install tree. 420set(VTK_CONFIG_CODE " 421# Compute the installation prefix from this VTKConfig.cmake file location. 422set(_vtk_installed_prefix \"${CMAKE_INSTALL_PREFIX}/${VTK_INSTALL_PACKAGE_DIR}\") 423set(_vtk_requested_prefix \"\${CMAKE_CURRENT_LIST_DIR}\") 424get_filename_component(_vtk_installed_prefix_full \"\${_vtk_installed_prefix}\" REALPATH) 425get_filename_component(_vtk_requested_prefix_full \"\${_vtk_requested_prefix}\" REALPATH) 426if (_vtk_installed_prefix_full STREQUAL _vtk_requested_prefix_full) 427 set(VTK_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\") 428else () 429 set(VTK_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_DIR}\")") 430 431# Construct the proper number of get_filename_component(... PATH) 432# calls to compute the installation prefix. 433string(REGEX REPLACE "/" ";" _count "${VTK_INSTALL_PACKAGE_DIR}") 434foreach(p ${_count}) 435 set(VTK_CONFIG_CODE "${VTK_CONFIG_CODE} 436 get_filename_component(VTK_INSTALL_PREFIX \"\${VTK_INSTALL_PREFIX}\" PATH)") 437endforeach() 438 439set(VTK_CONFIG_CODE "${VTK_CONFIG_CODE} 440endif ()") 441 442set(VTK_CONFIG_CODE "${VTK_CONFIG_CODE} 443set(VTK_MODULES_DIR \"\${VTK_INSTALL_PREFIX}/${VTK_INSTALL_PACKAGE_DIR}/Modules\")") 444set(VTK_CONFIG_CMAKE_DIR "\${VTK_INSTALL_PREFIX}/${VTK_INSTALL_PACKAGE_DIR}") 445set(VTK_CONFIG_TARGETS_CONDITION "") 446set(VTK_CONFIG_TARGETS_FILE "\${VTK_INSTALL_PREFIX}/${VTK_INSTALL_PACKAGE_DIR}/VTKTargets.cmake") 447set(VTK_CONFIG_MODULE_API_FILE "\${VTK_INSTALL_PREFIX}/${VTK_INSTALL_PACKAGE_DIR}/vtkModuleAPI.cmake") 448configure_file(CMake/VTKConfig.cmake.in CMakeFiles/VTKConfig.cmake @ONLY) 449 450include(CMakePackageConfigHelpers) 451write_basic_package_version_file( 452 ${VTK_BINARY_DIR}/VTKConfigVersion.cmake 453 VERSION ${_VTK_VERSION_MAJOR}.${_VTK_VERSION_MINOR}.${_VTK_VERSION_PATCH} 454 COMPATIBILITY SameMajorVersion 455 ) 456 457if (NOT VTK_INSTALL_NO_DEVELOPMENT) 458 install(FILES ${VTK_BINARY_DIR}/CMakeFiles/VTKConfig.cmake 459 ${VTK_BINARY_DIR}/VTKConfigVersion.cmake 460 CMake/exportheader.cmake.in 461 CMake/GenerateExportHeader.cmake 462 CMake/pythonmodules.h.in 463 CMake/UseVTK.cmake 464 CMake/FindTCL.cmake 465 CMake/TopologicalSort.cmake 466 CMake/vtkTclTkMacros.cmake 467 CMake/vtk-forward.c.in 468 CMake/vtkGroups.cmake 469 CMake/vtkForwardingExecutable.cmake 470 CMake/vtkJavaWrapping.cmake 471 CMake/vtkMakeInstantiator.cmake 472 CMake/vtkMakeInstantiator.cxx.in 473 CMake/vtkMakeInstantiator.h.in 474 CMake/vtkModuleAPI.cmake 475 CMake/vtkModuleHeaders.cmake.in 476 CMake/vtkModuleInfo.cmake.in 477 CMake/vtkModuleMacros.cmake 478 CMake/vtkModuleMacrosPython.cmake 479 CMake/vtkMPI.cmake 480 CMake/vtkExternalModuleMacros.cmake 481 CMake/vtkObjectFactory.cxx.in 482 CMake/vtkObjectFactory.h.in 483 CMake/vtkPythonPackages.cmake 484 CMake/vtkPythonWrapping.cmake 485 CMake/vtkTclWrapping.cmake 486 CMake/vtkThirdParty.cmake 487 CMake/vtkWrapHierarchy.cmake 488 CMake/vtkWrapJava.cmake 489 CMake/vtkWrapperInit.data.in 490 CMake/vtkWrapping.cmake 491 CMake/vtkWrapPython.cmake 492 CMake/vtkWrapPythonSIP.cmake 493 CMake/vtkWrapPython.sip.in 494 CMake/vtkWrapTcl.cmake 495 496 DESTINATION ${VTK_INSTALL_PACKAGE_DIR}) 497 get_property(VTK_TARGETS GLOBAL PROPERTY VTK_TARGETS) 498 if(VTK_TARGETS) 499 install(EXPORT ${VTK_INSTALL_EXPORT_NAME} DESTINATION ${VTK_INSTALL_PACKAGE_DIR}) 500 else() 501 set(CMAKE_CONFIGURABLE_FILE_CONTENT "# No targets!") 502 configure_file(${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in 503 ${VTK_BINARY_DIR}/CMakeFiles/VTKTargets.cmake @ONLY) 504 install(FILES ${VTK_BINARY_DIR}/CMakeFiles/VTKTargets.cmake 505 DESTINATION ${VTK_INSTALL_PACKAGE_DIR}) 506 endif() 507endif() 508