Adding Makefile-like conditional logic to visual studio's build system
Say I have a C++ project in Visual Studio 2008, and its compilation depends on a number of configuration settings. For example, I have optional preprocessor definitions WITH_MYLIB and EXPERIMENTAL which modify the code.
A user that has MyLib will want to compile using a project configuration that has WITH_MYLIB in the list of preprocessor definitions, and adds the library to the include/link settings. A user who wants to enable experimental features will want to add EXPERIMENTAL to the preprocessor definitions. But other than these changes, the rest of the project configurations should be mostly identical.
I am trying to avoid creating an "exponential" number of project configurations to handle all of the possibilities, namely I don't want to have
- Debug
- Debug_WithMyLib
- Debug_WithMyLib_Experimental
- Debug_Experimental
- ...4 more for Release...
because there is a huge amou开发者_开发问答nt of redundancy here.
Using Makefiles this would be very easy because the makefile would use an "if" statement to augment the compiler flags as necessary, leaving the rest identical between configurations.
I am aware of build systems such as CMake, SCons, etc. and I realize they would probably solve my problem.
My question is simply whether there is any reasonable approach to achieve this with visual studio's build system. And if this is somehow related to that "Inherit from parent or project defaults" option that appears in visuals studio, maybe someone could explain to me how this parent and its defaults are set/changed.
Thanks.
There is a feature called "property sheets" which solves exactly what you want. You simply add a new property sheet to your project and add it to your projects. Settings done in property sheet are inherited in every project. So you can simply define the literal you want in one place and affect whole projects.
Take a look at the "Property Manager" in the Visual Studio "View" menu.
MSDN link http://msdn.microsoft.com/en-us/library/a4xbdz1e(v=vs.80).aspx
精彩评论