From fa46dce0e1ffb355a36cd3f74c0308180f02650d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 8 Oct 2023 21:03:10 +0800 Subject: [PATCH] CMake: detect uclibc and musl version --- CMakeLists.txt | 9 +++++++++ src/detection/libc/libc_linux.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b2b55146..c23bd15e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -663,6 +663,15 @@ if(yyjson_FOUND) target_link_libraries(libfastfetch PRIVATE yyjson) endif() +if(LINUX AND EXISTS "/lib/ld-musl-x86_64.so.1") + execute_process(COMMAND "/lib/ld-musl-x86_64.so.1" + ERROR_VARIABLE LD_MUSL_VERSION) + string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" LD_MUSL_VERSION "${LD_MUSL_VERSION}") + if(NOT LD_MUSL_VERSION STREQUAL "") + target_compile_definitions(libfastfetch PUBLIC FF_MUSL_VERSION="${LD_MUSL_VERSION}") + endif() +endif() + target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__=1) if(WIN32) target_compile_definitions(libfastfetch PUBLIC WIN32_LEAN_AND_MEAN=1) diff --git a/src/detection/libc/libc_linux.c b/src/detection/libc/libc_linux.c index 399a67870..19e8e8328 100644 --- a/src/detection/libc/libc_linux.c +++ b/src/detection/libc/libc_linux.c @@ -7,12 +7,19 @@ const char* ffDetectLibc(FFLibcResult* result) { -#ifdef __GNU_LIBRARY__ +#ifdef __UCLIBC__ + result->name = "uClibc"; + result->version = FF_STR(__UCLIBC_MAJOR__) "." FF_STR(__UCLIBC_MINOR__) "." FF_STR(__UCLIBC_SUBLEVEL__); +#elif defined(__GNU_LIBRARY__) result->name = "glibc"; result->version = FF_STR(__GLIBC__) "." FF_STR(__GLIBC_MINOR__); #else result->name = "musl"; - result->version = NULL; + #ifdef FF_MUSL_VERSION + result->version = FF_MUSL_VERSION; + #else + result->version = NULL; + #endif #endif return NULL;