darda
darda

Reputation: 4155

Using a #define in build output name in Visual Studio

I'm using Visual Studio 2010 for a C/C++ project. As far as version numbers go I like to have a revision and build date; for example "Project 1.0 R2 Apr 21 2013". I display this at startup, so I can easily tell if someone is running an old version. Now I'd like to put things like this in the filename of the executable created by the build. For example, "Project10R2.exe".

I make use of the build macros as listed here. For display of the build date, I use the predefined macro as listed here. To clarify possible confusion, the build macros are usable from, say, the project properties and what they refer to as "predefined macros" are #define's. I know you can define custom custom build macros (see this) (and obviously any #define I desire).

Now what I want is to use one with the other. That is, I'd like to define a revision string in one place and have it appear both in the program output at startup (easy with a #define) and also in the build output filename (easy with a custom $ macro). I don't want to maintain two different constants.

Anyone know how to do this? It appears you cannot even put the build date in the filename (not safely, anyway, if you use the Windows %DATE% environment variable, you may end up with illegal characters.)

Upvotes: 3

Views: 991

Answers (1)

SMMB
SMMB

Reputation: 127

As you've said you can create a custom build macro and then in your project's Properties > C/C++ > Preprocessor > Preprocessor Definitions, you can add something like this: $(my_custom_build_macro);... but this would define the macro in every file.

Upvotes: 0

Related Questions