kcomex | 28 May, 2008 09:14
In Symbian C++ development, MMP file is used to define a project. For large or complex project, often it is needed to gather some switches in a place act as configuration file, so different target could be made by changing configurations while the rest project file stay untouched. With help of MACROs we could get this done. Probably most of us had very smooth experience when using MACROs in their .cpp or .c files, but using MACROs in MMP is not so pleasant.
Before starting my words, it is good to revise MMP file syntax and related information from Symbian Developer Library. From the document we know MACROs for source files (.CPP) could be set by MACRO statement. But what about using conditional flow control in MMP file? I guess you must have examined the "hellowordbasic" example comes with S60 SDK 3rd Edition, and probably you have used this in MMP for a S60 3rd project:
#ifdef WINSCW
TARGETPATH \private\10003a3f\apps
#else
TARGETPATH \private\10003a3f\import\apps
#endif
This told us preprosessor which deals with MACROs is used in MMP and many built-in MACROs are used, for example WINSCW, EKA2 and so on. With the power of MACROs in MMP we could do many, maybe the first one you want is using one MMP for one application with two (SymbianSigned and self-sign) UIDs. See below:
TARGET MYAPP.exe
#if defined (M_SELFSIGN)
UID 0x100039CE 0xA000ABCD
#else
UID 0x100039CE 0x20006789
#endif
Obviously, this single MMP with two possible UIDs reduces many labors. Yet lines shown above is not complete. You have to define M_SELFSIGN in an earlier place. We mentioned "gather configuration switches in one place" in the beginning, so we make a "config.h" and include it in our MMP by add #include "config.h" line before TARGET statement. The content of config.h could contain:
#ifndef __CONFIG_H__
#define __CONFIG_H__
/* Switches */
#define S_SELFSIGN
#define S_ANOTHER_SWITCH
/* BODY */
#ifdef S_SELFSIGN
#define M_SELFSIGN
MACRO __SELFSIGN__
#endif //S_SELFSIGN
#endif //__CONFIG_H__
In this config.h file, we have two sections. First one is switches and the second one is body statements used in MMP. You could see with help of #define M_SELFSIGN , we can use conditional control flow in our MMP file, so two UIDs are applied in one single MMP. If you want to use SymbianSigned UID, just comment the #define S_SELFSIGN . Also we add a MACRO statement so that .CPP file could know this switch too.
Macro is a powerful tool, wielding this could reduce many of your labor work. I hope you could get insights by reading this, and glad to hear feedbacks on tricks of this kind.
CommentsPropecia | 23/01/2010, 02:41
That is some inspirational stuff. Never knew that opinions could be this varied. Thanks for all the enthusiasm to offer such helpful information here.
Re: Using MACRO in MMP
sri_mform | 17/09/2008, 01:54
Nice one and very informative.
I like to add one more info here,Using macro we can segregate SDKs' specific code from the cpp file and reuse the code to make work across various SDKs.