How to Upload/Download files at build time

I have to download/upload some files at build time, not a configure time. So, i am using a custom target, but how to specify a command for downloading/uploading data at build time (at configure time i would use file() command)?
Thanks in advance for any help

You could define your build command as something like:

${CMAKE_COMMAND} -P somefile.cmake

The somefile.cmake file is just a CMake script, so you could use file() to do the upload/download.

1 Like

I had the same question. What transfer types does CMake support? I haven’t found the documentation. Does CMake support TFTP?

The problem is that I need the build time information (i.e. Configuration used) for downloading the right file

CMake uses libcurl underneath, so I guess it should work with TFTP just fine.

Just pass whatever you need as parameters to the invoked script like that:


Yes, i was thinking of doing it, i was hoping in a cleaner way

I’m using CMake 3.21, add_custom_command() can accept generator expressions.
I currently use something like: $<TARGET_FILE:target_name>

$<TARGET_FILE:target_name> expands to the full file path of the file to deploy.