ExternalProject: Match filenames in URLs with query strings and anchors

While at it, refactor logic to consolidate the filename extraction
and verification into a single match.

Inspired-by: Ruslan Baratov <ruslan_baratov@yahoo.com>
This commit is contained in:
Brad King 2016-07-05 14:52:00 -04:00
parent 909048e534
commit 57c337e2ef
1 changed files with 5 additions and 7 deletions

View File

@ -1871,15 +1871,13 @@ function(_ep_add_download_command name)
if("${url}" MATCHES "^[a-z]+://") if("${url}" MATCHES "^[a-z]+://")
# TODO: Should download and extraction be different steps? # TODO: Should download and extraction be different steps?
if("x${fname}" STREQUAL "x") if("x${fname}" STREQUAL "x")
string(REGEX MATCH "[^/\\?]*$" fname "${url}") set(fname "${url}")
endif() endif()
if(NOT "${fname}" MATCHES "(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$") if("${fname}" MATCHES [[([^/\?#]+(\.|=)(7z|tar|tar\.bz2|tar\.gz|tar\.xz|tbz2|tgz|txz|zip))([/?#].*)?$]])
string(REGEX MATCH "([^/\\?]+(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip))/.*$" match_result "${url}")
set(fname "${CMAKE_MATCH_1}") set(fname "${CMAKE_MATCH_1}")
endif() elseif(no_extract)
if (no_extract) get_filename_component(fname "${fname}" NAME)
get_filename_component(fname "${url}" NAME) else()
elseif(NOT "${fname}" MATCHES "(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
message(FATAL_ERROR "Could not extract tarball filename from url:\n ${url}") message(FATAL_ERROR "Could not extract tarball filename from url:\n ${url}")
endif() endif()
string(REPLACE ";" "-" fname "${fname}") string(REPLACE ";" "-" fname "${fname}")