We have several projects in development sharing the same codebase. Certain pieces of code are only relevant to one or other of those projects.
We have a couple of requirements:
The first requirement is that we want our final releases not to compile in code from the other projects.
One solution (the one we like) is to use the preprocessor to remove that code: (this is what we do in some places).
#if defined PROJECT1
{
// some code
}
#endif
The second requirement is, that while we are developing, it is helpful to make sure that a change of code still works across all projects, so we would like to compile ALL the project code at once, and be able to switch between projects without a recompile - so in other places in our code, we use a variable to determine the project instead:
if (project == 1)
{
// some code
}
What I'd like to be able to do is to combine the benefits of both - code which in some situations (let's say determined by a #define REMOVECODE) is not included in the final exe at all, but in other situations (determined by the non-definition of the REMOVECODE define) to include the code in the compiled .exe
One more thing - sometimes we have code which exists in a couple of projects, so the solution would need to handle tests like "if project == 1 || project == 2"
I'm thinking it would look something like the following (this doesn't work because I don't think you can nest preprocessor directives), but I'm not sure if it is even possible with macros. Maybe there's some kind of template solution?
#ifdef REMOVECODE
#define BEGINTEST #if
#define ENDTEST #endif
#define CONDITION1 defined PROJECT1
#else
#define BEGINTEST if
#define ENDTEST
#define CONDITION1 project == 1
#endif
BEGINTEST(CONDITION1)
{
// some code
}
ENDTEST
If anyone can help out, I'd be much obliged.