Is install() of a target with EXCLUDE_FROM_ALL == TRUE really undefined?

In the documentation of the install command we can read:

Installing a target with the EXCLUDE_FROM_ALL target property set to TRUE has undefined behavior.

I wonder whether this is really the case. Installation seems to be skipped for such targets.

Assuming there is undefined behavior which we must avoid:
For those targets I could skip install or call install with the EXCLUDE_FROM_ALL argument.

Now, the EXCLUDE_FROM_ALL target property however allows generator expressions.
The EXCLUDE_FROM_ALL argument of install does not.
For targets that have EXCLUDE_FROM_ALL set to some generator expression I cannot just skip install nor can I use install's EXCLUDE_FROM_ALL option.

Can someone clarify whether the documentation is correct - and if yes, how to handle the latter case of targets with EXCLUDE_FROM_ALL set to a generator expression?

The main issue is that the install script has no idea how much of the build has completed. The install target just depends on all, so the installation of EXCLUDE_FROM_ALL targets doesn’t guarantee they’ll actually be available. The documentation is basically just a license for CMake to skip the if (EXISTS) check for complicated things (probably historical).

As for install(EXCLUDE_FROM_ALL <genex>), the main question is in what context is the genex evaluated? It’s easy for install(TARGETS) (it’d be evaluated once per target), but install(FILES) won’t have any implicit target context. If such questions have reasonable answers, I think it’d just be a feature request.

what about if the install command is an EXCLUDE_FROM_ALL target, but the install cmd had the OPTIONAL flag? That should be well defined, no?

That’s fine as OPTIONAL doesn’t care if the source file exists or not.

I see. Thanks for your answer!

For the install(EXCLUDE_FROM_ALL <genex>) case I was indeed thinking of install(TARGETS), not install(FILES).