Re: Finding os version at compile time and os version at runtime?
Re: Finding os version at compile time and os version at runtime?
- Subject: Re: Finding os version at compile time and os version at runtime?
- From: John Engelhart <email@hidden>
- Date: Sat, 15 Dec 2007 21:48:57 -0500
On Dec 15, 2007, at 8:06 PM, Jerry LeVan wrote:
Hi,
I have an app I am trying to maintain with one set of sources.
The app uses the quartz filter manager and some leopard pdfkit
stuff that is not available in the 10.4 universal sdk.
I would like to be able to detect the target os version at
compile time so I can prevent the 10.5 stuff from compiling
when I am building a universal version. ( It is all in
a single subroutine).
I also need to be able to detect at runtime if the app
is running a version < 10.5 so I can disable the menu
that invokes the 10.5 code.
Is there a standard way for doing both of these tasks?
I've had to deal with this a bit myself. You can see the results in
my open source project at http://regexkit.sourceforge.net/
Specifically, you'll want to examine the file that's in 'Source/Build/
Xcode/RegexKit Build Settings.xcconfig', which I use to keep a lot of
the projects Xcode tunables where they can be commented, instead of
inside the .xcodeproj project. I source the .xcconfig file at the
project level by setting the Project > Edit Project Settings > Build
(tab) > Based On (drop down menu, lower right).
Here's a few examples. You can create the exact equivalents inside
Xcode's Project > Edit (Project | Target | Executable) Settings.
// The SDK for the current Mac OS X release
SDKROOT_1040 = /Developer/SDKs/MacOSX10.4u.sdk
SDKROOT_1050 = /Developer/SDKs/MacOSX10.5.sdk
SDKROOT = ${SDKROOT_${MAC_OS_X_VERSION_MAJOR}}
// Compiler flags dependent on the current Mac OS X release
XCODE_CFLAGS_1040 =
XCODE_CFLAGS_1050 = -fstack-protector-all
XCODE_CFLAGS_FOR_OS = ${XCODE_CFLAGS_$
{MAC_OS_X_VERSION_MAJOR}}
OTHER_CFLAGS = ${XCODE_CFLAGS_FOR_OS}
// The architectures we build for for the current Mac OS X release
ARCHS_1040 = ppc i386
ARCHS_1050 = ppc ppc64 i386 x86_64
ARCHS = ${ARCHS_${MAC_OS_X_VERSION_MAJOR}}
// Xcode 3.0 will apply per architecture settings for _ARCH build
settings
MACOSX_DEPLOYMENT_TARGET_ppc = 10.4
MACOSX_DEPLOYMENT_TARGET_i386 = 10.4
MACOSX_DEPLOYMENT_TARGET_ppc64 = 10.5
MACOSX_DEPLOYMENT_TARGET_x86_64 = 10.5
As to the detection of 10.4 and 10.5 functionality at run time with
code, that can be a bit trickier depending on what you're attempting
to do. And there's a lot of different ways to accomplish it. I would
suggest taking a look at:
http://developer.apple.com/documentation/DeveloperTools/Conceptual/DynamicLibraries/Introduction.html
http://developer.apple.com/documentation/DeveloperTools/Conceptual/DynamicLibraries/Articles/DynamicLibraryUsageGuidelines.html#/
/apple_ref/doc/uid/TP40001928-SW13 (Using Weakly Linked Symbols)
With Objective-C, there's some additional possibilities. You can ask
the runtime system to check if a class exists, or if an object
responds to a selector. As an example:
if([objc_getClass("NSGarbageCollector") defaultCollector] !=
NULL) { /* NSGarbageCollector exists, and Garbage Collection is
active. */ }
if([NSThread respondsToSelector(@selector(mainThread))]) { /*
NSThread responds to the new 10.5 mainThread method. */ }
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden