Skip to content

Commit 834ad8f

Browse files
committed
Apple: Add QT_APPLE_SDK_EQUAL_OR_ABOVE for explicit SDK checks
QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE and its per-platform wrappers take a fixed, positional argument list, so a call has to fill the platforms it doesn't care about with __MAC_NA and friends, and the reader has to remember which slot is which. We were also missing handling for visionOS. QT_APPLE_SDK_EQUAL_OR_ABOVE names each platform explicitly and takes them in any order, listing only the ones that matter: #if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(26), IOS(17, 2), VISIONOS(2)) The version is given in one to three parts, e.g. IOS(17), IOS(17, 2) or IOS(17, 2, 1), and expanded to the encoding the __..._VERSION_MAX_ALLOWED macros already use. The platform headers take care of defining __..._VERSION_MAX_ALLOWED appropriately per platform, so we don't need additional Q_OS_... guards. In fact adding these would prevent IOS(17) from being true on visionOS, which does inherit its API surface from iOS 17. The in-tree callers are moved over, and the old QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE base macro is deprecated. That also covers the per-platform wrappers, since they expand through it. Pick-to: 6.12 Change-Id: Ie71f58b314e45de949716216c4f1e814cc4e4847 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
1 parent 2dbde10 commit 834ad8f

10 files changed

Lines changed: 58 additions & 10 deletions

File tree

src/corelib/global/qsystemdetection.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
#ifdef Q_OS_DARWIN
183183
# include <Availability.h>
184184
# include <AvailabilityMacros.h>
185+
# include <QtCore/qtpreprocessorsupport.h>
185186

186187
# define QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios, tvos, watchos) \
187188
((defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && macos != __MAC_NA && __MAC_OS_X_VERSION_MAX_ALLOWED >= macos) || \
@@ -206,6 +207,8 @@
206207
# define QT_WATCHOS_PLATFORM_SDK_EQUAL_OR_ABOVE(watchos) \
207208
QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_NA, __IPHONE_NA, __TVOS_NA, watchos)
208209

210+
# pragma clang deprecated(QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE, "Use QT_APPLE_SDK_EQUAL_OR_ABOVE instead")
211+
209212
# define QT_MACOS_IOS_DEPLOYMENT_TARGET_BELOW(macos, ios) \
210213
QT_DARWIN_DEPLOYMENT_TARGET_BELOW(macos, ios, __TVOS_NA, __WATCHOS_NA)
211214
# define QT_MACOS_DEPLOYMENT_TARGET_BELOW(macos) \
@@ -219,6 +222,50 @@
219222

220223
# pragma clang deprecated(QT_DARWIN_DEPLOYMENT_TARGET_BELOW, "Use @available instead")
221224

225+
/*!
226+
\macro QT_APPLE_SDK_EQUAL_OR_ABOVE
227+
\internal
228+
229+
Generalized Apple platform SDK check, for code requiring
230+
a minimum version of build SDK, e.g.:
231+
232+
#if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(26, 6, 1), IOS(17, 2), VISIONOS(2))
233+
234+
For runtime version checks, use @available
235+
*/
236+
237+
# define QT_APPLE_SDK_VERSION(...) QT_APPLE_SDK_VERSION_IMPL(__VA_ARGS__, 0, 0)
238+
# define QT_APPLE_SDK_VERSION_IMPL(major, minor, patch, ...) \
239+
((major) * 10000 + (minor) * 100 + (patch))
240+
241+
# define QT_APPLE_SDK_PLATFORM_MACOS(...) \
242+
(__MAC_OS_X_VERSION_MAX_ALLOWED >= QT_APPLE_SDK_VERSION(__VA_ARGS__))
243+
# define QT_APPLE_SDK_PLATFORM_IOS(...) \
244+
(__IPHONE_OS_VERSION_MAX_ALLOWED >= QT_APPLE_SDK_VERSION(__VA_ARGS__))
245+
# define QT_APPLE_SDK_PLATFORM_TVOS(...) \
246+
(__TV_OS_VERSION_MAX_ALLOWED >= QT_APPLE_SDK_VERSION(__VA_ARGS__))
247+
# define QT_APPLE_SDK_PLATFORM_WATCHOS(...) \
248+
(__WATCH_OS_VERSION_MAX_ALLOWED >= QT_APPLE_SDK_VERSION(__VA_ARGS__))
249+
# define QT_APPLE_SDK_PLATFORM_VISIONOS(...) \
250+
(__VISION_OS_VERSION_MAX_ALLOWED >= QT_APPLE_SDK_VERSION(__VA_ARGS__))
251+
252+
# define QT_APPLE_SDK_EQUAL_OR_ABOVE_1(p1) \
253+
(QT_APPLE_SDK_PLATFORM_##p1)
254+
# define QT_APPLE_SDK_EQUAL_OR_ABOVE_2(p1, p2) \
255+
(QT_APPLE_SDK_PLATFORM_##p1 || QT_APPLE_SDK_PLATFORM_##p2)
256+
# define QT_APPLE_SDK_EQUAL_OR_ABOVE_3(p1, p2, p3) \
257+
(QT_APPLE_SDK_PLATFORM_##p1 || QT_APPLE_SDK_PLATFORM_##p2 \
258+
|| QT_APPLE_SDK_PLATFORM_##p3)
259+
# define QT_APPLE_SDK_EQUAL_OR_ABOVE_4(p1, p2, p3, p4) \
260+
(QT_APPLE_SDK_PLATFORM_##p1 || QT_APPLE_SDK_PLATFORM_##p2 \
261+
|| QT_APPLE_SDK_PLATFORM_##p3 || QT_APPLE_SDK_PLATFORM_##p4)
262+
# define QT_APPLE_SDK_EQUAL_OR_ABOVE_5(p1, p2, p3, p4, p5) \
263+
(QT_APPLE_SDK_PLATFORM_##p1 || QT_APPLE_SDK_PLATFORM_##p2 \
264+
|| QT_APPLE_SDK_PLATFORM_##p3 || QT_APPLE_SDK_PLATFORM_##p4 \
265+
|| QT_APPLE_SDK_PLATFORM_##p5)
266+
267+
# define QT_APPLE_SDK_EQUAL_OR_ABOVE(...) QT_OVERLOADED_MACRO(QT_APPLE_SDK_EQUAL_OR_ABOVE, __VA_ARGS__)
268+
222269
#else // !Q_OS_DARWIN
223270

224271
#define QT_DARWIN_PLATFORM_SDK_EQUAL_OR_ABOVE(macos, ios, tvos, watchos) (0)
@@ -227,6 +274,7 @@
227274
#define QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(ios) (0)
228275
#define QT_TVOS_PLATFORM_SDK_EQUAL_OR_ABOVE(tvos) (0)
229276
#define QT_WATCHOS_PLATFORM_SDK_EQUAL_OR_ABOVE(watchos) (0)
277+
#define QT_APPLE_SDK_EQUAL_OR_ABOVE(...) (0)
230278

231279
#endif // Q_OS_DARWIN
232280

src/corelib/platform/darwin/qdarwinpermissionplugin_contacts.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ @implementation QDarwinContactsPermissionHandler
2121
const auto status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
2222
switch (status) {
2323
case CNAuthorizationStatusAuthorized:
24-
#if (defined(Q_OS_IOS) && QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(180000)) || defined(Q_OS_VISIONOS)
24+
#if (defined(Q_OS_IOS) && QT_APPLE_SDK_EQUAL_OR_ABOVE(IOS(18))) || defined(Q_OS_VISIONOS)
2525
case CNAuthorizationStatusLimited:
2626
#endif
2727
return Qt::PermissionStatus::Granted;

src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ - (NSInteger) accessibilityInsertionPointLineNumber {
836836
- (NSArray *)accessibilityAttributeNames {
837837
NSMutableArray *attributes = [[NSMutableArray new] autorelease];
838838

839-
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(260000)
839+
#if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(26))
840840
if (@available(macOS 26, *))
841841
[attributes addObject:NSAccessibilityLanguageAttribute];
842842
#endif
@@ -855,7 +855,7 @@ - (id)accessibilityAttributeValue:(NSString *)attribute {
855855
return nil;
856856
}
857857

858-
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(260000)
858+
#if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(26))
859859
if (@available(macOS 26, *)) {
860860
if ([attribute isEqualToString:NSAccessibilityLanguageAttribute]) {
861861
QAccessibleAttributesInterface *attributesIface = iface->attributesInterface();

src/plugins/platforms/cocoa/qcocoacursor.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ + (id)_windowResizeEastWestCursor;
155155
case Qt::SizeHorCursor:
156156
case Qt::SizeBDiagCursor:
157157
case Qt::SizeFDiagCursor: {
158-
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(150000)
158+
#if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(15))
159159
if (@available(macOS 15, *)) {
160160
auto position = [newShape]{
161161
switch (newShape) {

src/plugins/platforms/cocoa/qnsview.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ @interface QNSView (ComplexText) <NSTextInputClient>
8686
@interface QNSView (ServicesMenu) <NSServicesMenuRequestor>
8787
@end
8888

89-
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(150000)
89+
#if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(15))
9090
@interface QNSView (ContentSelectionInfo) <NSViewContentSelectionInfo>
9191
@end
9292
#endif

src/plugins/platforms/cocoa/qnsview_complextext.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ - (QString)utiForPasteboardType:(NSPasteboardType)pasteboardType
794794

795795
@end
796796

797-
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(150000)
797+
#if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(15))
798798
@implementation QNSView (ContentSelectionInfo)
799799

800800
/*

src/plugins/platforms/cocoa/qnsview_keys.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ - (void)flagsChanged:(NSEvent *)nsevent
254254
}
255255
}
256256

257-
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(150000)
257+
#if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(15))
258258
- (void)contextMenuKeyDown:(NSEvent *)nsevent
259259
{
260260
qCDebug(lcQpaKeys) << "Handling context menu key down for" << nsevent;

src/plugins/platforms/cocoa/qnsview_menus.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ - (id)supplementalTargetForAction:(SEL)action sender:(id)sender
4040
return [super supplementalTargetForAction:action sender:sender];
4141
}
4242

43-
#if QT_MACOS_PLATFORM_SDK_EQUAL_OR_ABOVE(150000)
43+
#if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(15))
4444
- (void)showContextMenuForSelection:(id)sender
4545
{
4646
QPointF windowPoint;

src/plugins/tls/securetransport/qtls_st.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ bool TlsCryptographSecureTransport::setSessionCertificate(QString &errorDescript
820820
const void *values[2] = { password };
821821
CFIndex nKeys = 1;
822822
#ifdef Q_OS_MACOS
823-
#if QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(150000, 180000)
823+
#if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(15), IOS(18))
824824
// Starting from macOS 15 our temporary keychain is ignored.
825825
// We have to use kSecImportToMemoryOnly/kCFBooleanTrue key/value
826826
// instead. This key is "memory" but looks like Security framework

src/testlib/qtesthelpers_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ inline bool isSecureTransportBlockingTest()
142142
#ifdef Q_OS_MACOS
143143
#if QT_CONFIG(ssl)
144144
if (QSslSocket::activeBackend() == QLatin1String("securetransport")) {
145-
#if QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(150000, 180000)
145+
#if QT_APPLE_SDK_EQUAL_OR_ABOVE(MACOS(15), IOS(18))
146146
// Starting from macOS 15 our temporary keychain is ignored.
147147
// We have to use kSecImportToMemoryOnly/kCFBooleanTrue key/value
148148
// instead. This way we don't have to use QT_SSL_USE_TEMPORARY_KEYCHAIN anymore.

0 commit comments

Comments
 (0)