I'm trying to have cmake download some files. Is it possible to do this once, when the "Generate" button is pressed? I can only set it up to run each time the configure button is pressed or each time the project is built.
CMakeLists are processed at configure time, so you can't have it do things at generate time. You could, however, set up a cache variable and use it as a flag to determine if the download should happen or not. Something like:
if(NOT DOWNLOAD_HAPPENED)
execute_process( ... do the downloading stuff ... )
set(DOWNLOAD_HAPPENED TRUE CACHE BOOL "Has the download happened?" FORCE)
endif()
This will execute the download on first configure and never again (unless the user manually resets the DOWNLOAD_HAPPENED) variable. However, if you really need the download to happen at the last configure, you're out of luck, AFAIK.
Something like this should help:
add_custom_command(
OUTPUT myfile.txt
COMMAND wget http://myurl.com/myfile.txt
)
EDIT 1
It's require to make it as a dependency of the main command:
add_dependencies(<myprogram> wget)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With