better support for building without features

This commit is contained in:
Linus Dierheimer
2021-10-19 18:44:59 +02:00
parent 73436824f9
commit 349e5b24fa
7 changed files with 222 additions and 149 deletions
+53 -33
View File
@@ -45,53 +45,73 @@ find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules (GIO2 gio-2.0)
if(GIO2_FOUND)
add_compile_definitions(FF_HAS_GIO2=1)
endif()
pkg_check_modules (DCONF dconf)
if(DCONF_FOUND)
add_compile_definitions(FF_HAS_DCONF=1)
endif()
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 (LIBPCI libpci)
if(LIBPCI_FOUND)
add_compile_definitions(FF_HAVE_LIBPCI=1)
else(LIBPCI_FOUND)
message(WARNING "Package libpci not found. Building without support.")
endif(LIBPCI_FOUND)
pkg_check_modules (X11 x11)
if(X11_FOUND)
add_compile_definitions(FF_HAS_X11=1)
endif()
add_compile_definitions(FF_HAVE_X11=1)
else(X11_FOUND)
message(WARNING "Package x11 not found. Building without support.")
endif(X11_FOUND)
pkg_check_modules (XRANDR xrandr)
if(XRANDR_FOUND)
add_compile_definitions(FF_HAVE_XRANDR=1)
else(XRANDR_FOUND)
message(WARNING "Package xrandr not found. Building without support.")
endif(XRANDR_FOUND)
pkg_check_modules (WAYLAND wayland-client)
if(WAYLAND_FOUND)
add_compile_definitions(FF_HAS_WAYLAND=1)
endif()
add_compile_definitions(FF_HAVE_WAYLAND=1)
else(WAYLAND_FOUND)
message(WARNING "Package wayland-client not found. Building without support.")
endif(WAYLAND_FOUND)
pkg_check_modules (GIO gio-2.0)
if(GIO_FOUND)
add_compile_definitions(FF_HAVE_GIO=1)
else(GIO_FOUND)
message(WARNING "Package gio-2.0 not found. Building without support.")
endif(GIO_FOUND)
pkg_check_modules (DCONF dconf)
if(DCONF_FOUND)
add_compile_definitions(FF_HAVE_DCONF=1)
else(DCONF_FOUND)
message(WARNING "Package dconf not found. Building without support.")
endif(DCONF_FOUND)
pkg_check_modules (XFCONF libxfconf-0)
if(XFCONF_FOUND)
add_compile_definitions(FF_HAVE_XFCONF=1)
else(XFCONF_FOUND)
message(WARNING "Package libxfconf-0 not found. Building without support.")
endif(XFCONF_FOUND)
pkg_check_modules (SQLITE3 sqlite3)
if(SQLITE3_FOUND)
add_compile_definitions(FF_HAS_SQLITE3=1)
endif()
pkg_check_modules (LIBPCI REQUIRED libpci)
add_compile_definitions(FF_HAVE_SQLITE3=1)
else(SQLITE3_FOUND)
message(WARNING "Package sqlite3 not found. Building without support.")
endif(SQLITE3_FOUND)
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}
${X11_INCLUDE_DIRS}
${XRANDR_INCLUDE_DIRS}
${WAYLAND_INCLUDE_DIRS}
${GIO_INCLUDE_DIRS}
${DCONF_INCLUDE_DIRS}
${XFCONF_INCLUDE_DIRS}
${SQLITE3_INCLUDE_DIRS}
)
link_libraries(
+3 -1
View File
@@ -69,7 +69,9 @@ cmake --build . -j$(nproc)
This will produce `build/fastfetch` and `build/flashfetch`, both standalone executables.
Command line completions for bash can be found in [`completions/bash`](completions/bash).
Note that the headers of the libraries listed in [Dependencies](#Dependencies) are needed to build the project.
[pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) is also required for building. It is used to find the header files for the libraries listed in [Dependencies](#Dependencies). If pkg-config fails to find a package, a warning will be printed and fastfetch will be build without support for the features depending on it.
Note that building with a feature enabled, doesn't mean the library must be present to run fastfetch, as they are still loaded dynamically during runtime.
## Packaging
+1
View File
@@ -104,6 +104,7 @@ __fastfetch_completion()
"--print-default-structure"
"--print-available-modules"
"--print-available-presets"
"--list-supported-features"
)
local FF_OPTIONS_HELP=(
+88 -80
View File
@@ -2,12 +2,6 @@
#include <dlfcn.h>
#include <pthread.h>
#if FF_HAS_DCONF
# include <dconf.h> // Also included gio/gio.h
#endif
#if FF_HAS_SQLITE3
# include <sqlite3.h>
#endif
typedef void* DynamicLibrary;
@@ -29,7 +23,9 @@ typedef void* DynamicLibrary;
if(dlerror() != NULL) \
FF_LIBRARY_ERROR_RETURN(library, mutex, returnValue)
#if FF_HAS_DCONF
#ifdef FF_HAVE_GIO
#include <gio/gio.h>
typedef struct GVariantGetters
{
const gchar*(*ffg_variant_get_string)(GVariant*, gsize*);
@@ -56,61 +52,6 @@ static FFvariant getGVariantValue(GVariant* variant, FFvarianttype type, GVarian
return FF_VARIANT_NULL;
}
typedef struct DConfData
{
GVariant*(*ffdconf_client_read_full)(DConfClient*, const gchar*, DConfReadFlags, const GQueue*);
GVariantGetters variantGetters;
DConfClient* client;
} DConfData;
static FFvariant getDConfValue(DConfData* data, const char* key, FFvarianttype type)
{
if(data->client == NULL)
return FF_VARIANT_NULL;
GVariant* variant = data->ffdconf_client_read_full(data->client, key, DCONF_READ_FLAGS_NONE, NULL);
if(variant != NULL)
return getGVariantValue(variant, type, &data->variantGetters);
variant = data->ffdconf_client_read_full(data->client, key, DCONF_READ_USER_VALUE, NULL);
if(variant != NULL)
return getGVariantValue(variant, type, &data->variantGetters);
variant = data->ffdconf_client_read_full(data->client, key, DCONF_READ_DEFAULT_VALUE, NULL);
return getGVariantValue(variant, type, &data->variantGetters);
}
FFvariant ffSettingsGetDConf(FFinstance* instance, const char* key, FFvarianttype type)
{
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static bool init = false;
static DConfData data;
pthread_mutex_lock(&mutex);
if(init)
{
pthread_mutex_unlock(&mutex);
return getDConfValue(&data, key, type);
}
init = true;
data.client = NULL; //error indicator
DynamicLibrary library = FF_LIBRARY_LOAD(instance->config.libDConf, "libdconf.so", mutex, FF_VARIANT_NULL);
data.ffdconf_client_read_full = FF_LIBRARY_LOAD_SYMBOL(library, "dconf_client_read_full", mutex, FF_VARIANT_NULL);
FF_LIBRARY_GVARIANT_GETTERS_INIT(library, data.variantGetters, mutex);
DConfClient*(*ffdconf_client_new)(void) = FF_LIBRARY_LOAD_SYMBOL(library, "dconf_client_new", mutex, FF_VARIANT_NULL);
if((data.client = ffdconf_client_new()) == NULL)
FF_LIBRARY_ERROR_RETURN(library, mutex, FF_VARIANT_NULL);
pthread_mutex_unlock(&mutex);
return getDConfValue(&data, key, type);
}
typedef struct GSettingsData
{
GSettingsSchemaSource* schemaSource;
@@ -187,6 +128,78 @@ FFvariant ffSettingsGetGSettings(FFinstance* instance, const char* schemaName, c
return getGSettingsValue(&data, schemaName, path, key, type);
}
#else //FF_HAVE_GIO
FFvariant ffSettingsGetGSettings(FFinstance* instance, const char* schemaName, const char* path, const char* key, FFvarianttype type)
{
return FF_VARIANT_NULL;
}
#endif //FF_HAVE_GIO
#ifdef FF_HAVE_DCONF
#include <dconf.h>
typedef struct DConfData
{
GVariant*(*ffdconf_client_read_full)(DConfClient*, const gchar*, DConfReadFlags, const GQueue*);
GVariantGetters variantGetters;
DConfClient* client;
} DConfData;
static FFvariant getDConfValue(DConfData* data, const char* key, FFvarianttype type)
{
if(data->client == NULL)
return FF_VARIANT_NULL;
GVariant* variant = data->ffdconf_client_read_full(data->client, key, DCONF_READ_FLAGS_NONE, NULL);
if(variant != NULL)
return getGVariantValue(variant, type, &data->variantGetters);
variant = data->ffdconf_client_read_full(data->client, key, DCONF_READ_USER_VALUE, NULL);
if(variant != NULL)
return getGVariantValue(variant, type, &data->variantGetters);
variant = data->ffdconf_client_read_full(data->client, key, DCONF_READ_DEFAULT_VALUE, NULL);
return getGVariantValue(variant, type, &data->variantGetters);
}
FFvariant ffSettingsGetDConf(FFinstance* instance, const char* key, FFvarianttype type)
{
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static bool init = false;
static DConfData data;
pthread_mutex_lock(&mutex);
if(init)
{
pthread_mutex_unlock(&mutex);
return getDConfValue(&data, key, type);
}
init = true;
data.client = NULL; //error indicator
DynamicLibrary library = FF_LIBRARY_LOAD(instance->config.libDConf, "libdconf.so", mutex, FF_VARIANT_NULL);
data.ffdconf_client_read_full = FF_LIBRARY_LOAD_SYMBOL(library, "dconf_client_read_full", mutex, FF_VARIANT_NULL);
FF_LIBRARY_GVARIANT_GETTERS_INIT(library, data.variantGetters, mutex);
DConfClient*(*ffdconf_client_new)(void) = FF_LIBRARY_LOAD_SYMBOL(library, "dconf_client_new", mutex, FF_VARIANT_NULL);
if((data.client = ffdconf_client_new()) == NULL)
FF_LIBRARY_ERROR_RETURN(library, mutex, FF_VARIANT_NULL);
pthread_mutex_unlock(&mutex);
return getDConfValue(&data, key, type);
}
#else //FF_HAVE_DCONF
FFvariant ffSettingsGetDConf(FFinstance* instance, const char* key, FFvarianttype type)
{
return FF_VARIANT_NULL;
}
#endif //FF_HAVE_DCONF
FFvariant ffSettingsGet(FFinstance* instance, const char* dconfKey, const char* gsettingsSchemaName, const char* gsettingsPath, const char* gsettingsKey, FFvarianttype type)
{
FFvariant gsettings = ffSettingsGetGSettings(instance, gsettingsSchemaName, gsettingsPath, gsettingsKey, type);
@@ -199,7 +212,8 @@ FFvariant ffSettingsGet(FFinstance* instance, const char* dconfKey, const char*
return ffSettingsGetDConf(instance, dconfKey, type);
}
typedef struct _XfconfChannel XfconfChannel; // /usr/include/xfce4/xfconf-0/xfconf/xfconf-channel.h#L39
#ifdef FF_HAVE_XFCONF
#include <xfconf/xfconf.h>
typedef struct XFConfData
{
@@ -266,23 +280,16 @@ 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) {
#else //FF_HAVE_XFCONF
FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, const char* propertyName, FFvarianttype type)
{
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
#endif //FF_HAVE_XFCONF
#ifdef FF_HAVE_SQLITE3
#include <sqlite3.h>
#if FF_HAS_SQLITE3
typedef struct SQLiteData
{
int(*ffsqlite3_open_v2)(const char* filename, sqlite3** ppDb, int flags, const char* zVfs);
@@ -374,8 +381,9 @@ 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*) {
#else //FF_HAVE_SQLITE3
uint32_t ffSettingsGetSQLiteColumnCount(FFinstance* instance, const char* fileName, const char* tableName)
{
return 0;
}
#endif // FF_HAS_SQLITE3
#endif //FF_HAVE_SQLITE3
+38 -1
View File
@@ -43,7 +43,8 @@ static inline void printHelp()
" --print-default-config: prints the default config and exits\n"
" --print-default-structure: prints the default stucture and exits\n"
" --print-available-modules: prints a list of available modules and exits\n"
" --print-available-presets: list presets fastfetch knows about. They can be loaded with --load-config. (+)\n"
" --print-available-presets: list presets fastfetch knows about. They can be loaded with --load-config. (+)\n"
" --list-supported-features: list the supported features fastfetch was compiled with. Mainly for development.\n"
"\n"
"General options:\n"
" --structure <structure>: sets the structure of the fetch. Must be a colon separated list of keys. Use --print-available-modules to show the default\n"
@@ -577,6 +578,37 @@ static inline void listAvailablePresets(FFinstance* instance)
ffStrbufDestroy(&folder);
}
static inline void listSupportedFeatures()
{
fputs(
#ifdef FF_HAVE_LIBPCI
"libpci\n"
#endif
#ifdef FF_HAVE_X11
"x11\n"
#endif
#ifdef FF_HAVE_XRANDR
"xrandr\n"
#endif
#ifdef FF_HAVE_WAYLAND
"wayland\n"
#endif
#ifdef FF_HAVE_GIO
"gio\n"
#endif
#ifdef FF_HAVE_DCONF
"dconf\n"
#endif
#ifdef FF_HAVE_XFCONF
"xfconf\n"
#endif
#ifdef FF_HAVE_SQLITE3
"sqlite3\n"
#endif
""
, stdout);
}
static void parseOption(FFinstance* instance, FFdata* data, const char* key, const char* value);
static void parseConfigFile(FFinstance* instance, FFdata* data, FILE* file)
@@ -751,6 +783,11 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
listAvailablePresets(instance);
exit(0);
}
else if(strcasecmp(key, "--list-supported-features") == 0)
{
listSupportedFeatures();
exit(0);
}
else if(strcasecmp(key, "--spacing") == 0)
{
if(value == NULL)
+14 -2
View File
@@ -1,12 +1,22 @@
#include "fastfetch.h"
#include <string.h>
#include <dlfcn.h>
#include <pci/pci.h>
#define FF_GPU_MODULE_NAME "GPU"
#define FF_GPU_NUM_FORMAT_ARGS 4
#ifndef FF_HAVE_LIBPCI
void ffPrintGPU(FFinstance* instance)
{
ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, "Fastfetch was compiled without libpci support");
}
#else
#include <dlfcn.h>
#include <pci/pci.h>
static void printGPU(FFinstance* instance, struct pci_access* pacc, struct pci_dev* dev, FFcache* cache, uint8_t counter, char*(*ffpci_lookup_name)(struct pci_access*, char*, int, int, ...))
{
char vendor[512];
@@ -144,3 +154,5 @@ void ffPrintGPU(FFinstance* instance)
ffpci_cleanup(pacc);
dlclose(pci);
}
#endif
+25 -32
View File
@@ -5,19 +5,11 @@
#include <dirent.h>
#include <pthread.h>
#if FF_HAS_X11
# include <X11/Xlib.h>
#endif
#if FF_HAS_XRANDR
# include <X11/extensions/Xrandr.h>
#endif
#if FF_HAS_WAYLAND
# include <wayland-client.h>
#endif
#define FF_RESOLUTION_MODULE_NAME "Resolution"
#define FF_RESOLUTION_NUM_FORMAT_ARGS 3
typedef void* DynamicLibrary;
#define FF_LIBRARY_LOAD(libraryNameUser, libraryNameDefault) dlopen(libraryNameUser.length == 0 ? libraryNameDefault : libraryNameUser.chars, RTLD_LAZY); \
if(dlerror() != NULL) \
return false;
@@ -28,8 +20,6 @@
return false; \
}
typedef void* DynamicLibrary;
typedef struct ResolutionResult
{
int width;
@@ -69,7 +59,6 @@ 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)
@@ -87,7 +76,6 @@ static int parseRefreshRate(int32_t refreshRate)
return refreshRate;
}
#endif // FF_HAS_XRANDR || FF_HAS_WAYLAND
static void printResolutionDRMBackend(FFinstance* instance)
{
@@ -149,7 +137,9 @@ static void printResolutionDRMBackend(FFinstance* instance)
printResolutionResultList(instance, &modes);
}
#if FF_HAS_X11
#ifdef FF_HAVE_X11
#include <X11/Xlib.h>
static void x11AddScreenAsResult(FFlist* results, Screen* screen, int refreshRate)
{
if(WidthOfScreen(screen) == 0 || HeightOfScreen(screen) == 0)
@@ -186,9 +176,12 @@ static bool printResolutionX11Backend(FFinstance* instance)
return printResolutionResultList(instance, &results);
}
#endif // FF_HAS_XLIB
#if FF_HAS_XRANDR
#endif //FF_HAVE_X11
#ifdef FF_HAVE_XRANDR
#include <X11/extensions/Xrandr.h>
typedef struct XrandrData
{
XRRScreenConfiguration*(*ffXRRGetScreenInfo)(Display* display, Window window);
@@ -370,9 +363,11 @@ static bool printResolutionXrandrBackend(FFinstance* instance)
return printResolutionResultList(instance, &data.results);
}
#endif // FF_HAS_XRANDR
#endif // FF_HAVE_XRANDR
#ifdef FF_HAVE_WAYLAND
#include <wayland-client.h>
#if FF_HAS_WAYLAND
typedef struct WaylandData
{
FFinstance* instance;
@@ -517,25 +512,23 @@ static bool printResolutionWaylandBackend(FFinstance* instance)
return printResolutionResultList(instance, &data.results);
}
#endif // FF_HAS_WAYLAND
#endif //FF_HAVE_WAYLAND
void ffPrintResolution(FFinstance* instance)
{
if(
#if FF_HAS_WAYLAND
printResolutionWaylandBackend(instance) ||
#endif
#if FF_HAS_XRANDR
printResolutionXrandrBackend(instance) ||
#endif
#if FF_HAS_X11
printResolutionX11Backend(instance) ||
#endif
#if FF_HAVE_WAYLAND
printResolutionWaylandBackend(instance) ||
#endif
#if FF_HAVE_XRANDR
printResolutionXrandrBackend(instance) ||
#endif
#if FF_HAVE_X11
printResolutionX11Backend(instance) ||
#endif
false
) return;
printResolutionDRMBackend(instance);
}
#undef FF_LIBRARY_LOAD
#undef FF_LIBRARY_LOAD_SYMBOL