josh's WebLog

Visual C++ IDE from the trenches

understanding the VC project system part IV: properties and property inheritance

picking up from where we left off, there are a couple of "special" macros: $(Inherit) and $(NoInherit). to understand what they are and how they work, you first need to understand how inheritance works with properties.

earlier we looked at the property pages dialog for a project. i said one thing in that post that isn't quite true: "if the property value is not bold, the property is in its default state and has not been set". the whole truth is that it means it hasn't been set at that level in the inheritance chain. the inheritance chain for properties, starting with "most-derived" looks like this:
file (file configuration)
project (configuration)
property sheets
defaults
what this means is that when the project system needs to find the value of a property it first checks with the file configuration in question (e.g. foo.cpp, debug configuration), then with the project-level configuration, then with the property sheets and finally, since it wasn't explicitly set anywhere, it falls back to whatever the ultimate "default" value should be. hopefully what the file configuration and project configuration levels are is apparent, and you can view them easily in the property pages dialog by selecting either a file node or a project node in solution explorer when you have the dialog open.

the term "property sheets" is probably new to you, however. property sheets are a mechanism for setting a collection of property values in one place. the items that you see on the "general" property page, under the "project defaults" category actually control which property sheets your configuration inherits from. for instance, if you have "Use of ATL" set to "Dynamic link to ATL", what that actually means is that your configuration inherits from the ATLDynamic.vcstyle property sheet (found in the vc7\VCProjectDefaults directory in your VS installation). if you opened this file you would see that it is an XML file that looks remarkably similar to a project file. in VS 2002/2003 property sheets are only an internal mechanism; in the upcoming version of VS they are exposed to the user so that projects can be configured in quite complex ways. more on this in a future post.

as far as the properties themselves, there are five types: booleans, enumerations, integral values, text strings and multi-strings. booleans, integral values and strings are fairly self-explanatory; enumerations are those properties which have a set number of choices; multi-strings are collections of single strings that are separated by a delimiting character (generally a comma or semi-colon). a good example of a multi-string is the include paths for the compiler to search.

now, getting back to our two special macros, $(Inherit) and $(NoInherit). these two macros allow you to exercise some additional control over how string properties are evaluated. $(NoInherit) means that the normal course of inheritance described above should not be followed, and the property value should be taken from the current level and its "children" only. $(Inherit) is only useful in multi-string properties; it indicates that the values that were inherited from the "parents" should be inserted at the point where the macro is. for instance, let's say the value for the "preprocessor definitions" property on a file configuration is "FOO; $(Inherit); BAR", and the value of the same property on the project configuration is "TOSTADA; $(NoInherit)". now the fully evaluated property value will be "FOO; TOSTADA; BAR", because the $(NoInherit) macro at the project level tells it to not pick up anything from the levels below it, and the $(Inherit) value at the file level tells it to put the inherited values (TOSTADA) between FOO and BAR.

that about covers properties and wraps up the basics of the project system. next i'll be moving on to cover how projects are built.
Published Monday, February 09, 2004 6:25 PM by josh_
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker