TheRarebit
TheRarebit

Reputation: 385

Using header file variables to generate include directories

I asked a question a while ago asking about how to check internal library versions at compile time and came up with the following solution:

// GameVersion.h
constexpr unsigned int LIB_VERSION_MAJOR = 1;
constexpr unsigned int LIB_VERSION_MINOR = 0;
constexpr unsigned int LIB_VERSION_PATCH = 0;

// Function stored in our librarys which static_asserts version with its own data
library_version_check<LIB_VERSION_MAJOR, LIB_VERSION_MINOR, LIB_VERSION_PATCH>();

It isn't the greatest solution but it does allow us compile time library version checking rather than building an application and waiting until it runs to discover theres a library version mismatch.

Since then the libraries we use have changed their file structure:

C:\Library\src            //!< Old structure
C:\Library\1.0.0\src      //!< New structure
C:\Library\1.0.1\src

This breaks the include directories stored in the application prop files. Originally we'd include the one folder (Library\src) and then do the internal version check, now the include directories are dependent on the version info stored in this header file. I was wondering if its possible in Visual Studio 2013 to modify a projects include directories based on information stored in header/source files like the one in this example? I was thinking this could be done as some kind of pre-build step or an external script ran as part of the pre-build to generate an inculde directory for the project? I'm stumped as to how to do this though and any enlightenment would be greatly appreciated.

Thanks in advance.

Upvotes: 0

Views: 120

Answers (1)

Pete
Pete

Reputation: 4812

One way to do this would be to use User Macros for the build. Not familiar with VS2013 as I need my stuff to still run on XP and can't 'up'grade. I've not used msbuild so don;t know how much stuff carries over from the older build system.

That being said, in VS2008 you could have user macros in a .vsprops file for the 3 version numbers. These can be used to generate the version info file by being passed as arguments to a a pre-build step. e.g.

make-ver.exe GameVersion.h $(VerMajor) $(VerMinor) $(VerPatch)

You can then use these user macros as you wish throughout the build configuration and these are automatically updated in your source code by the build.

Alternatively to this method, could you not use the old structure for the head revision only?

Then when you release a version, copy the files to the versioned folder by using its version information (i.e. embed the version info in the exe/dll's resources).

There are windows APIs for extracting version resources. See GetFileVersionInfo. Using this you could write a simple exe to do the copying for you.

I do something similar when I build installers for a few projects. Once the installer is built, it gets the version info from the main exe and appends this to the file-name of the installer.

I personally don't bother with versioned source folders for dependencies - the dependencies are all in SVN externals and built at the same time as the main exe. These are tagged at each release using a special script that pegs the SVN revision of the externals.

Upvotes: 1

Related Questions