I have generally the same question as in Can CMake always force the compilation/build of a specific file?
I have a C++ file using
__DATE__
to display the build date of my app. But if this file is not modified, it will not be rebuilt and the date will not be updated.Can CMake always rebuild that specific file?
... except I want something slightly different:
In the CMake project I have (for C, transpiles to Makefile which I use), sometimes there are no actual changes to the code when I run make
, which is detected nicely, in the sense that there is no recompilation (or relinking) of the program.
Obviously, in this case, I do not want to update the timestamp, and end up with a new executable, which is otherwise identical to the previous one - apart from the build date.
I have seen in the quoted post, that one simply has to ensure a changed timestamp on the file, to force a recompilation. So, assuming my __DATE__
usage is in use_date.c
, what I'd want, is that the timestamp of use_date.c
is updated (forcing recompilation), only if any other file in the project (say, main.c
) has been changed, so it forces project recompilation and linking (obviously, this should also work if I just change use_date.c
manually, and no other file).
So, assuming my project just generates an executable (no libraries):
add_executable(my_project use_date.c other_file.c main.c)
... is it possible to add a CMake step, that updates the timestamp of use_date.c
(and thus causes its recompilation), only if otherwise the project is getting recompiled and relinked?