carpat
carpat

Reputation: 871

CMake run command during generation

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.

Upvotes: 3

Views: 7197

Answers (2)

dmoreno
dmoreno

Reputation: 706

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)

Upvotes: 3

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.

Upvotes: 8

Related Questions