conditional compilation in xrc Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Lloyd
Super wx Problem Solver
Super wx Problem Solver
Posts: 350
Joined: Wed May 03, 2006 2:36 pm
Location: India
Contact:

conditional compilation in xrc

Post by Lloyd » Thu Apr 24, 2008 11:44 am

Hi,
Our application has two varients one is demo and the other one is the original. we have a splash screen which is different for demo and the actual application. We use xrc (XML) based resource system to store and access these images. An example would be

Code: Select all

<?xml version="1.0"  encoding="ISO-8859-1"?>
<resource version="2.3.0.1">
<object class="wxBitmap" name="SPLASH">../images/splash.png</object>
...
...
And we access it using

Code: Select all

SplashBitmap=wxXmlResource::Get()->LoadBitmap(wxT("SPLASH"));
can I use of some sort of conditional inclusion in the xml file. So that based on the compilation argument (as -D option in gcc) the appropriate file is only added to the resource (resource.cpp) file..

Hope I made things clear. In not I am ready to explain it more...

Thanks,
Lloyd

mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r » Thu Apr 24, 2008 7:37 pm

No conditionals in xrc as far as i know. But you could give the splash 2 different names and load one or the other based on the flag.

Or, you could have 2 xrc files and load which ever is appropriate.

-Max

EDIT: sorry didn't read close enough.

If you only want one of the images to be added at compile time you will have to configure something in your build system(Makefile).

Or you could use C preprocessor commands #ifdef #define, etc... and use -E to gcc to preprocess it outputting to your xrc. You will probably have to use -P as well to surpress generation of line numbers.

-Max

Lloyd
Super wx Problem Solver
Super wx Problem Solver
Posts: 350
Joined: Wed May 03, 2006 2:36 pm
Location: India
Contact:

Post by Lloyd » Fri Apr 25, 2008 8:22 am

Code: Select all

No conditionals in xrc as far as i know. But you could give the splash 2 different names and load one or the other based on the flag.

Or, you could have 2 xrc files and load which ever is appropriate. 
The above 2 method seems to be the normail idea.

Unfortunately I didn't understand the following...

Code: Select all

If you only want one of the images to be added at compile time you will have to configure something in your build system(Makefile).

Or you could use C preprocessor commands #ifdef #define, etc... and use -E to gcc to preprocess it outputting to your xrc. You will probably have to use -P as well to surpress generation of line numbers. 
yes I use #ifdefs in my code. To avoid the complexity of addidng ifdefs here and there in the code, I could have simplifid it if conditional inclusion of a line in xml file is possible. So I could have used same name for both image files.

Thanks,
Lloyd

mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r » Fri Apr 25, 2008 5:31 pm

Lloyd wrote:Unfortunately I didn't understand the following...

Code: Select all

If you only want one of the images to be added at compile time you will have to configure something in your build system(Makefile).

Or you could use C preprocessor commands #ifdef #define, etc... and use -E to gcc to preprocess it outputting to your xrc. You will probably have to use -P as well to surpress generation of line numbers. 
yes I use #ifdefs in my code. To avoid the complexity of addidng ifdefs here and there in the code, I could have simplifid it if conditional inclusion of a line in xml file is possible. So I could have used same name for both image files.

Thanks,
Lloyd
Which is what the bit you didn't understand was trying to explain. If you don't want both images in the xrc and want to remove when based on compile time flags -D, you will have to write something that isn't and xrc (XRC doesn't know about #ifdef) and have gcc preprocess it and generate an xrc for you from your thing that looks like xrc but with #ifdef's

-Max

Lloyd
Super wx Problem Solver
Super wx Problem Solver
Posts: 350
Joined: Wed May 03, 2006 2:36 pm
Location: India
Contact:

Post by Lloyd » Mon Apr 28, 2008 4:04 am

Thanks Max.

Post Reply