2

I have a CMakeLists.txt, which has a file(download xxx yy) command. There is also a custom_target cpx, which needs this downloaded file. But when the cpx target is invoked, the xxx file is not yet downloaded.

So my question is, when will the download be executed in CMake, and how can I make my custom target depend on the file(download) instruction?

squareskittles
  • 11,997
  • 7
  • 31
  • 48
ddwolf
  • 65
  • 1
  • 10

1 Answers1

2

The file(DOWNLOAD ...) instruction executes at the configuration stage when the CMake file is processed, before the cpx target is even generated. So, your file will already be downloaded and available to use when you run the cpx custom target.

Note the capitalization for the DOWNLOAD option in the file() command; these options are case-sensitive.

squareskittles
  • 11,997
  • 7
  • 31
  • 48
  • it turns out my fault, I haven't pass a condition variable to cmake, which caused the download not to be triggered. Thanks any way, your answer is right. – ddwolf Mar 20 '20 at 13:41