Question

I have a file in one of our projects that defines a variable that affects the behavior of most of the other modules throughout the project. Let's call it custom.h. It looks like this:

#pragma once

#define BUILD 3 // 1: personal, 2: select, 3: elite

Throughout the project there are numerous references to this variable to control behavior between product editions. Changing this value triggers a rebuild of most of the project. What I'd like to do is create separate Build Configurations, one for each edition, so that it only rebuilds modified files, not the entire project, when I make a change to the edition.

If I have three Configurations, one for each edition, is there a way to get Visual Studio not to rebuild when a change is made to this custom.h file if the edition matched what was built for that Configuration already? IE, if I set BUILD to 3 and build with the Elite Configuration, then change BUILD to 2 and build with the Select Configuration, I don't want it to rebuild the whole project, because the Intermediary Files for Select should already exist.

The Configurations all have their own Intermediary Directories as well as their own Output Directories. It feels like I'm close to what I need, but some advice at this point would be invaluable.

Was it helpful?

Solution

Rather than changing the defines for each build, one option would be to use configurations like you mentioned and define Preprocessor Definitions in your project. Then use compile directives for each configuration. I think this would let your incremental compiles work correctly.

Your custom.h would look like this:

#pragma once

#if defined(PERSONAL)
    #define BUILD 1 
#elif defined(SELECT)
    #define BUILD 2 
#elif defined(ELITE)
    #define BUILD 3 
#endif

The Preprocessor Definitions can be set in the Project Properties or via command line switches depending on how you build.

Directives on MSDN

Preprocessor Definitions on MSDN

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