CMake/Tests/CMakeTests/FileDownloadTest.cmake.in
David Cole f67139ae6f Improve FILE(DOWNLOAD) and ExternalProject.
Improve FILE(DOWNLOAD ...):

- Add percent complete progress output to the FILE DOWNLOAD
  command. This progress output is off by default to
  preserve existing behavior. To turn it on, pass
  SHOW_PROGRESS as an argument.

- Add EXPECTED_MD5 argument. Verify that the downloaded
  file has the expected md5 sum after download is complete.

- Add documentation for SHOW_PROGRESS and EXPECTED_MD5.

  When the destination file exists already and has the
  expected md5 sum, then do not bother re-downloading
  the file. ("Short circuit" return.)

  Also, add a test that checks for the status output
  indicating that the short circuit behavior is actually
  occurring. Use a binary file for the test so that the
  md5 sum is guaranteed to be the same on all platforms
  regardless of "shifting text file line ending" issues.

Improve ExternalProject:

- Add argument URL_MD5.

- Add verify step that compares md5 sum of .tar.gz file
  before extracting it.

- Add md5 check to download step, too, to prevent
  unnecessary downloads.

- Emit a warning message when a file is not verified.
  Indicate that the file may be corrupt or that no
  checksum was specified.
2010-05-27 12:21:56 -04:00

42 lines
829 B
CMake

set(url "file://@CMAKE_CURRENT_SOURCE_DIR@/FileDownloadInput.png")
set(dir "@CMAKE_CURRENT_BINARY_DIR@/downloads")
message(STATUS "FileDownload:1")
file(DOWNLOAD
${url}
${dir}/file1.png
TIMEOUT 2
)
message(STATUS "FileDownload:2")
file(DOWNLOAD
${url}
${dir}/file2.png
TIMEOUT 2
SHOW_PROGRESS
)
# Two calls in a row, exactly the same arguments.
# Since downloaded file should exist already for 2nd call,
# the 2nd call will short-circuit and return early...
#
if(EXISTS ${dir}/file3.png)
file(REMOVE ${dir}/file3.png)
endif()
message(STATUS "FileDownload:3")
file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT 2
EXPECTED_MD5 d16778650db435bda3a8c3435c3ff5d1
)
message(STATUS "FileDownload:4")
file(DOWNLOAD
${url}
${dir}/file3.png
TIMEOUT 2
EXPECTED_MD5 d16778650db435bda3a8c3435c3ff5d1
)