summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2013-01-24 19:09:39 (GMT)
committerBrad King <brad.king@kitware.com>2013-01-30 15:05:07 (GMT)
commitaa8b2288d320335d28f3777e1bc86ed3df231a09 (patch)
tree26f84b98b06626766e8921638933c297d0002847
parent9e518a8169bae33c8a971c146e29b5af20114648 (diff)
downloadCMake-aa8b2288d320335d28f3777e1bc86ed3df231a09.zip
CMake-aa8b2288d320335d28f3777e1bc86ed3df231a09.tar.gz
CMake-aa8b2288d320335d28f3777e1bc86ed3df231a09.tar.bz2
ExternalData: Generalize hash algo/ext handling
Use private global variables _ExternalData_REGEX_(ALGO|EXT) to match the possible hash algorithm names and extensions in regular expressions. Use "file(<algo>)" instead of "cmake -E md5sum" to compute hashes without a child process and to support more hash algorithms.
-rw-r--r--Modules/ExternalData.cmake20
1 files changed, 9 insertions, 11 deletions
diff --git a/Modules/ExternalData.cmake b/Modules/ExternalData.cmake
index 43ff517..fef8367 100644
--- a/Modules/ExternalData.cmake
+++ b/Modules/ExternalData.cmake
@@ -261,18 +261,16 @@ endfunction()
#-----------------------------------------------------------------------------
# Private helper interface
+set(_ExternalData_REGEX_ALGO "MD5")
+set(_ExternalData_REGEX_EXT "md5")
set(_ExternalData_SELF "${CMAKE_CURRENT_LIST_FILE}")
get_filename_component(_ExternalData_SELF_DIR "${_ExternalData_SELF}" PATH)
function(_ExternalData_compute_hash var_hash algo file)
- if("${algo}" STREQUAL "MD5")
- # TODO: Errors
- execute_process(COMMAND "${CMAKE_COMMAND}" -E md5sum "${file}"
- OUTPUT_VARIABLE output)
- string(SUBSTRING "${output}" 0 32 hash)
+ if("${algo}" MATCHES "^${_ExternalData_REGEX_ALGO}$")
+ file("${algo}" "${file}" hash)
set("${var_hash}" "${hash}" PARENT_SCOPE)
else()
- # TODO: Other hashes.
message(FATAL_ERROR "Hash algorithm ${algo} unimplemented.")
endif()
endfunction()
@@ -295,7 +293,7 @@ function(_ExternalData_atomic_write file content)
endfunction()
function(_ExternalData_link_content name var_ext)
- if("${ExternalData_LINK_CONTENT}" MATCHES "^(MD5)$")
+ if("${ExternalData_LINK_CONTENT}" MATCHES "^(${_ExternalData_REGEX_ALGO})$")
set(algo "${ExternalData_LINK_CONTENT}")
else()
message(FATAL_ERROR
@@ -305,7 +303,7 @@ function(_ExternalData_link_content name var_ext)
_ExternalData_compute_hash(hash "${algo}" "${name}")
get_filename_component(dir "${name}" PATH)
set(staged "${dir}/.ExternalData_${algo}_${hash}")
- set(ext ".md5")
+ string(TOLOWER ".${algo}" ext)
_ExternalData_atomic_write("${name}${ext}" "${hash}\n")
file(RENAME "${name}" "${staged}")
set("${var_ext}" "${ext}" PARENT_SCOPE)
@@ -533,7 +531,7 @@ endmacro()
function(_ExternalData_arg_find_files pattern regex)
file(GLOB globbed RELATIVE "${top_src}" "${top_src}/${pattern}*")
foreach(entry IN LISTS globbed)
- if("x${entry}" MATCHES "^x(.*)(\\.md5)$")
+ if("x${entry}" MATCHES "^x(.*)(\\.(${_ExternalData_REGEX_EXT}))$")
set(relname "${CMAKE_MATCH_1}")
set(alg "${CMAKE_MATCH_2}")
else()
@@ -716,8 +714,8 @@ if("${ExternalData_ACTION}" STREQUAL "fetch")
file(READ "${name}${ext}" hash)
string(STRIP "${hash}" hash)
- if("${ext}" STREQUAL ".md5")
- set(algo "MD5")
+ if("${ext}" MATCHES "^\\.(${_ExternalData_REGEX_EXT})$")
+ string(TOUPPER "${CMAKE_MATCH_1}" algo)
else()
message(FATAL_ERROR "Unknown hash algorithm extension \"${ext}\"")
endif()