Introducing file dependencies

In my project, a source file depends upon a VERSION_Q_FILE, that depends in turn upon the VERSION_FILE. I have tryed to write the rules using add_dependencies command, but I cannot formulate them correctly. Any suggests?

The major question is, when are the files changed or needs to be created?

If your VERSION_FILE is under source control, then you can create VERSION_Q_FILE during CMake’s configure stage (in your CMakeLists.txt).
In that case, you simply add the file to the property CMAKE_CONFIGURE_DEPENDS.
If a file in that property change, then the build system will call CMake again for re-configuration.

Ok, I was too short in my question. Here is a detailed description of project:
a directory src that contains fortran 90 sources, that are included in the revision control by the command
file(GLOB sources src/*.f90)
The VERSION file is a simple one line string that contains project version and is not included in the sources. Before the compilation, a quoted version of the file VERSION_Q has to be generated, since is required by one source file (main.f90) that includes it.
I hope that it is clear now. Thank you.

When I said “under source control” I asked if that file is added to e.g. your git repository. It doesn’t matter in what directory that file is.

In contrast, if that VERSION_FILE file is created during the build, you must also create your VERSION_Q_FILE during the build. That needs a different solution, than what I wrote.