Platform specific built in compiler directive

8 posts / 0 new
Last post
ezyclie
ezyclie's picture
Offline
Mobile Wizard
Joined: 4 Mar 2010
Posts:
Platform specific built in compiler directive

Hi,

Is there any MoSync built in compiler directive that i can use to build my code differently for every platform.

Thanks in advance

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Fredrik Eldh
Fredrik's picture
Offline
Mobile Sorcerer
Joined: 16 Feb 2009
Posts:

Not sure it's exactly what you want, but if you #include , you'll get the profile information of the device you're building for.

To see the contents of maprofile.h, you can right-click any device in the MoSync IDE's device list and select "Show profile info".

If you want to access the files outside of the IDE, they are stored in /MoSync/profiles/vendor/.

ezyclie
ezyclie's picture
Offline
Mobile Wizard
Joined: 4 Mar 2010
Posts:

Hi Fredrik,

I need compiler directive to compile my code differently for every platform, for example:

#if defined(__SERIES60__)
#if defined(__SERIES60_2X__)
// code for symbian s60 2nd ed
#elif defined(__SERIES60_3X__)
// code for symbian s60 3rd ed
#endif
#elif defined(__WINMO__)
// code for winmo
#endif
Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

You need to look at the properties

#define MA_PROF_STRING_VENDOR
#define MA_PROF_STRING_DEVICE
#define MA_PROF_STRING_PLATFORM

in any maprofile.h - have a look at the one for the Nokia N95 for example. It contains

#define MA_PROF_STRING_VENDOR "Nokia"
#define MA_PROF_STRING_DEVICE "N75"
#define MA_PROF_STRING_PLATFORM "s60v3"

The Acer Liquid A1 has

#define MA_PROF_STRING_VENDOR "Acer"
#define MA_PROF_STRING_DEVICE "Liquid A1 S100"
#define MA_PROF_STRING_PLATFORM "android"

and the Gigabyte g-Smart has

#define MA_PROF_STRING_VENDOR "Gigabyte"
#define MA_PROF_STRING_DEVICE "g-Smart"
#define MA_PROF_STRING_PLATFORM "wm6pro"

so what you can do is test the values of this string.

Alternatively, using the directives you've shown, you can use these values

#define MA_PROF_SUPPORT_OS_SYMBIAN_OS_9_1
#define MA_PROF_SUPPORT_OS_WINDOWS_MOBILE_6

Although there doesn't appear to be a an equivilent for Android, which I think is something MoSync will need to add.

ezyclie
ezyclie's picture
Offline
Mobile Wizard
Joined: 4 Mar 2010
Posts:

Cool! Thanks

ahaeber
ahaeber's picture
Offline
Joined: 2 Jul 2010
Posts:

In addition to MA_PROF_STRING_PLATFORM it would be nice with macro definitions that can be easier used in pre-processing directives.

For example, for HTC Bravo we currently have:
#define MA_PROF_STRING_PLATFORM "android"

It is hard to use this one with pre-processor directives like:
#if MA_PROF_STRING_PLATFORM = "android"
MAUI::Label* androidSpecificLabel;
#endif

gives me the following error from the gcc preprocessor: "token ""android"" is not valid in preprocessor expressions"

Therefore, it would be great if we instead had defines like: MA_PROF_PLATFORM_ANDROID, MA_PROF_PLATFORM_SYMBIAN_S60V3, ...

... or is there a simpler solution I haven't thought about for what I want to achieve here?

Sam Pickard
rival's picture
Offline
Mobile Archmage
Joined: 19 Mar 2009
Posts:

#define MA_PROF_STRING_PLATFORM_ANDROID

#ifndef _MSAB_PROF_H_
#define _MSAB_PROF_H_

#define MA_PROF_STRING_VENDOR "HTC"
#define MA_PROF_STRING_DEVICE "Droid Eris"
#define MA_PROF_STRING_PLATFORM "android"
#define MA_PROF_STRING_PLATFORM_ANDROID
#define MA_PROF_VENDOR_HTC
#define MA_PROF_DEVICE_DROID_ERIS

#define MA_PROF_CONST_SCREENSIZE_X 240
#define MA_PROF_CONST_SCREENSIZE_Y 320
#define MA_PROF_CONST_BITSPERPIXEL 8
#define MA_PROF_SUPPORT_CAMERA
#define MA_PROF_SUPPORT_STYLUS

#endif /* _MSAB_PROF_H_ */

ahaeber
ahaeber's picture
Offline
Joined: 2 Jul 2010
Posts:

Thanks. I forgot to mention that I'm using MoSync 2.3 Beta r767. I downloaded the most recent nightly build (2.5 r1592) and found the MA_PROF_STRING_PLATFORM_#name# define you mention.

If anyone else wonders this change was added in r1276.