1

In the vein of Which macro to wrap Mac OS X specific code in C/C++.

What macro to use to identify when compiling on OSX 10.9 specifically. As opposed to other versions of OSX like 10.8, Snow Lion, Lion, Leopard, Leotard, Puma (made that one up), or Harrison Ford.

  • __APPLE__ only gives a boolean, and isn't enough information about this.
  • __APPLE_CC__ gives a version number of sorts, but that seems to be about the compiler and no the general OS.
Community
  • 1
  • 1
DragonFax
  • 4,625
  • 2
  • 32
  • 35
  • Consider a static const global variable instead of a macro, haven't done much OS X development, but there is a C function somewhere to get the current OS X version. Here is a related question, in Objective-C: http://stackoverflow.com/questions/6492038/find-mac-os-x-version-number-in-objective-c – Pacha Dec 10 '13 at 04:14
  • 1
    Obsequious? It's a good word, but it doesn't mean what you think it means (because it can't be used in that context). – Jonathan Leffler Dec 10 '13 at 05:31
  • Do you want to know if you are compiling **on** OS X 10.9 or whether you are compiling **for** OS X 10.9? A compiler can execute on one version of OS X but produce a program designed to run on another version of OS X (at least), and then the program can actually run on a later version of OS X. Do you want to know whether OS X 10.9 is **within** the range of targeted versions (the program may run on 10.9 but may run on other versions too) or whether OS X 10.9 is the **least** of the targeted versions (the program will run on 10.9 or later)? – Eric Postpischil Dec 10 '13 at 14:39
  • This is a great distinction. Thank you. Actually its both. Compiling ON osx and FOR osx (i.e. just for that specific machine). This is a ruby gem that uses rake-compile, but I'm not a package builder (maintainer) for it. I'm just trying to send my patches upstream to help out the more knowledgeable. – DragonFax Dec 10 '13 at 20:49

2 Answers2

3
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_9
 <Put your Mavericks specific code here..>
#else
 <Put all other code here..>
#endif

This works for other versions as well. For other macros relating to OSX versions, see AvailiabilityMacros.h.

Adrian Collado
  • 699
  • 8
  • 20
0

The headers on Mac OS X are littered with macros such as:

__OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
__OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_8,__IPHONE_2_0,__IPHONE_6_0)

You can also find definitions such as:

/usr/include/AvailabilityMacros.h:
#define AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_9    DEPRECATED_ATTRIBUTE

And you can find:

$ grep -A2 -n DEPREC /usr/include/Availability.h
[...]
--
153:    #define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep) \
154-                                __AVAILABILITY_INTERNAL##_iosIntro##_DEP##_iosDep
155:    #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg) \
156-                               __AVAILABILITY_INTERNAL##_iosIntro##_DEP##_iosDep##_MSG(_msg)
157-
--
160:    #define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep) \
161-                                __AVAILABILITY_INTERNAL##_osxIntro##_DEP##_osxDep
162:    #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg) \
163-                               __AVAILABILITY_INTERNAL##_osxIntro##_DEP##_osxDep##_MSG(_msg)
--
167:    #define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep)
168:    #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg)

You can reasonably hope that __MAC_10_9 means Mac OS X 10.9 Mavericks:

/usr/include/AvailabilityMacros.h:
#define MAC_OS_X_VERSION_10_0         1000
#define MAC_OS_X_VERSION_10_1         1010
#define MAC_OS_X_VERSION_10_2         1020
#define MAC_OS_X_VERSION_10_3         1030
#define MAC_OS_X_VERSION_10_4         1040
#define MAC_OS_X_VERSION_10_5         1050
#define MAC_OS_X_VERSION_10_6         1060
#define MAC_OS_X_VERSION_10_7         1070
#define MAC_OS_X_VERSION_10_8         1080
#define MAC_OS_X_VERSION_10_9         1090

/usr/include/Availability.h:
#define __MAC_10_0            1000
#define __MAC_10_1            1010
#define __MAC_10_2            1020
#define __MAC_10_3            1030
#define __MAC_10_4            1040
#define __MAC_10_5            1050
#define __MAC_10_6            1060
#define __MAC_10_7            1070
#define __MAC_10_8            1080
#define __MAC_10_9            1090

None of this directly gives you the current version of Mac OS X, but there are macros are defined in terms of these. Read the comments in the headers for guidance.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278