views:

64

answers:

4

I am maintaining a large codebase and some vcproj files are used in different solutions. Due to some horrendous configuration and dependencies it seems the best way to handle some build issues is to #ifdef the code but in order to do that I need to set a preprocessor definition at the solution file level and not at the vcproj level.

Is that possible?

How to do it?

+1  A: 

2008 sln's are really dumb, they only have lists of projects/files to put in the solution explorer and project dependencies, so I don't think that's an option.

My gut instinct is to do something with relative paths. For example, in your stdafx.h's you could #include "....\project_configuration.h", then for building sln a, you'd check things out to one dir, and sln b another. Each would have its separate project_configuration.h.

I believe you could do something similar with vsprops files, which are essentially #includes for vcproj files, though I've found them a bit annoying to maintain over time.

Tom
Yeah - I figured the sln files would not be helpful. Your other suggestions are interesting but we're back to the same issue - how to differentiate WHICH sln we are in while building a PROJECT.
Tim
+1  A: 

Select all the projects in your solution. Project + Properties, C/C++, Preprocessor, Preprocessor Definitions. Add

/DSOLUTION=$(SolutionName)

You can now test the SOLUTION macro value in your source code.

Hans Passant
Wouldn't that _set_ this the preprocessor macro (instead off _adding_ to it)? If you do this, make sure the current state of the project files is checked in and safe.
sbi
@Tim: sbi has a point. If the setting is empty after you selected all projects then you'll have to append it for each individual project.
Hans Passant
I only need a setting for ONE project, not all projects i n the solution. I just need to be able to choose to compile (or not) based on which solution I am under.
Tim
Okay, this will be fine then, just ignore the "select all the projects" bit.
Hans Passant
+2  A: 

I believe what you may want to do is create a project property sheet with the VS Project Manager that all the projects could inherit from. This would allow you to set any common project settings, including preprocessor macros, in a single location and inherit them as you need.

Daryl Hanson
A: 

Well, I also looked at

http://stackoverflow.com/questions/485237/define-a-preprocessor-value-from-command-line-using-msbuild

and

http://stackoverflow.com/questions/479979/

and those might work as well, however our build system is pretty brittle right now and I am not in a position to change it all.

The solution I came up with was to clone the build configuration for the project in a solution and give it a different name. Then I added a macros/preprocessor definition to that new configuration.

It appears to work as desired. So one solution uses the old "release" configuration and the other solution uses a clone "ReleaseSpecial" (not the name I really used) configuration with different preprocessor defs.

Not ideal, but it works.

It would be nice if the propoerties were easier to deal with or SLN files could pass in preprocessor defs.

Tim