Question

I am using VS2008, and developing C/C++ projects. I am using .bat file to build my projects from commandline (VC2k8 command prompt). I need a way to include preprossor directive dynamically at build time.

I am using devenv to build from command line.

>devenv my\project\path\myproject.sln /build release > logs\build.log

Actually I want to set a macro definition based on a command line parameter to the batch file. I can keep two different .vcproj files, but that gives problem in keeping multiple project/sln files. My batch file would something like this...

if (condition)
#define MYPROC_ENABLE_MYMODULE "yes" // To be included in the project.
else
#define MYPROC_ENABLE_MYMODULE "no"

Any help would be really appreciated.

Thanks.

Was it helpful?

Solution

One option would be to set the CL environment variable, using something like:

set CL=/DMYPROC_ENABLE_MYMODULE

The C++ compiler (cl.exe) will add the contents of the CL environment variable to its command line when it runs.

I know you can define macros if you build using msbuild, but I'm not sure you can do the same when using devenv directly.

OTHER TIPS

You can make different configurations for your solution and define different preprocessor flags for the different configurations. Then you would just need to select the configuration at the command line and no need for multiple solution or project files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top