Metadata (`git describe') in OUTPUT_DIRECTORY

Problem Description

I would like to use metadata, like the result of git describe, in the *OUTPUT_DIRECTORY_<CONFIG> variables.

I am already using metadata, which is constant and can therefore be added in the configuration/generation phase, like the compiler name and version, target architecture, which I will not change from build to build.

I could also already include some dynamic metadata using generator expressions, like the configuration in use (DEBUG, RELEASE, etc.), which is known only during the build phase for multi-config generators, like Visual Studio.

So I currently have folders which like are named like that:


whereas I want them to look like that:


and after I e.g. commit my code, I do not want to reconfigure the CMake project, but new folders with names like these should be generated:


Failed “Solutions”

I thought about adding a post-build-target, which would run after any of my targets ran and would get the git describe information and substitute the placeholder accordingly.

One of the problems is about how to define a post-build-target like that. I have a pre-build-target, which generates an file with this git metadata, including the history of the last 20 commits, etc. and it was easy to have it build before ANY other target was build, by simply adding it as a dependency to every other target.
But the opposite for the post-build target would not work, i.e. when adding every other target as a dependency of the post-build-target I would always have to build everything.

A second problem could be that if I do not e.g. commit my code from one to the next build, the git describe tag stays the same and in that case the target folder already exists (from a previous build) and renaming the temporary folder name to the final one could cause a conflict.
On the other hand maybe the two folders would be merged?!


The consequence is that I am getting the git describe information during the configure/generate phase. Whenever I commit code, I manually reconfigure my CMake project to update the ${GIT_DESCRIBE_INFORMATION} variable.


Does anyone have an idea how I could manage this problem?

Why do you want this done during the build rather than during something like the install or packaging step (where such information is attached to the build)? Also, making a new commit would cause everything to be out-of-date as the output “doesn’t exist”? This also means that CMake needs to rerun for every commit which seems…overkill to me. I’d say that you probably want this to be done at the packaging step myself.

I thought cpack was used to create an installer and the install phase was mostly used on Unix systems, where it is common for the user to build and install from source code.

I am building on a development PC, want to create an output folder as shown above, compress that folder and manually copy&extract the compiled applications on a target PC.

I’ll have a closer look at cpack and see whether that does the trick. Thanks for the hint! :slight_smile:

Yes, that can be done using the CPack Archive generators.