Set preprocessor definitions from file content in

2019-03-03 03:51发布

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.

2条回答
我想做一个坏孩纸
2楼-- · 2019-03-03 04:28

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.

查看更多
Explosion°爆炸
3楼-- · 2019-03-03 04:40

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.

查看更多
登录 后发表回答