From e5322cf165c00a00235f1063260d1828d4004597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 19 Oct 2021 05:16:24 +0000 Subject: [PATCH] Make it possible to build without optional dependencies --- CMakeLists.txt | 56 ++++++++++++++++++++++++++++------------ src/common/settings.c | 30 ++++++++++++++++++--- src/modules/resolution.c | 29 ++++++++++++++++++--- 3 files changed, 93 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 189ae8167..ce9551d2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,31 +43,55 @@ configure_file(src/fastfetch_config.h.in fastfetch_config.h) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) -find_package (PkgConfig) +find_package(PkgConfig REQUIRED) -if(${PkgConfig_FOUND}) - pkg_check_modules (GIO2 gio-2.0) - pkg_check_modules (DCONF dconf) -endif(${PkgConfig_FOUND}) +pkg_check_modules (GIO2 gio-2.0) +if(GIO2_FOUND) + add_compile_definitions(FF_HAS_GIO2=1) +endif() -if(NOT DEFINED GIO2_INCLUDE_DIRS) - set(GIO2_INCLUDE_DIRS - /usr/include/glib-2.0/ - /usr/lib/glib-2.0/include/ - ) -endif(NOT DEFINED GIO2_INCLUDE_DIRS) +pkg_check_modules (DCONF dconf) +if(DCONF_FOUND) + add_compile_definitions(FF_HAS_DCONF=1) +endif() -if(NOT DEFINED DCONF_INCLUDE_DIRS) - set(DCONF_INCLUDE_DIRS - /usr/include/dconf/ - ) -endif(NOT DEFINED DCONF_INCLUDE_DIRS) +pkg_check_modules (XFCONF xfconf) +if(XFCONF_FOUND) + add_compile_definitions(FF_HAS_XFCONF=1) +endif() + +pkg_check_modules (XRANDR xrandr) +if(XRANDR_FOUND) + add_compile_definitions(FF_HAS_XRANDR=1) +endif() + +pkg_check_modules (X11 x11) +if(X11_FOUND) + add_compile_definitions(FF_HAS_X11=1) +endif() + +pkg_check_modules (WAYLAND wayland-client) +if(WAYLAND_FOUND) + add_compile_definitions(FF_HAS_WAYLAND=1) +endif() + +pkg_check_modules (SQLITE3 sqlite3) +if(SQLITE3_FOUND) + add_compile_definitions(FF_HAS_SQLITE3=1) +endif() + +pkg_check_modules (LIBPCI REQUIRED libpci) include_directories( ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/src ${GIO2_INCLUDE_DIRS} ${DCONF_INCLUDE_DIRS} + ${XRANDR_INCLUDE_DIRS} + ${X11_INCLUDE_DIRS} + ${WAYLAND_INCLUDE_DIRS} + ${SQLITE3_INCLUDE_DIRS} + ${LIBPCI_INCLUDE_DIRS} ) link_libraries( diff --git a/src/common/settings.c b/src/common/settings.c index 9b646fccc..12122b93b 100644 --- a/src/common/settings.c +++ b/src/common/settings.c @@ -2,8 +2,12 @@ #include #include -#include // Also included gio/gio.h -#include +#if FF_HAS_DCONF +# include // Also included gio/gio.h +#endif +#if FF_HAS_SQLITE3 +# include +#endif typedef void* DynamicLibrary; @@ -25,6 +29,7 @@ typedef void* DynamicLibrary; if(dlerror() != NULL) \ FF_LIBRARY_ERROR_RETURN(library, mutex, returnValue) +#if FF_HAS_DCONF typedef struct GVariantGetters { const gchar*(*ffg_variant_get_string)(GVariant*, gsize*); @@ -261,9 +266,23 @@ FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, con pthread_mutex_unlock(&mutex); return getXFConfValue(&data, channelName, propertyName, type); } - +#else +FFvariant ffSettingsGet(FFinstance*, const char*, const char*, const char*, const char*, FFvarianttype) { + return FF_VARIANT_NULL; +} +FFvariant ffSettingsGetDConf(FFinstance*, const char*, FFvarianttype) { + return FF_VARIANT_NULL; +} +FFvariant ffSettingsGetXFConf(FFinstance*, const char*, const char*, FFvarianttype) { + return FF_VARIANT_NULL; +} +FFvariant ffSettingsGetGSettings(FFinstance*, const char*, const char*, const char*, FFvarianttype) { + return FF_VARIANT_NULL; +} +#endif // FF_HAS_DCONF #undef FF_VARIANT_NULL +#if FF_HAS_SQLITE3 typedef struct SQLiteData { int(*ffsqlite3_open_v2)(const char* filename, sqlite3** ppDb, int flags, const char* zVfs); @@ -355,3 +374,8 @@ uint32_t ffSettingsGetSQLiteColumnCount(FFinstance* instance, const char* fileNa pthread_mutex_unlock(&mutex); return getSQLiteColumnCount(&data, fileName, tableName); } +#else +uint32_t ffSettingsGetSQLiteColumnCount(FFinstance*, const char*, const char*) { + return 0; +} +#endif // FF_HAS_SQLITE3 diff --git a/src/modules/resolution.c b/src/modules/resolution.c index 2add70394..2857c2573 100644 --- a/src/modules/resolution.c +++ b/src/modules/resolution.c @@ -4,8 +4,16 @@ #include #include #include -#include -#include + +#if FF_HAS_X11 +# include +#endif +#if FF_HAS_XRANDR +# include +#endif +#if FF_HAS_WAYLAND +# include +#endif #define FF_RESOLUTION_MODULE_NAME "Resolution" #define FF_RESOLUTION_NUM_FORMAT_ARGS 3 @@ -61,6 +69,7 @@ static bool printResolutionResultList(FFinstance* instance, FFlist* results) return res; } +#if FF_HAS_XRANDR || FF_HAS_WAYLAND static int parseRefreshRate(int32_t refreshRate) { if(refreshRate <= 0) @@ -78,6 +87,7 @@ static int parseRefreshRate(int32_t refreshRate) return refreshRate; } +#endif // FF_HAS_XRANDR || FF_HAS_WAYLAND static void printResolutionDRMBackend(FFinstance* instance) { @@ -139,6 +149,7 @@ static void printResolutionDRMBackend(FFinstance* instance) printResolutionResultList(instance, &modes); } +#if FF_HAS_X11 static void x11AddScreenAsResult(FFlist* results, Screen* screen, int refreshRate) { if(WidthOfScreen(screen) == 0 || HeightOfScreen(screen) == 0) @@ -175,7 +186,9 @@ static bool printResolutionX11Backend(FFinstance* instance) return printResolutionResultList(instance, &results); } +#endif // FF_HAS_XLIB +#if FF_HAS_XRANDR typedef struct XrandrData { XRRScreenConfiguration*(*ffXRRGetScreenInfo)(Display* display, Window window); @@ -357,7 +370,9 @@ static bool printResolutionXrandrBackend(FFinstance* instance) return printResolutionResultList(instance, &data.results); } +#endif // FF_HAS_XRANDR +#if FF_HAS_WAYLAND typedef struct WaylandData { FFinstance* instance; @@ -502,13 +517,21 @@ static bool printResolutionWaylandBackend(FFinstance* instance) return printResolutionResultList(instance, &data.results); } +#endif // FF_HAS_WAYLAND void ffPrintResolution(FFinstance* instance) { if( +#if FF_HAS_WAYLAND printResolutionWaylandBackend(instance) || +#endif +#if FF_HAS_XRANDR printResolutionXrandrBackend(instance) || - printResolutionX11Backend(instance) +#endif +#if FF_HAS_X11 + printResolutionX11Backend(instance) || +#endif + false ) return; printResolutionDRMBackend(instance);