0

On the disk I have a file VERSION with in it the version number this is used in CMakeLists.txt means of

include(version)

where the version.cmake has as content:

file (STRINGS "${TOP}/VERSION" VERSION)
set(ENV{VERSION} "${VERSION}")

The so created environment variable used is later on by means of:

add_custom_target(run_doxygen
        COMMAND ${CMAKE_COMMAND} -E env VERSION=${VERSION} ${THE_EXECUTABLE}
)

(with also setting some dependencies and the working directory).

So far so good, though when just changing the value in the VERSION file, the value of the environment variable is not changed, it is first changed when one of the cmake files is changed (the cmake configuration step is rerun at that moment).

How to overcome this problem?

albert
  • 8,285
  • 3
  • 19
  • 32
  • In other words, you want to automatically re-run CMake if file at `${TOP}/VERSION` is changed. This is described e.g. in [that question](https://stackoverflow.com/questions/24246037/how-to-make-cmake-reconfiguration-depend-on-custom-file). Upon re-run, CMake will update content of the COMMAND in `run_doxygen` target. – Tsyvarev Aug 27 '22 at 13:50
  • 1
    "... The so created environment variable used is later on by means of: ..." - No, your further code (by construct `${VERSION}`) uses **CMake** variable, not the **environment** one. The setting of environment variable `VERSION` is lost after configuration is done. – Tsyvarev Aug 27 '22 at 13:54
  • @Tsyvarev indeed about the env var is good to know – albert Aug 27 '22 at 16:12
  • I tried the`configure_file(MyInputFile.xml DummyOutput.xml)` trick and this looks like to work (though I'd say I would never have thought about it, and I think that is very obscure as). – albert Aug 27 '22 at 16:18
  • `configure_file` is an old way for enforce dependency. Modern way is `CMAKE_CONFIGURE_DEPENDS` property, and it is described in the [most voted answer](https://stackoverflow.com/a/32464853/3440745). (Acceptance was never a signal of "the best" answer, and recent sorting changes on Stack Overflow are meant to emphasize that: https://meta.stackoverflow.com/questions/411352/outdated-answers-accepted-answer-is-now-unpinned-on-stack-overflow). – Tsyvarev Aug 27 '22 at 17:15
  • @Tsyvarev I first tried that answer, but couldn't get it working ... – albert Aug 27 '22 at 17:23
  • @Tsyvarev revisiting , looks like to work (although the word DIRECTORY is here a bit strange to me). – albert Aug 27 '22 at 17:39

0 Answers0