Conditional compilation using MACOSX_DEPLOYMENT_TARGET in Xcode for a Cocoa app
Asked Answered
A

1

7

In a Cocoa application, I'd like to use conditional compilation, like:

#if MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4    
    [[NSFileManager defaultManager] removeFileAtPath:path handler:nil];
#else
    [[NSFileManager defaultManager] removeItemAtPath:path error:NULL];
#endif

My hope is that this will avoid compiler warnings about removeFileAtPath: being deprecated when MACOSX_DEPLOYMENT_TARGET = 10.6, since it shouldn't be compiling that line.

It doesn't work.

When MACOSX_DEPLOYMENT_TARGET = 10.6 I get a warning that removeFileAtPath: is deprecated. But it shouldn't be compiling that line, so it shouldn't be warning about it having a deprecated method!

(I am setting MACOSX_DEPLOYMENT_TARGET in both the project build settings and the target build settings. I have BASE_SDK set to 10.6 and specify GCC 4.2 in both, too.)

What am I doing wrong? Do I have some fundamental misunderstanding of conditional compilation?

Abiogenesis answered 6/12, 2010 at 15:33 Comment(0)
S
11

MACOSX_DEPLOYMENT_TARGET is mostly used to perform a weak-linking. You should use MAC_OS_X_VERSION_MIN_REQUIRED instead to perform conditional compilation:

#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
    [[NSFileManager defaultManager] removeFileAtPath:path handler:nil];
#else
    [[NSFileManager defaultManager] removeItemAtPath:path error:NULL];
#endif

See Ensuring Backwards Binary Compatibility - Weak Linking and Availability Macros on Mac OS X from Apple for more examples.

Stein answered 6/12, 2010 at 15:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.