Search code examples
c++msbuildnmakewdkmakefile

Pass macro to nmake


From my earlier post, I figured out why the command

build /nmake "USER_C_FLAGS=/DMyVersion=3"

doesn't associate the define MyVersion with value 3. MSDN says that -

Compiling with /Dname= causes the symbol to not have an associated value. So, while the symbol can still be used to conditionally compile code, the symbol will otherwise evaluate to nothing. For example, in the previous sample program, compiling with /DTEST= will cause a compiler error. This behavior is similar to using #define with or without a value.

I have an environment variable that gets set up at run-time and I need to pass that env. variable to the Visual Studio 2005 Makefile Project. Now the question is, how can I pass the env. variable to the run-time build environment ? Once passed, I should be able to something like -

#define VERSION 11

#ifdef BUILD_VERSION       // How to get this macro to the current env. ?
   #undef VERSION
   #define VERSION BUILD_VERSION
#endif

#define FILE_VERSION VERSION

I don't see any flags from nmake documentation to pass env. variables. Any ideas are highly appreciated.


Solution

  • MSDN will answer this for nmake Environment-Variable Macros.

    Pay attention here: "Use the /E option to cause macros inherited from environment variables to override any macros with the same name in the makefile."