ExternalProject: add support for just downloading a file

Some projects only ship self-extracting installers rather than
compressed archives. Add a flag so that these files may be used in
ExternalProject.
This commit is contained in:
Ben Boeckel 2016-03-29 10:25:01 -04:00 committed by Brad King
parent 90f24f016e
commit 1ba9b53547
2 changed files with 32 additions and 6 deletions

View File

@ -0,0 +1,6 @@
external-project-no-extract
---------------------------
* The :module:`ExternalProject` module leared the ``DOWNLOAD_NO_EXTRACT 1``
argument to skip extracting the file that is downloaded (e.g., for
self-extracting shell installers or ``.msi`` files).

View File

@ -77,6 +77,9 @@ Create custom targets to build projects in external trees
Path to a certificate authority file Path to a certificate authority file
``TIMEOUT <seconds>`` ``TIMEOUT <seconds>``
Time allowed for file download operations Time allowed for file download operations
``DOWNLOAD_NO_EXTRACT 1``
Just download the file and do not extract it; the full path to the
downloaded file is available as ``<DOWNLOADED_FILE>``.
Update/Patch step options are: Update/Patch step options are:
@ -1107,7 +1110,7 @@ macro(_ep_replace_location_tags target_name)
set(vars ${ARGN}) set(vars ${ARGN})
foreach(var ${vars}) foreach(var ${vars})
if(${var}) if(${var})
foreach(dir SOURCE_DIR BINARY_DIR INSTALL_DIR TMP_DIR) foreach(dir SOURCE_DIR BINARY_DIR INSTALL_DIR TMP_DIR DOWNLOADED_FILE)
get_property(val TARGET ${target_name} PROPERTY _EP_${dir}) get_property(val TARGET ${target_name} PROPERTY _EP_${dir})
string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}") string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}")
endforeach() endforeach()
@ -1875,6 +1878,7 @@ function(_ep_add_download_command name)
set(cmd ${CMAKE_COMMAND} -E remove_directory ${source_dir} set(cmd ${CMAKE_COMMAND} -E remove_directory ${source_dir}
COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir}) COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir})
else() else()
get_property(no_extract TARGET "${name}" PROPERTY _EP_DOWNLOAD_NO_EXTRACT SET)
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")
@ -1884,7 +1888,9 @@ function(_ep_add_download_command name)
string(REGEX MATCH "([^/\\?]+(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip))/.*$" match_result "${url}") 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() endif()
if(NOT "${fname}" MATCHES "(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$") if (no_extract)
get_filename_component(fname "${url}" NAME)
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}")
@ -1898,16 +1904,30 @@ function(_ep_add_download_command name)
set(cmd ${CMAKE_COMMAND} -P "${download_script}" set(cmd ${CMAKE_COMMAND} -P "${download_script}"
COMMAND) COMMAND)
set(retries 3) set(retries 3)
set(comment "Performing download step (download, verify and extract) for '${name}'") if (no_extract)
set(steps "download and verify")
else ()
set(steps "download, verify and extract")
endif ()
set(comment "Performing download step (${steps}) for '${name}'")
else() else()
set(file "${url}") set(file "${url}")
set(comment "Performing download step (verify and extract) for '${name}'") if (no_extract)
set(steps "verify")
else ()
set(steps "verify and extract")
endif ()
set(comment "Performing download step (${steps}) for '${name}'")
endif() endif()
_ep_write_verifyfile_script("${stamp_dir}/verify-${name}.cmake" "${file}" "${hash}" "${retries}" "${download_script}") _ep_write_verifyfile_script("${stamp_dir}/verify-${name}.cmake" "${file}" "${hash}" "${retries}" "${download_script}")
list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/verify-${name}.cmake list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/verify-${name}.cmake
COMMAND) COMMAND)
_ep_write_extractfile_script("${stamp_dir}/extract-${name}.cmake" "${name}" "${file}" "${source_dir}") if (NOT no_extract)
list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/extract-${name}.cmake) _ep_write_extractfile_script("${stamp_dir}/extract-${name}.cmake" "${name}" "${file}" "${source_dir}")
list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/extract-${name}.cmake)
else ()
set_property(TARGET ${name} PROPERTY _EP_DOWNLOADED_FILE ${file})
endif ()
endif() endif()
else() else()
_ep_is_dir_empty("${source_dir}" empty) _ep_is_dir_empty("${source_dir}" empty)