0

I have a custom target'download_files' that is not part of the build, so users can call it manually. Now I would like to add another custom target that performs the custom target 'download_files' and then still build the all target. Is that possible in cmake? This is what I tried:

add_custom_target(download_files)
add_custom_target(download_and_build DEPENDS download_files all)

I do this because I do not always want to download the files, but it might still be convenient to have a target that does both in one go.

It seems that 'all' is not really a target, although CMake configure and generate goes well.

ninja: error: '../all', needed by 'CMakeFiles/download_and_build ', missing and no known rule to make it

Marnix
  • 6,384
  • 4
  • 43
  • 78
  • 1
    Have you read through the answers in this [post](https://stackoverflow.com/questions/30532448/what-is-the-name-of-cmakes-default-build-target)? – Kevin Jul 23 '19 at 13:54
  • I did not see that, thanks. But, the answers date from 2015, so it might be that things have changed in cmake nowadays. – Marnix Jul 23 '19 at 14:07
  • If I undersand correctly, you want `download_and_build` to be part of the build when building everything? – Guillaume Racicot Jul 23 '19 at 14:14
  • No, I want download_and_build to be a separate target that downloads and then builds all. download_files will just download. build all will just build without downloading. – Marnix Jul 23 '19 at 14:17
  • @Marnix I don't think cmake made for this. You'd need to make the `ALL` target depend on `dowload_files`, only when building `download_and_build`. It may be possible, but I think there is much better solution than this. – Guillaume Racicot Jul 23 '19 at 14:26
  • 2
    The question looks like a **duplicate** for the [one](https://stackoverflow.com/questions/30532448/what-is-the-name-of-cmakes-default-build-target) suggested by @squareskittles. Requirement to have `download_files` target to be additionally dependent from `download_files` is **another** (unrelated) **problem**, and it could be easily resolved by normal CMake means. If you want to ask again about the problem stated in the existed question, then just add bounty to it. – Tsyvarev Jul 23 '19 at 14:38
  • @Tsyvarev Yes it is a duplicate of that post, but that was back 2015, so I though let's ask again and see if people now know new things. The easiest way is probably to turn it around and make this one the default build and make another target `just_build`, but I don't want my default processes to change. If people are building, I expect them to do a `just_build` via `all` and not also downloading the files. – Marnix Jul 24 '19 at 08:48
  • 1
    So I have marked the question as a duplicate. Note, that "duplicate" doesn't mean you question will be removed (neither now, nor via roomba). So comments are still enabled, and voting is enabled too. The only thing which is disabled is answering your question: If "people now know new things", then the **answer** should be added to the **original question**. This is just how Stack Overflow works. – Tsyvarev Jul 24 '19 at 09:55

0 Answers0