Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional compilation for working at home

Tags:

c++

I code C++ using MS Dev Studio and I work from home two days per week. I use CVS to keep my sources synchronized between the two computers but there are difference between the environments the machines are in.

Can anyone suggest a way I can conditionally modify constants in my code depending on whether I am compiling on my home box or not ?

What I am after is a way of defining a symbol, let's call it _ATHOME, automatically so I can do this:

#ifdef _ATHOME
#  define TEST_FILES  "E:\\Test"
#  define TEST_SERVER "192.168.0.1"
#else
#  define TEST_FILE   "Z:\\Project\\Blah\\Test"
#  define TEST_SERVER "212.45.68.43"
#endif

NB: This is for development and debugging purposes of course, I would never release software with hard coded constants like this.

like image 671
Adam Pierce Avatar asked Jun 10 '26 12:06

Adam Pierce


1 Answers

On your home and work machines, set an environment variable LOCATION that is either "1" for home or "2" for work.

Then in the preprocessor options, add a preprocessor define /DLOCATION=$(LOCATION). This will evaluate to either the "home" or "work" string that you set in the environment variable.

Then in your code:

#if LOCATION==1
  // home
#else
  // work
#endif
like image 134
1800 INFORMATION Avatar answered Jun 13 '26 01:06

1800 INFORMATION