From 99e0dc9aaa9ecf3645c086258149058beb1442af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 31 Aug 2024 12:34:36 +0800 Subject: [PATCH] Zpool: don't break `-DBINARY_LINK_TYPE=dynamic` Fix #1233 --- CMakeLists.txt | 20 ++++++++++++++++++++ src/common/init.c | 3 +++ src/detection/zpool/zpool_linux.c | 11 +++++++++++ 3 files changed, 34 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 615a992c6..8b60ddaf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF) cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF) cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR FreeBSD OR ANDROID" OFF) cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF) +cmake_dependent_option(ENABLE_LIBZFS "Enable libzfs" ON "LINUX OR FreeBSD OR SunOS" OFF) option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF) option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF) @@ -1098,6 +1099,25 @@ ff_lib_enable(DIRECTX_HEADERS "DirectX-Headers" "DirectX-Headers" ) +# The system is only usable on SunOS. We provide our local copy of it so it's always available. +if(ENABLE_LIBZFS) + if(BINARY_LINK_TYPE STREQUAL "dlopen") + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_LIBZFS=1) + else() + set(CMAKE_REQUIRED_LIBRARIES_BACKUP ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} zfs) + check_function_exists("libzfs_init" LIBZFS_FOUND) + set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_BACKUP}) + if(NOT LIBZFS_FOUND) + message(STATUS "Library: missing: LIBZFS") + else() + message(STATUS "Library: found LIBZFS") + target_compile_definitions(libfastfetch PRIVATE FF_HAVE_LIBZFS=1) + target_link_libraries(libfastfetch PRIVATE zfs) + endif() + endif() +endif() + if(ENABLE_THREADS) target_compile_definitions(libfastfetch PRIVATE FF_HAVE_THREADS) diff --git a/src/common/init.c b/src/common/init.c index 2da9f3027..ba569c829 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -247,6 +247,9 @@ void ffListFeatures(void) #if FF_HAVE_ELF "libelf\n" #endif + #if FF_HAVE_LIBZFS + "libzfs\n" + #endif #if FF_HAVE_DIRECTX_HEADERS "Directx Headers\n" #endif diff --git a/src/detection/zpool/zpool_linux.c b/src/detection/zpool/zpool_linux.c index ae937d9c0..e62febbd0 100644 --- a/src/detection/zpool/zpool_linux.c +++ b/src/detection/zpool/zpool_linux.c @@ -1,5 +1,7 @@ #include "zpool.h" +#ifdef FF_HAVE_LIBZFS + #ifdef __sun #define FF_DISABLE_DLOPEN #include @@ -98,3 +100,12 @@ const char* ffDetectZpool(FFlist* result /* list of FFZpoolResult */) return NULL; } + +#else + +const char* ffDetectZpool(FF_MAYBE_UNUSED FFlist* result) +{ + return "Fastfetch was compiled without libzfs support"; +} + +#endif