From 430da1578db93cda9a1fead53137a86c855a968b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 9 Oct 2023 10:43:58 +0800 Subject: [PATCH] Libc (macOS): detect `libSystem` version --- CMakeLists.txt | 9 ++++++++- src/detection/libc/libc_apple.c | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/detection/libc/libc_apple.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d672362a..94cbd5ae5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -546,7 +546,7 @@ elseif(APPLE) src/detection/host/host_apple.c src/detection/lm/lm_nosupport.c src/detection/icons/icons_nosupport.c - src/detection/libc/libc_nosupport.c + src/detection/libc/libc_apple.c src/detection/localip/localip_linux.c src/detection/gamepad/gamepad_apple.c src/detection/media/media_apple.m @@ -670,6 +670,13 @@ if(LINUX AND EXISTS "/lib/ld-musl-${CMAKE_HOST_SYSTEM_PROCESSOR}.so.1") target_compile_definitions(libfastfetch PUBLIC FF_MUSL_VERSION="${CMAKE_MATCH_1}") endif() endif() +if(APPLE AND EXISTS "/usr/bin/otool") + execute_process(COMMAND /usr/bin/otool -L /usr/bin/otool + OUTPUT_VARIABLE OTOOL_OTOOL_RESULT) + if("${OTOOL_OTOOL_RESULT}" MATCHES "libSystem\\.B\\.dylib \\(.*current version ([0-9]+\\.[0-9]+\\.[0-9]+)\\)") + target_compile_definitions(libfastfetch PUBLIC FF_LIBSYSTEM_VERSION="${CMAKE_MATCH_1}") + endif() +endif() target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__=1) if(WIN32) diff --git a/src/detection/libc/libc_apple.c b/src/detection/libc/libc_apple.c new file mode 100644 index 000000000..dbaa20d91 --- /dev/null +++ b/src/detection/libc/libc_apple.c @@ -0,0 +1,13 @@ +#include "libc.h" + +const char* ffDetectLibc(FFLibcResult* result) +{ + result->name = "libSystem"; + +#ifdef FF_LIBSYSTEM_VERSION + result->version = FF_LIBSYSTEM_VERSION; +#else + result->version = NULL; +#endif + return NULL; +}