# Introducing file dependencies

**URL:** <https://discourse.cmake.org/t/introducing-file-dependencies/11695>\
**Category:** Code\
**Created:** [September 16, 2024, 1:05pm UTC](https://discourse.cmake.org/t/introducing-file-dependencies/11695 "2024-09-16T13:05:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![artu72](https://discourse.cmake.org/user_avatar/discourse.cmake.org/artu72/32/4929_2.png) [@artu72](https://discourse.cmake.org/u/artu72)\
**Post date:** [September 16, 2024, 1:05pm UTC](https://discourse.cmake.org/t/introducing-file-dependencies/11695/1 "2024-09-16T13:05:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)\
**Post date:** [September 16, 2024, 6:38pm UTC](https://discourse.cmake.org/t/introducing-file-dependencies/11695/2 "2024-09-16T18:38:59Z")

</div>

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](https://cmake.org/cmake/help/latest/prop_dir/CMAKE_CONFIGURE_DEPENDS.html).  
If a file in that property change, then the build system will call CMake again for re-configuration.

---

<div class="post-metadata">

**Author:** ![artu72](https://discourse.cmake.org/user_avatar/discourse.cmake.org/artu72/32/4929_2.png) [@artu72](https://discourse.cmake.org/u/artu72)\
**Post date:** [September 17, 2024, 6:26am UTC](https://discourse.cmake.org/t/introducing-file-dependencies/11695/3 "2024-09-17T06:26:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)\
**Post date:** [September 17, 2024, 4:45pm UTC](https://discourse.cmake.org/t/introducing-file-dependencies/11695/4 "2024-09-17T16:45:34Z")

</div>

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.
