Author Topic: Using selected project configuration with pre-processor directives?  (Read 6838 times)

SyRenity

  • Community Member
  • Posts: 9
  • Hero Points: 0
Hi.

Is it possible to detect the selected project configuration, and then according to it include/exclude some code?

Something like this:

Code: [Select]
#ifdef Debug
    //Run tests
#endif

Thanks.

Wanderer

  • Senior Community Member
  • Posts: 557
  • Hero Points: 23
Re: Using selected project configuration with pre-processor directives?
« Reply #1 on: August 17, 2006, 11:35:29 PM »
I'm not sure exactly what you are asking, but two things come to mind.
1)  Maybe View->Selective Display->Preprocessor Directives is what you're looking for.
Using the 'Scan for Defines' button makes it pretty easy.

We have quite a bit of old code that is littered with preprocessor junk, as we built for Mac/Win/Motif/OS2/dontRememberWhatElse.
The Selective Display capability is great, but you do need to be careful that you assign the right values to the tokens.
For example, we have tokens for a number of windowing systems:

#define MACWS   0
#define WINWS   1
#define PMWS   2
#define WMWS   3
#define X11WS   4
#define XOLWS   5
#define DWTWS   6
#define MTFWS   7

A lot of the conditional compiling is in blocks such as
#if XVTWS == WINWS
so you need to define both XVTWS and WINWS correctly, or you won't be looking at the code you want...

2)  Look at the Project->Properties->Compile/Link tab.  While I have no experience with it, it looks like it might be useful to you.

Maybe you could elaborate on what exactly you are trying to do?


SyRenity

  • Community Member
  • Posts: 9
  • Hero Points: 0
Re: Using selected project configuration with pre-processor directives?
« Reply #2 on: August 19, 2006, 04:15:57 AM »
Hi.

I have a test framework, which I want to include only for the Debug configuration. For the Release configuration, I need to exclude it. Hence, I thought about using #ifdef macros to define the framework usage code only for the Debug configuration.

Unfortunately, I couldn't find the exact method how to do it, although I found some examples for general gcc:

#ifdef _DEBUG
return TestRun();
#endif

I'm not locked on this approach, any other idea of how to achieve the above will be very welcomed.