I have a static library that is used in production code and test code. I want to be able to inject test data only if I am building the test .exe. I would like to do this using preprocessor #defines, rather than MSVS configurations (e.g., Debug vs. Release) because I am testing performance. Debug builds turn off optimization, which is great during debugging but not so great when I want to test performance.
As an example, say I have Foo.lib, Production.exe, and Test.exe projects in MSVS. Production.exe and Test.exe both link Foo.lib. I would like Production.exe and Test.exe to rebuild Foo.lib with their respective preprocessor definitions, so the code in Foo.lib will conditionally compile based on which executable it is targeted for.
I'm open to other solutions, and I hope I stated my problem clearly. First post on stack overflow.
You'll need to set up multiple solution configurations to support each of the scenarios you desire. First we'll add a new Test configuration to the static library, and create an accompanying Test solution configuration:
Now you can modify your static library's new Test configuration with your desired #defines:
...now, you want to set your builds up so that you have a build configuration that builds Test.exe with the static library's Test configuration, and the Release.exe with the library's Release configuration. Go back to the Configuration Manager (as we did in the first two steps above):
Set up your build configuration for Release.exe:
Set up your build configuration for Test.exe:
Now, when you change your solution to Test or Release configuration, I'd expect you to have the build behavior you desire for each.