# How to download ancillary files during build with wget from Google Drive

**URL:** https://discourse.cmake.org/t/how-to-download-ancillary-files-during-build-with-wget-from-google-drive/652
**Category:** Code
**Created:** [February 18, 2020, 4:02pm UTC](https://discourse.cmake.org/t/how-to-download-ancillary-files-during-build-with-wget-from-google-drive/652 "2020-02-18T16:02:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![heather999](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/f4b2a3/32.png) [@heather999](https://discourse.cmake.org/u/heather999)
#### Post date: [February 18, 2020, 4:02pm UTC](https://discourse.cmake.org/t/how-to-download-ancillary-files-during-build-with-wget-from-google-drive/652/1 "2020-02-18T16:02:29Z")

</div>

Hi,  
I’m rather new to cmake and am trying to add a step to an existing cmake project to download 2 ancillary files available on Google Drive using wget. The format for the download command line is a little complicated, but this works:  
`wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id= **FILEID**' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id= **FILEID**" -O **FILENAME** && rm -rf /tmp/cookies.txt`

Given that I don’t think I can use file(DOWNLOAD…), which I gather would use a simple curl call.  
I’ve also started to look at ExternalProject\_Add where I might be able to create a custom command.  
I have tried adding wget module, but so far I cannot get my build to call it:

```
find_package(Wget)

function(WGET FILEID FILENAME)
    CMAKE_PARSE_ARGUMENTS(WGETARG "" "FILEID;FILENAME" "" ${ARGN})

    set(_fileid "${WGETARG_FILEID}")
    set(_filename "${WGETARG_FILENAME}")

    add_custom_command(OUTPUT ${_filename} 
                     COMMAND ${WGET_EXECUTABLE} --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=${_fileid}' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/1\n/p')&id=${_fileid}" -O ${_filename} && rm -rf /tmp/cookies.txt
                                           
                     )

endfunction(WGET)

```

* * *

This seems like I’m making this too complicated - anyone out there with some experience with using wget to download some files during a cmake build - preferably set up such that it doesn’t automatically redownload the files if they are already available?

Thanks,  
Heather

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 18, 2020, 4:31pm UTC](https://discourse.cmake.org/t/how-to-download-ancillary-files-during-build-with-wget-from-google-drive/652/2 "2020-02-18T16:31:37Z")

</div>

If you’re going to use a `$()` subshell anyways, can you put it into a shell script and call that from CMake?

---

<div class="post-metadata">

### Author: ![penguin359](https://discourse.cmake.org/user_avatar/discourse.cmake.org/penguin359/32/982_2.png) [@penguin359](https://discourse.cmake.org/u/penguin359)
#### Post date: [November 30, 2020, 4:51am UTC](https://discourse.cmake.org/t/how-to-download-ancillary-files-during-build-with-wget-from-google-drive/652/3 "2020-11-30T04:51:40Z")

</div>

Rather than trying to call the wget command directly, you might be better off using the ExternalData module for CMake and have it do the downloading for you.

[https://cmake.org/cmake/help/latest/module/ExternalData.html](https://cmake.org/cmake/help/latest/module/ExternalData.html)

Just point it at the public URL for your Google Drive file.
