Commit ef927f02 authored by Bill Lorensen's avatar Bill Lorensen

ENH: Remote module capability

A preliminary implementation of Remote modules. This approach follows
the ITK implementation.

Three remote modules are included for testing
 David Doria's Poissoin Reconstruction, David Gobbi's vtkDICOM and Slicer's vtkAddon.

To configure vtk with these remote modules:
cmake -DvtkAddon:BOOL=ON -DModule_PoissonReconstruction:BOOL=ON -DModule_vtkDICOM:BOOL=ON vtk_source_dir
make
parent 7691a166
......@@ -56,13 +56,15 @@ set(ExternalData_URL_TEMPLATES "" CACHE STRING
"Additional URL templates for the ExternalData CMake script to look for testing data. E.g.
file:///var/bigharddrive/%(algo)/%(hash)")
mark_as_advanced(ExternalData_URL_TEMPLATES)
list(APPEND ExternalData_URL_TEMPLATES
# Data published by MIDAS
"http://midas3.kitware.com/midas/api/rest?method=midas.bitstream.download&checksum=%(hash)&algorithm=%(algo)"
if(NOT VTK_FORBID_DOWNLOADS)
list(APPEND ExternalData_URL_TEMPLATES
# Data published by MIDAS
"http://midas3.kitware.com/midas/api/rest?method=midas.bitstream.download&checksum=%(hash)&algorithm=%(algo)"
# Data published by developers using git-gitlab-push.
"http://www.vtk.org/files/ExternalData/%(algo)/%(hash)"
# Data published by developers using git-gitlab-push.
"http://www.vtk.org/files/ExternalData/%(algo)/%(hash)"
)
endif()
# Tell ExternalData commands to transform raw files to content links.
# TODO: Condition this feature on presence of our pre-commit hook.
......
# Function to fetch remote modules.
# Helper to perform the initial git clone and checkout.
function(_git_clone git_executable git_repository git_tag module_dir)
execute_process(
COMMAND "${git_executable}" clone "${git_repository}" "${module_dir}"
RESULT_VARIABLE error_code
OUTPUT_QUIET
ERROR_VARIABLE git_clone_error
)
if(error_code)
message(FATAL_ERROR "Failed to clone repository: '${git_repository}' Clone error is: '${git_clone_error}'")
Endif()
execute_process(
COMMAND "${git_executable}" checkout ${git_tag}
WORKING_DIRECTORY "${module_dir}"
RESULT_VARIABLE error_code
OUTPUT_QUIET
ERROR_QUIET
)
if(error_code)
message(FATAL_ERROR "Failed to checkout tag: '${git_tag}'")
endif()
execute_process(
COMMAND "${git_executable}" submodule init
WORKING_DIRECTORY "${module_dir}"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR "Failed to init submodules in: '${module_dir}'")
endif()
execute_process(
COMMAND "${git_executable}" submodule update --recursive
WORKING_DIRECTORY "${module_dir}"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR "Failed to update submodules in: '${module_dir}'")
endif()
endfunction()
# Helper to perform a git update. Checks the current Git revision against the
# desired revision and only performs a fetch and checkout if needed.
function(_git_update git_executable git_repository git_tag module_dir)
execute_process(
COMMAND "${git_executable}" rev-parse --verify ${git_tag}
WORKING_DIRECTORY "${module_dir}"
RESULT_VARIABLE error_code
OUTPUT_VARIABLE tag_hash
)
if(error_code)
message(FATAL_ERROR "Failed to get the hash for tag '${module_dir}'")
endif()
execute_process(
COMMAND "${git_executable}" rev-parse --verify HEAD
WORKING_DIRECTORY "${module_dir}"
RESULT_VARIABLE error_code
OUTPUT_VARIABLE head_hash
)
if(error_code)
message(FATAL_ERROR "Failed to get the hash for ${git_repository} HEAD")
endif()
# Is the hash checkout out that we want?
if(NOT (tag_hash STREQUAL head_hash))
execute_process(
COMMAND "${git_executable}" fetch "${git_repository}"
WORKING_DIRECTORY "${module_dir}"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR "Failed to fetch repository '${git_repository}'")
endif()
execute_process(
COMMAND "${git_executable}" checkout ${git_tag}
WORKING_DIRECTORY "${module_dir}"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR "Failed to checkout tag: '${git_tag}'")
endif()
execute_process(
COMMAND "${git_executable}" submodule update --recursive
WORKING_DIRECTORY "${module_dir}"
RESULT_VARIABLE error_code
)
if(error_code)
message(FATAL_ERROR "Failed to update submodules in: '${module_dir}'")
endif()
endif()
endfunction()
# Helper function to fetch a module stored in a Git repository.
# Git fetches are only performed when required.
function(_fetch_with_git git_executable git_repository git_tag module_dir)
if("${git_tag}" STREQUAL "" OR "${git_repository}" STREQUAL "")
message(FATAL_ERROR "Tag or repository for git checkout should not be empty.")
endif()
# If we don't have a clone yet.
if(NOT EXISTS "${module_dir}")
_git_clone("${git_executable}" "${git_repository}" "${git_tag}" "${module_dir}")
message(STATUS " The remote module: ${git_repository} is cloned into the directory ${module_dir}")
else() # We already have a clone, but we need to check that it has the right revision.
_git_update("${git_executable}" "${git_repository}" "${git_tag}" "${module_dir}")
endif()
endfunction()
# Download and turn on a remote module.
#
# The module CMake option is created: Module_${module_name}, which defaults to OFF.
# Once set to ON, the module is downloaded into the Remote module group.
#
# A module name and description are required. The description will show up in
# the CMake user interface.
#
# The following options are currently supported:
# [GIT_REPOSITORY url] # URL of git repo
# [GIT_TAG tag] # Git branch name, commit id or tag
function(vtk_fetch_module _name _description)
option(Module_${_name} "${_description}" OFF)
mark_as_advanced(Module_${_name})
# Fetch_$_remote_module} is deprecated. To maintain backward compatibility:
if(Fetch_${_name})
message(WARNING "Fetch_${_name} is deprecated, please use Module_${_name} to download and enable the remote module.")
set(Module_${_name} ON CACHE FORCE "${_description}")
endif()
if(Module_${_name})
vtk_download_attempt_check(Module_${_name})
include(CMakeParseArguments)
cmake_parse_arguments(_fetch_options "" "GIT_REPOSITORY;GIT_TAG" "" ${ARGN})
find_package(Git)
if(NOT GIT_EXECUTABLE)
message(FATAL_ERROR "error: could not find git for clone of ${_name}")
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" --version
OUTPUT_VARIABLE ov
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE "^git version (.+)$" "\\1" _version "${ov}")
if("${_version}" VERSION_LESS 1.6.6)
message(FATAL_ERROR "Git version 1.6.6 or later is required.")
endif()
_fetch_with_git("${GIT_EXECUTABLE}"
"${_fetch_options_GIT_REPOSITORY}"
"${_fetch_options_GIT_TAG}"
"${VTK_SOURCE_DIR}/Remote/${_name}"
)
endif()
endfunction()
......@@ -44,6 +44,18 @@ set(CMAKE_MODULE_PATH ${VTK_CMAKE_DIR} ${CMAKE_MODULE_PATH})
include(vtkModuleMacros)
include(vtkExternalData)
#-----------------------------------------------------------------------------
# Forbid downloading resources from the network during a build. This helps
# when building on systems without network connectivity to determine which
# resources much be obtained manually and made available to the build.
option(VTK_FORBID_DOWNLOADS "Do not download source code or data from the network" OFF)
mark_as_advanced(VTK_FORBID_DOWNLOADS)
macro(vtk_download_attempt_check _name)
if(VTK_FORBID_DOWNLOADS)
message(SEND_ERROR "Attempted to download ${_name} when VTK_FORBID_DOWNLOADS is ON")
endif()
endmacro()
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug' as none was specified.")
......@@ -254,6 +266,10 @@ if (CMAKE_CROSSCOMPILING AND NOT COMPILE_TOOLS_IMPORTED)
set (COMPILE_TOOLS_IMPORTED TRUE)
endif()
#-----------------------------------------------------------------------------
# Add the Remote Subdirectory
add_subdirectory(Remote)
#-----------------------------------------------------------------------------
# Do we try to use system libraries by default?
option(VTK_USE_SYSTEM_LIBRARIES "Use the system's libraries by default." OFF)
......
*
!*.remote.cmake
!CMakeLists.txt
!README.txt
# Functions to fetch remote modules.
include(vtkModuleRemote)
file(GLOB remotes "*.remote.cmake")
foreach(remote_module ${remotes})
include(${remote_module})
endforeach()
#
# Poisson Reconstruction
#
vtk_fetch_module(PoissonReconstruction
"Poisson Surface reconstruction from unorganized points"
GIT_REPOSITORY https://github.com/lorensen/PoissonReconstruction
# July 5, 2015 - first working as a remote module
GIT_TAG a3fdb529774d48329a2e807e542f2fe589060ccb
)
Remote Modules
==============
This directory is a place-holder for all remote modules distributed
outside VTK's main repository. Remote modules share the same
directory structure as modules in the main repository. They will be
picked up by the configuration system and entered into the build after
they are downloaded into this directory.
Modules can be easily downloaded and accessible to the community by
listing the module in the current directory. For more information on
adding a new module to the list of new modules, see the page that
describes the policy and procedures for adding a new module:
[Adding Remote Modules to VTK](http://www.vtk.org/Wiki/VTK/Remote_Modules)
__NOTE__ that in each `<remote module name>.remote.cmake`, the first
argument of the function vtk_fetch_module() is the name of the remote
module, and it has to be consistent with the module name defined in
the correponding module.cmake.
#
# vtkAddon
#
vtk_fetch_module(vtkAddon
"Slicer additions to vtk"
GIT_REPOSITORY https://github.com/lorensen/vtkAddon
GIT_TAG 0d324d0a7afbd2f7ddd79ae52640fddd15091b34
)
#
# Dicom Classes
#
vtk_fetch_module(vtkDICOM
"Dicom classes and utilities"
GIT_REPOSITORY https://github.com/lorensen/vtk-dicom
# July 9, 2015 - first working as a vtk remote module
GIT_TAG vtkRemote
)
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