Directory creation by ninja when using BYPRODUCTS of add_custom_command

Further to issue 25808, I experimented a little more with the pattern…bear with :slight_smile:

@brad.king on cursory reading, the comment you made here is what was being performed in the example cmake configuration as given. I think the detail that needs emphasis is “…If you use a custom command to generate the…”.
As you point out earlier, in the example there is nothing explicitly tying the imported binary. Reading the docs for add_custom_command/BYPRODUCTS this sounds like something that would give that binding to the imported binary. It sounds like one of its purposes is to help the Ninja generator.

So, taking the example and adding the extra line to the custom command: BYPRODUCTS ${importedBinary} the rule link is provided for Ninja (we’ll gloss over the clean step potentially removing this file for the point of this).

Now, here’s the thing. If the steps are followed in the example, when ninja is invoked and finds it needs to recreate the (indirection) symlink, it first creates a directory of the same name. The outcome is the subsequent cmake create_symlink fails.

This is mainly an academic exercise now (as an alternative approach has been taken), but it could be highlighting some underlying issue.

ninja is defined to create the directories for any outputs that do not exist when it starts work on an edge.