Skip to content

Commit 99e0dc9

Browse files
committed
Zpool: don't break -DBINARY_LINK_TYPE=dynamic
Fix #1233
1 parent 73e9db5 commit 99e0dc9

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF)
7171
cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF)
7272
cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR FreeBSD OR ANDROID" OFF)
7373
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF)
74+
cmake_dependent_option(ENABLE_LIBZFS "Enable libzfs" ON "LINUX OR FreeBSD OR SunOS" OFF)
7475

7576
option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF)
7677
option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF)
@@ -1098,6 +1099,25 @@ ff_lib_enable(DIRECTX_HEADERS
10981099
"DirectX-Headers"
10991100
"DirectX-Headers"
11001101
)
1102+
# The system <libzfs.h> is only usable on SunOS. We provide our local copy of it so it's always available.
1103+
if(ENABLE_LIBZFS)
1104+
if(BINARY_LINK_TYPE STREQUAL "dlopen")
1105+
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_LIBZFS=1)
1106+
else()
1107+
set(CMAKE_REQUIRED_LIBRARIES_BACKUP ${CMAKE_REQUIRED_LIBRARIES})
1108+
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} zfs)
1109+
check_function_exists("libzfs_init" LIBZFS_FOUND)
1110+
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_BACKUP})
1111+
if(NOT LIBZFS_FOUND)
1112+
message(STATUS "Library: missing: LIBZFS")
1113+
else()
1114+
message(STATUS "Library: found LIBZFS")
1115+
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_LIBZFS=1)
1116+
target_link_libraries(libfastfetch PRIVATE zfs)
1117+
endif()
1118+
endif()
1119+
endif()
1120+
11011121

11021122
if(ENABLE_THREADS)
11031123
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_THREADS)

src/common/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ void ffListFeatures(void)
247247
#if FF_HAVE_ELF
248248
"libelf\n"
249249
#endif
250+
#if FF_HAVE_LIBZFS
251+
"libzfs\n"
252+
#endif
250253
#if FF_HAVE_DIRECTX_HEADERS
251254
"Directx Headers\n"
252255
#endif

src/detection/zpool/zpool_linux.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "zpool.h"
22

3+
#ifdef FF_HAVE_LIBZFS
4+
35
#ifdef __sun
46
#define FF_DISABLE_DLOPEN
57
#include <libzfs.h>
@@ -98,3 +100,12 @@ const char* ffDetectZpool(FFlist* result /* list of FFZpoolResult */)
98100

99101
return NULL;
100102
}
103+
104+
#else
105+
106+
const char* ffDetectZpool(FF_MAYBE_UNUSED FFlist* result)
107+
{
108+
return "Fastfetch was compiled without libzfs support";
109+
}
110+
111+
#endif

0 commit comments

Comments
 (0)