Commit db504d1e authored by David E. DeMarle's avatar David E. DeMarle

Allow projects to have modules that live outside of VTK.

This change lets projects like ParaView, that use VTK as a
submodule, reuse VTK's CMake code for their own
modules which are maintained outside of VTK's repository.

To specify additional directories to search in, call either of
the two new macros in vtkModuleAPI to build up the search path
before adding VTK as a cmake subdirectory.
For example:
include (vtkModuleAPI)
vtk_module_src_glob_path_add(
  "${ParaView_SOURCE_DIR}/ParaViewCore/modular"
  "${ParaView_BINARY_DIR}"
)
vtk_module_src_path_add(
  "${ParaView_SOURCE_DIR/MyModule"
  "${ParaView_BINARY_DIR/MyModule"
)
add_subdirectory(VTK)

Change-Id: Ic738ad289e330a20215c7a2e644ce52cf1156413
parent 922f2ec6
......@@ -119,3 +119,13 @@ macro(vtk_module_config ns)
endforeach()
unset(_${ns}_AUTOINIT)
endmacro()
# Call to add two level directory tree to search for modules under
macro(vtk_module_src_glob_path_add src bld)
list(APPEND vtk_module_src_glob_path "${src},${bld}")
endmacro()
# Call to add a single directory to the module search path
macro(vtk_module_src_path_add src bld)
list(APPEND vtk_module_src_path "${src},${bld}")
endmacro()
......@@ -455,33 +455,60 @@ macro(vtk_module_third_party _pkg)
endif()
endmacro()
macro(vtk_module_glob src bld) # [test-langs]
set(VTK_MODULES_ALL)
file(GLOB meta RELATIVE "${src}" "${src}/*/*/module.cmake")
foreach(f ${meta})
unset(vtk-module)
include(${src}/${f})
if(DEFINED vtk-module)
list(APPEND VTK_MODULES_ALL ${vtk-module})
get_filename_component(${vtk-module}_BASE ${f} PATH)
set(${vtk-module}_SOURCE_DIR ${src}/${${vtk-module}_BASE})
set(${vtk-module}_BINARY_DIR ${bld}/${${vtk-module}_BASE})
foreach(_lang ${ARGN})
if(EXISTS ${${vtk-module}_SOURCE_DIR}/Testing/${_lang}/CMakeLists.txt)
vtk_add_test_module(${_lang})
endif()
endforeach()
if(VTK_MODULE_${vtk-module}_IMPLEMENTS)
foreach(dep IN LISTS VTK_MODULE_${vtk-module}_IMPLEMENTS)
set(${dep}_IMPLEMENTED 1)
endforeach()
# called internally to add one module to the list of available modules
macro(vtk_add_module src f bld)
unset(vtk-module)
include(${src}/${f} OPTIONAL)
if(DEFINED vtk-module)
list(APPEND VTK_MODULES_ALL ${vtk-module})
get_filename_component(${vtk-module}_BASE ${f} PATH)
set(${vtk-module}_SOURCE_DIR ${src}/${${vtk-module}_BASE})
set(${vtk-module}_BINARY_DIR ${bld}/${${vtk-module}_BASE})
foreach(_lang ${ARGN})
if(EXISTS ${${vtk-module}_SOURCE_DIR}/Testing/${_lang}/CMakeLists.txt)
vtk_add_test_module(${_lang})
endif()
endforeach()
if(VTK_MODULE_${vtk-module}_IMPLEMENTS)
foreach(dep IN LISTS VTK_MODULE_${vtk-module}_IMPLEMENTS)
set(${dep}_IMPLEMENTED 1)
endforeach()
endif()
endforeach()
endif()
unset(vtk-module)
unset(vtk-module-test)
endmacro()
# called internally to add all the modules undeneath a particular directory to the list of modules
macro(vtk_module_glob src bld) # [test-langs]
file(GLOB meta RELATIVE "${src}" "${src}/*/*/module.cmake")
foreach(f ${meta})
vtk_add_module(${src} ${f} ${bld})
endforeach()
endmacro()
# called to search for all modules under the
# vtk_module_src_glob_path and vtk_module_src_path paths to the list
macro(vtk_module_search) # [test-langs]
set(VTK_MODULES_ALL)
#go through all the glob dirs, and make modules of any ./*/*/module.cmakes found under them
foreach(pair ${vtk_module_src_glob_path})
string(REGEX MATCH "^([^,]*),([^,]*)$" m "${pair}")
set(src "${CMAKE_MATCH_1}")
set(bld "${CMAKE_MATCH_2}")
vtk_module_glob("${src}" "${bld}")
endforeach()
#go through all the direct dirs, and make modules of any ./module.cmakes found under them
foreach(pair ${vtk_module_src_path})
string(REGEX MATCH "^([^,]*),([^,]*)$" m "${pair}")
set(src "${CMAKE_MATCH_1}")
set(bld "${CMAKE_MATCH_2}")
vtk_add_module("${src}" module.cmake "${bld}")
endforeach()
endmacro()
macro(vtk_add_test_module _lang)
set(_test_module_name ${vtk-module-test}-${_lang})
......
......@@ -18,7 +18,9 @@ endif()
# Load the module DAG.
# Assess modules, and tests in the repository.
vtk_module_glob("${VTK_SOURCE_DIR}" "${VTK_BINARY_DIR}" ${_test_languages})
#vtk_module_glob("${VTK_SOURCE_DIR}" "${VTK_BINARY_DIR}" ${_test_languages})
vtk_module_src_glob_path_add("${VTK_SOURCE_DIR}" "${VTK_BINARY_DIR}")
vtk_module_search(${_test_languages})
# Now include the module group logic.
include(vtkGroups)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment