From 1f5e5dd1a4d11baf053a3eae9a5adb2c63d4863c Mon Sep 17 00:00:00 2001 From: Amy W Date: Mon, 14 Mar 2022 16:39:42 -0700 Subject: [PATCH] Fix build for all versions --- serial.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/serial.c b/serial.c index 84d7e8a..3f686b8 100644 --- a/serial.c +++ b/serial.c @@ -440,8 +440,27 @@ static char *find_path(int vid, int pid) } io_iterator_t devices = IO_OBJECT_NULL; - kern_return_t ret = IOServiceGetMatchingServices(kIOMainPortDefault, - dict, &devices); + + kern_return_t ret; + + /* MacOS 12.0 deprecates kIOMasterPortDefault for kIOMainPortDefault + * and build breaks on a deprecation warning. + * Use the clang __builtin_available thing to guard the new version + * and change that warning to non-error to prevent breakage. + */ + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdeprecated-declarations" + + if (__builtin_available(macOS 12.0, *)) { + ret = IOServiceGetMatchingServices(kIOMainPortDefault, + dict, &devices); + } else { + ret = IOServiceGetMatchingServices(kIOMasterPortDefault, + dict, &devices); + } + + #pragma clang diagnostic pop + if (ret != KERN_SUCCESS) { printf("Cannot find matching IO services.\n"); return 0;