Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake run command during generation

Tags:

cmake

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.

like image 841
carpat Avatar asked May 15 '26 02:05

carpat


2 Answers

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.

like image 63
Angew is no longer proud of SO Avatar answered May 17 '26 14:05

Angew is no longer proud of SO


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)
like image 36
dmoreno Avatar answered May 17 '26 15:05

dmoreno