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

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 "$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate ' **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:



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

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


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?


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

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.

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