I have a file in my project which contains the project version number. I have to make the content of this file available as a preprocessor definition in my code.
What I need is to somehow pass the value from the file to the compiler as a /D parameter.
I tried to add the preprocessor definition
VERSION=$(Version)
and set the Version environment variable in a prebuild step, but I did not find a way to do the latter, so I got stuck.
As a workaround, a pre-build step could be created which calls a script that reads the file and generates the macro definition in a header. Then this header file could be included in my projects.
However I do not find this solution nice, I hope there is a better one.
As an alternative to generating .h files, you can also generate a .vsprops (Property Sheet) file. .vsprops files are to .vcproj files what .h files are to .cpp files. In particular, you can define a
/D
command-line option in a property sheet. This is how/D UNICODE
is commonly define, via a default property sheet.The additional benefit is that you can also set the
/VERSION
flag for the linker, something which you can't do via a header file.