Bug 2409 - Provide conditional compilation symbols for MonoTouch apps and libraries
Summary: Provide conditional compilation symbols for MonoTouch apps and libraries
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: iOS add-in ()
Version: Trunk
Hardware: Macintosh Mac OS
: Normal enhancement
Target Milestone: ---
Assignee: Jeffrey Stedfast
URL:
Depends on:
Blocks:
 
Reported: 2011-12-07 22:31 UTC by Greg Shackles
Modified: 2013-03-25 16:42 UTC (History)
7 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Greg Shackles 2011-12-07 22:31:20 UTC
If would be very useful for writing cross-platform libraries if MonoTouch could define conditional compilation symbols. For example, in Mono For Android it defines __ANDROID__, and then other symbols based on the target API level, such as __ANDROID_10__. If possible, these should be applied to both applications and class libraries.
Comment 1 Sebastien Pouliot 2011-12-08 08:47:52 UTC
-> monodevelop

MonoTouch itself does not compile the code. The MonoDevelop iPhone addin is calling `smcs` to do the job and it's where any additional define can be added.

IIRC one was added for SIMULATOR a while ago.
Comment 2 Miguel de Icaza [MSFT] 2011-12-11 21:38:01 UTC
I have never liked the idea of adding these symbols to the compilation, but they seem to be a pretty common request.

If we decide to add these, we could not add those to the Mono C# compiler as the next version of the compiler will be unified, so we should look into adding the following:

__monotouch__
__monodroid__

API levels sound like it is taking this a bit too far.

Michael, how could we add this to the iPhone and Android projects?
Comment 3 Mikayla Hutchinson [MSFT] 2011-12-12 10:38:19 UTC
There are two ways we can do this:
a) have hardcoded defines injected by the build system
b) add the defines to the configurations of each project we create

If we want them version-dependent, then (a) would make sense. It would also affect existing projects. I suppose that would also make more sense for double-underscore "internal" defines. However, implementing this for MonoTouch would currently require a small amount of work on MD core. For xbuild/android it's much easier.

We do currently have support for (b). added by Alan IIRC. It has the advantage that it's more visible to the user, since they can see the defines in the project options.
Comment 4 Jeffrey Stedfast 2012-10-15 18:36:06 UTC

*** This bug has been marked as a duplicate of bug 5054 ***
Comment 5 Jeffrey Stedfast 2013-03-15 18:46:35 UTC
I committed a patch to the IPhone's project build logic to modify the (cloned) Configuration by adding __MOBILE__ and __iOS__ just before it gets passed off to the Compile step, if they aren't already defined (so that we can always add them to the project configuration later, if we decide we'd rather do that).
Comment 6 Mikayla Hutchinson [MSFT] 2013-03-16 01:24:14 UTC
The basic approach looks good but the patch is bad. It will cause an invalid cast for all other project types.
Comment 7 Mikayla Hutchinson [MSFT] 2013-03-16 10:45:16 UTC
FTFY.
Comment 8 Jatin 2013-03-25 08:11:05 UTC
We have verified this issue with the latest builds:

XS 4.0.3.13
MT 6.2.1.201
MFA 4.6.01081
Mono 2.10.12
MTVS 1.1.194
VS 2012/2010

And now under the option C#, Android is appearing for the Android templates and iOS is appearing for the iOS templates.

Hence, closing this issue.
Comment 9 Mikayla Hutchinson [MSFT] 2013-03-25 16:42:40 UTC
I think there is some confusion about verifying this. This is not about templates. It's about the __MOBILE__ and __IOS__ defines being passed to the compiler. You can verify this by checking that this code is executed successfully in an iOS project:


#if __MOBILE__
    Console.WriteLine ("__MOBILE__ is defined");
#endif 

#if __IOS__
    Console.WriteLine ("__IOS__ is defined");
#endif