Question

I have a C++ project that builds on several platforms.

On Mac OSX and Linux, I use SConstruct, which allows me to have some "smartness" regarding the different compilation steps. Namely, I could put the program version in a file named VERSION at the root of the repository, whose content is simply:

2.0

In the build SConscript, I just have to open, read and parse that file and I can create dynamic defines based on it. For instance:

env.Append(CXXFLAGS=['-DVERSION_MAJOR=%s' % open('VERSION').read().split('.')[0]])

This is, for obvious reasons, very convenient. It also allows me to put today's date in an environment variable for instance.

Now for Windows, I have a .sln file with different .vcxproj files into which I'd like to do something similar, except I have no idea how.

To summarize, my question is: how can I have "smart" defines like that (reading, parsing a file and putting its content into several environment variables) without having to change the .sln/.vcxproj files manually on every version shift ?


I know I could use SCons on Windows too, but I'd like not to (mainly because it seems less popular on the platform, and I don't want to scare potential contributors that only know Windows-specific tools).

Was it helpful?

Solution

A common way to do this is to define your constants in an include file: e.g.

// Version.h - Autogenerated, don't edit
#define VERSION_MAJOR 1

Next you write a script or a program (in your favourite language) to obtain version from somewhere and dynamically write Version.h. Possibly parse the old Version.h and increment or get it from some external source.

In visual studio, create a custom build step for Version.h and make it dependent on something that forces it to update on every build.

OTHER TIPS

You could maintain the current solution, and for Windows, integrate it with Visual Studio solution and project files generated by SCons using the MSVSProject() builder or the MSVSSolution() builder.

You can find more info about these SCons builders here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top