Commit d7bf9e9a authored by Brad King's avatar Brad King

Add option VTK_DATA_STORE to specify ExternalData object store

Replace the ExternalData_OBJECT_STORES cache entry with a VTK-specific
name "VTK_DATA_STORE".  In the common use case there is only one store
so make the option a "PATH" cache entry for easy handling in cmake-gui.
In order to allow advanced users to configure multiple stores honor any
ExternalData_OBJECT_STORES that is set but do not add the cache option
by default.

Select a default for VTK_DATA_STORE based on the results of local user
configuration.  First, teach the SetupForDevelopment.sh script to run a
SetupExternalData.sh script that prompts the developer for a default
value.  Second, if no default was selected by developer setup, look for
a VTKExternalData or ExternalData directory as a sibling to the source
tree.  Third, if the previous two attempts failed, fall back to the
environment variable ExternalData_OBJECT_STORES for advanced users.

Change-Id: I964cb99aa204176010f27948a9bd40a00836532f
parent 05fcc851
get_filename_component(_VTKExternalData_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
include(${_VTKExternalData_DIR}/ExternalData.cmake)
if(NOT ExternalData_OBJECT_STORES)
# Use ExternalData_OBJECT_STORES from environment as default.
set(ExternalData_OBJECT_STORES_DEFAULT "")
if(DEFINED "ENV{ExternalData_OBJECT_STORES}")
file(TO_CMAKE_PATH "$ENV{ExternalData_OBJECT_STORES}" ExternalData_OBJECT_STORES_DEFAULT)
if(NOT VTK_DATA_STORE)
# Select a default from the following.
set(VTK_DATA_STORE_DEFAULT "")
if(EXISTS "${CMAKE_SOURCE_DIR}/.ExternalData/config/store")
# Configuration left by developer setup script.
file(STRINGS "${CMAKE_SOURCE_DIR}/.ExternalData/config/store"
VTK_DATA_STORE_DEFAULT LIMIT_COUNT 1 LIMIT_INPUT 1024)
elseif(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/../VTKExternalData")
# Adjacent directory created by user.
get_filename_component(VTK_DATA_STORE_DEFAULT
"${CMAKE_SOURCE_DIR}/../VTKExternalData" ABSOLUTE)
elseif(IS_DIRECTORY "${CMAKE_SOURCE_DIR}/../ExternalData")
# Generic adjacent directory created by user.
get_filename_component(VTK_DATA_STORE_DEFAULT
"${CMAKE_SOURCE_DIR}/../ExternalData" ABSOLUTE)
elseif(DEFINED "ENV{ExternalData_OBJECT_STORES}")
# Generic ExternalData environment variable.
file(TO_CMAKE_PATH "$ENV{ExternalData_OBJECT_STORES}" VTK_DATA_STORE_DEFAULT)
endif()
endif()
set(ExternalData_OBJECT_STORES "${ExternalData_OBJECT_STORES_DEFAULT}" CACHE STRING
"Semicolon-separated list of local directories holding data objects in the layout %(algo)/%(hash).")
mark_as_advanced(ExternalData_OBJECT_STORES)
if(NOT ExternalData_OBJECT_STORES)
set(ExternalData_OBJECT_STORES "${CMAKE_BINARY_DIR}/ExternalData/Objects")
file(MAKE_DIRECTORY "${ExternalData_OBJECT_STORES}")
# Provide users with an option to select a local object store,
# starting with the above-selected default.
set(VTK_DATA_STORE "${VTK_DATA_STORE_DEFAULT}" CACHE PATH
"Local directory holding ExternalData objects in the layout %(algo)/%(hash).")
mark_as_advanced(VTK_DATA_STORE)
# Use a store in the build tree if none is otherwise configured.
if(NOT VTK_DATA_STORE)
if(ExternalData_OBJECT_STORES)
set(VTK_DATA_STORE "")
else()
set(VTK_DATA_STORE "${CMAKE_BINARY_DIR}/ExternalData/Objects")
file(MAKE_DIRECTORY "${VTK_DATA_STORE}")
endif()
endif()
# Tell ExternalData module about selected object stores.
list(APPEND ExternalData_OBJECT_STORES
# Store selected by VTK-specific configuration above.
${VTK_DATA_STORE}
# Local data store populated by the VTK pre-commit hook
"${CMAKE_SOURCE_DIR}/.ExternalData"
)
......
#!/usr/bin/env bash
#=============================================================================
# Copyright 2013 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================
# Path conversion function.
case "$(uname)" in
*CYGWIN*)
native_path() {
cygpath -m "$1"
}
;;
*MINGW*)
native_path() {
cmd //c echo "$1" | sed 's/^"//;s/"$//'
}
;;
*)
native_path() {
echo "$1"
}
;;
esac
say_store() {
if test -f "$config_store"; then
echo 'A default for VTK_DATA_STORE is configured as:' &&
echo &&
sed 's/^/ /' < "$config_store" &&
echo
else
echo 'No default for VTK_DATA_STORE is configured.' &&
echo
fi
}
ask_store() {
ans='?'
while test "$ans" = '?'; do
read -ep 'From the options
<empty> = No change
n,no = No default
h,home = Use '"$store_home"'
s,sibling = Use '"$store_sibling"'
<full-path> = Use specified <full-path>
select a default for VTK_DATA_STORE [n/h/s]: ' ans &&
case "$ans" in
n|N|no) ans='no' ;;
h|H|home) ans="$store_home" ;;
s|S|sibling) ans="$store_sibling" ;;
/*) ;;
[A-Za-z]:[/\\]*) ;;
'') ans='' ;;
*) echo; echo "Invalid response '$ans'!"; echo; ans='?' ;;
esac
done
eval "$1='$ans'"
}
cd "${BASH_SOURCE%/*}/../.." &&
config_store='.ExternalData/config/store' &&
store_home="$(native_path "${HOME-$USERPROFILE}/.ExternalData")" &&
store_sibling="$(native_path "${PWD%/*}/VTKExternalData")" &&
echo 'VTK may download data objects into a local "store" using
the CMake ExternalData module. The store is content-addressed
and can be shared across multiple projects and build trees.
VTK build trees have a VTK_DATA_STORE CMake cache entry to set
their store location. A default for this value to be used in
build trees created with this source tree may now be chosen.
' &&
say_store &&
ask_store ans &&
case "$ans" in
'') ;;
no) rm -f "$config_store" ;;
*) mkdir -p "${config_store%/*}" && echo "$ans" > "$config_store" ;;
esac &&
say_store
......@@ -6,6 +6,7 @@ Utilities/GitSetup/setup-hooks && echo &&
Utilities/Scripts/SetupGitAliases.sh && echo &&
(Utilities/GitSetup/setup-gerrit ||
echo 'Failed to setup Gerrit. Run this again to retry.') && echo &&
Utilities/Scripts/SetupExternalData.sh && echo &&
Utilities/GitSetup/tips
# Rebase master by default
......
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