Skip to content

vtkModule: Do not generate files in source tree when building module externally

VTK modules can be built in the following scenarios:

  1. Module sources and generated buildsystem are respectively in VTK source and build trees (aka built-in case)
  2. Module sources are external and module generated buildsystem is in VTK build tree (aka built-in case for a VTK remote module)
  3. Module sources and module generated buildsystem are both external
  4. Module sources are in VTK source tree and module generated buildsystem is external

This commit implements logic ensuring files are not generated in VTK source for case (3) and (4).

To help understand the changes, the output for each cases were obtained applying patch [1] to VTK and building:

  • regular VTK
  • SlicerLookingGlass extension
  • SlicerVirtualReality extension

Note that the Slicer extensions externally build the relevant VTK modules (respectively vtkRenderingLookingGlass and vtkRenderingOpenVR) by leveraging https://github.com/KitwareMedical/VTKExternalModule

Output for the the different cases:

(1) Module sources and generated buildsystem are respectively in VTK source and build trees (aka built-in case)

  --------------------------------------
  _vtk_build_module_file .............. : /home/jcfr/Projects/Slicer-Release/VTK/Filters/FlowPaths/vtk.module
  _vtk_build_module_dir ............... : /home/jcfr/Projects/Slicer-Release/VTK/Filters/FlowPaths
  _vtk_build_module_subdir ............ : Filters/FlowPaths
  CMAKE_SOURCE_DIR .................... : /home/jcfr/Projects/Slicer-Release/VTK
  CMAKE_BINARY_DIR .................... : /home/jcfr/Projects/Slicer-Release/VTK-build
  source_dir .......................... : /home/jcfr/Projects/Slicer-Release/VTK/Filters/FlowPaths
  binary_dir .......................... : /home/jcfr/Projects/Slicer-Release/VTK-build/Filters/FlowPaths
  _vtk_build_module_absolute_source_dir : /home/jcfr/Projects/Slicer-Release/VTK/Filters/FlowPaths
  _vtk_build_module_absolute_binary_dir : /home/jcfr/Projects/Slicer-Release/VTK-build/Filters/FlowPaths
  _vtk_build_module_binary_dir ........ : /home/jcfr/Projects/Slicer-Release/VTK-build/Filters/FlowPaths

(2) Module sources are external and module generated buildsystem is in VTK build tree (aka built-in case for a VTK remote module)

  --------------------------------------
  _vtk_build_module_file .............. : /home/jcfr/Projects/Slicer-Release/VTK/Remote/SplineDrivenImageSlicer/vtk.module
  _vtk_build_module_dir ............... : /home/jcfr/Projects/Slicer-Release/VTK/Remote/SplineDrivenImageSlicer
  _vtk_build_module_subdir ............ : Remote/SplineDrivenImageSlicer
  CMAKE_SOURCE_DIR .................... : /home/jcfr/Projects/Slicer-Release/VTK
  CMAKE_BINARY_DIR .................... : /home/jcfr/Projects/Slicer-Release/VTK-build
  source_dir .......................... : /home/jcfr/Projects/Slicer-Release/VTK/Remote/SplineDrivenImageSlicer
  binary_dir .......................... : /home/jcfr/Projects/Slicer-Release/VTK-build/Remote/SplineDrivenImageSlicer
  _vtk_build_module_absolute_source_dir : /home/jcfr/Projects/Slicer-Release/VTK/Remote/SplineDrivenImageSlicer
  _vtk_build_module_absolute_binary_dir : /home/jcfr/Projects/Slicer-Release/VTK-build/Remote/SplineDrivenImageSlicer
  _vtk_build_module_binary_dir ........ : /home/jcfr/Projects/Slicer-Release/VTK-build/Remote/SplineDrivenImageSlicer

(3) Module sources and module generated buildsystem are both external

  --------------------------------------
  _vtk_build_module_file .............. : /home/jcfr/Projects/SlicerLookingGlass-r/vtkRenderingLookingGlass/vtk.module
  _vtk_build_module_dir ............... : /home/jcfr/Projects/SlicerLookingGlass-r/vtkRenderingLookingGlass
  _vtk_build_module_subdir ............ : ../vtkRenderingLookingGlass
  CMAKE_SOURCE_DIR .................... : /home/jcfr/Projects/SlicerVirtualReality-build/VTKExternalModule
  CMAKE_BINARY_DIR .................... : /home/jcfr/Projects/SlicerVirtualReality-build/VTKRenderingOpenVR-build
  source_dir .......................... : /home/jcfr/Projects/SlicerLookingGlass-r/VTKExternalModule/../vtkRenderingLookingGlass
  binary_dir .......................... : /home/jcfr/Projects/SlicerLookingGlass-r/vtkRenderingLookingGlass-build/../vtkRenderingLookingGlass
  _vtk_build_module_absolute_source_dir : /home/jcfr/Projects/SlicerLookingGlass-r/vtkRenderingLookingGlass
  _vtk_build_module_absolute_binary_dir : /home/jcfr/Projects/SlicerLookingGlass-r/vtkRenderingLookingGlass
  _vtk_build_module_binary_dir ........ : /home/jcfr/Projects/SlicerVirtualReality-build/VTKRenderingOpenVR-build-external

(4) Module sources are in VTK source tree and module generated buildsystem is external

  --------------------------------------
  _vtk_build_module_file .............. : /home/jcfr/Projects/Slicer-Release/VTK-build/../VTK/Rendering/OpenVR/vtk.module
  _vtk_build_module_dir ............... : /home/jcfr/Projects/Slicer-Release/VTK-build/../VTK/Rendering/OpenVR
  _vtk_build_module_subdir ............ : ../../Slicer-Release/VTK/Rendering/OpenVR
  CMAKE_SOURCE_DIR .................... : /home/jcfr/Projects/SlicerVirtualReality-build/VTKExternalModule
  CMAKE_BINARY_DIR .................... : /home/jcfr/Projects/SlicerVirtualReality-build/VTKRenderingOpenVR-build
  source_dir .......................... : /home/jcfr/Projects/SlicerVirtualReality-build/VTKExternalModule/../../Slicer-Release/VTK/Rendering/OpenVR
  binary_dir .......................... : /home/jcfr/Projects/SlicerVirtualReality-build/VTKRenderingOpenVR-build/../../Slicer-Release/VTK/Rendering/OpenVR
  _vtk_build_module_absolute_source_dir : /home/jcfr/Projects/Slicer-Release/VTK/Rendering/OpenVR
  _vtk_build_module_absolute_binary_dir : /home/jcfr/Projects/Slicer-Release/VTK/Rendering/OpenVR
  _vtk_build_module_binary_dir ........ : /home/jcfr/Projects/SlicerVirtualReality-build/VTKRenderingOpenVR-build-external

[1] Patch:

diff --git a/CMake/vtkModule.cmake b/CMake/vtkModule.cmake
index 7db01164fd..fd86b6b7d2 100644
--- a/CMake/vtkModule.cmake
+++ b/CMake/vtkModule.cmake
@@ -2538,6 +2538,18 @@ function (vtk_module_build)
       set(_vtk_build_module_binary_dir "${CMAKE_BINARY_DIR}-external")
     endif()

+    message("--------------------------------------")
+    message("_vtk_build_module_file .............. : ${_vtk_build_module_file}")
+    message("_vtk_build_module_dir ............... : ${_vtk_build_module_dir}")
+    message("_vtk_build_module_subdir ............ : ${_vtk_build_module_subdir}")
+    message("CMAKE_SOURCE_DIR .................... : ${CMAKE_SOURCE_DIR}")
+    message("CMAKE_BINARY_DIR .................... : ${CMAKE_BINARY_DIR}")
+    message("source_dir .......................... : ${CMAKE_SOURCE_DIR}/${_vtk_build_module_subdir}")
+    message("binary_dir .......................... : ${CMAKE_BINARY_DIR}/${_vtk_build_module_subdir}")
+    message("_vtk_build_module_absolute_source_dir : ${_vtk_build_module_absolute_source_dir}")
+    message("_vtk_build_module_absolute_binary_dir : ${_vtk_build_module_absolute_binary_dir}")
+    message("_vtk_build_module_binary_dir ........ : ${_vtk_build_module_binary_dir}")
+
     add_subdirectory(
       "${_vtk_build_module_absolute_source_dir}"
       "${_vtk_build_module_binary_dir}")
Edited by Jean-Christophe Fillion-Robin

Merge request reports