views:

135

answers:

1

We came across a bunch of pre-defined Build Macros for instance $(SolutionDir), but can you define your own build macros in Visual C++ 2005?

+1  A: 

The way that I have done this is to attach a .vsprops file to the project. When editing the properties of the custom property sheet, there's a "User Macros" section.

Here's an example from the VS2008 solution I set up to build Boost:

The .vcproj file is set up as an NMake project with the command line set to:

$(BJAM) $(BOOST_COMMON_OPTIONS) $(BOOST_RELEASE_VARIANT) $(BOOST_LINK_STATIC) ...

There are multiple variants with similar command lines, and these macros allow me to share common definitions across the various project configuration types. You can also use them to set default configuration options that apply to all the project configurations.

In the property manager, I added a custom property sheet to the project, and set up various user-defined macros:

http://imgur.com/r62dK.png

Tim Sylvester