3

How does one set up an External project to download a link that isn't a .tgz file?

For example Catch provides a release that is a single header distribution. I would like to just download this rather than the git repo or the .tgz release. But I haven't figured out how to tell CMake to do this.

I would like to do something like:

Include(ExternalProject)
ExternalProject_Add(
    catch
    PREFIX ${CMAKE_BINARY_DIR}/catch
    URL https://github.com/philsquared/Catch/releases/download/v1.9.6/catch.hpp ${CMAKE_BINARY_DIR}/catch
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
    LOG_DOWNLOAD ON
)

This fails as URL assumes that url is a compressed tar file. I have tried various variants of the DOWNLOAD_COMMAND without any success either.

Tal
  • 105
  • 9

1 Answers1

7

Use DOWNLOAD_NO_EXTRACT option of ExternalProject_Add:

Just download the file and do not extract it; the full path to the downloaded file is available as <DOWNLOADED_FILE>.

Code example:

ExternalProject_Add(
    catch
    PREFIX ${CMAKE_BINARY_DIR}/catch
    URL https://github.com/philsquared/Catch/releases/download/v1.9.6/catch.hpp
    DOWNLOAD_NO_EXTRACT 1
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
    )

File will be downloaded into <prefix>/src directory.


If use LOG_DOWNLOAD option alongside with DOWNLOAD_NO_EXTRACT, you need CMake 3.9 for work correctly. See these bugreports: https://gitlab.kitware.com/cmake/cmake/issues/16544, https://gitlab.kitware.com/cmake/cmake/issues/17046.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • Thanks. That's just what I was looking for. Also thanks for the tip about LOG_DOWNLOAD. The file was downloading fine. However, CMake was failing after the download until I turned off the LOG_DOWNLOAD. I was even using CMakeLists 3.8.2. So it looks like it might be broken again. – Tal Jul 10 '17 at 00:11
  • 1
    Followup on the CMake issue. This is fixed in CMake 3.9 and it has been back-patched into the 3.8 tree, so if there is another 3.8 release (ie. 3.8.3) it should be fixed there, too. For more info: https://gitlab.kitware.com/cmake/cmake/issues/17046#note_289032 – Tal Jul 12 '17 at 22:21
  • @Tal: Thanks, I have fixed the answer accordingly. – Tsyvarev Jul 12 '17 at 22:54
  • Should be DOWNLOAD_NO_EXTRACT 1 – IlliakaillI Sep 11 '18 at 01:06