[CMake] perpetually executed custom commands and timestamps

Pawel Veselov pawel.veselov at gmail.com
Tue Aug 15 14:14:30 EDT 2017


Hello.

I'm trying something I don't think is unreasonable.

I need to have an automatically generated file, let's say version.h

I have to run a custom command to generate it.

The contents of the file depend on some external forces, the custom command
m
ay or may not change it (but it will always generate it if it is there).

That header is then included in bunch of other files, creating multiple
targets

So, I created a custom command that has declared output of version.h, and
have version.h included as sources for other (multiple) targets. This
worked,
but, of course, if the version.h is already there, the command wouldn't run.

I couldn't find any way to force the command to run, so after reading this
SO post: https://stackoverflow.com/questions/13920072, I added a PHONY
output
to the command, and dependency to the targets. This forced the command to
run every time.

However, when the command runs, but doesn't change the output file, there is
some target that forces the file to be updated (the touch_nocreate). This
causes the targets to both recompile and relink for no reason.

Questions:
1) Can I make a custom command run every time, even if its target is present
(without creating a PHONY target)? I don't want the
2) Can I turn the touching off?

I don't think using TARGET based custom command is right, as it's a
pre-build
target activity, and such is not supported for !VS.

I don't think using an ALL custom target is right, because custom target has
no output files, and target-to-target dependency wouldn't correctly
determine
that I need that .h file in time.

I would love to know what's the point of touch_no_create, really, I can't
imagine a good reason the file is refreshed when it wasn't touched, it seems
that the point would be to "cheat" the dependency resolution that way, which
may have valid use cases, but as a forced default?

Thank you,
  Pawel.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170815/a246fff9/attachment.html>


More information about the CMake mailing list