mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Link apple frameworks at compile time
This commit is contained in:
+19
-3
@@ -43,8 +43,7 @@ cmake_dependent_option(ENABLE_ZLIB "Enable zlib" ON "ENABLE_IMAGEMAGICK6 OR ENAB
|
||||
cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX" OFF)
|
||||
cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX" OFF)
|
||||
cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX" OFF)
|
||||
cmake_dependent_option(ENABLE_CGL "Enable cgl" ON "APPLE" OFF)
|
||||
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR APPLE" OFF)
|
||||
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX" OFF)
|
||||
|
||||
option(BUILD_TESTS "Build tests" OFF) # Also create test executables
|
||||
option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds
|
||||
@@ -286,6 +285,7 @@ function(ff_lib_enable VARNAME)
|
||||
if(${VARNAME}_FOUND)
|
||||
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_${VARNAME}=1)
|
||||
target_include_directories(libfastfetch PRIVATE ${${VARNAME}_INCLUDE_DIRS})
|
||||
target_link_directories(libfastfetch PRIVATE ${${VARNAME}_LIBRARY_DIRS})
|
||||
return()
|
||||
endif()
|
||||
endforeach()
|
||||
@@ -313,9 +313,25 @@ ff_lib_enable(CHAFA chafa>=1.10)
|
||||
ff_lib_enable(EGL egl)
|
||||
ff_lib_enable(GLX glx)
|
||||
ff_lib_enable(OSMESA osmesa)
|
||||
ff_lib_enable(CGL, OpenGL)
|
||||
ff_lib_enable(OPENCL OpenCL)
|
||||
|
||||
function(ff_framwork_enable LIBNAME)
|
||||
if(NOT APPLE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
find_package(${LIBNAME} REQUIRED)
|
||||
|
||||
target_include_directories(libfastfetch PRIVATE ${${LIBNAME}_INCLUDE_DIRS})
|
||||
target_link_directories(libfastfetch PRIVATE ${${LIBNAME}_LIBRARY_DIRS})
|
||||
target_link_libraries(libfastfetch PRIVATE ${${LIBNAME}_LIBRARIES})
|
||||
endfunction()
|
||||
|
||||
ff_framwork_enable(IOKit)
|
||||
ff_framwork_enable(CoreGraphics)
|
||||
ff_framwork_enable(OpenGL)
|
||||
ff_framwork_enable(OpenCL)
|
||||
|
||||
target_include_directories(libfastfetch
|
||||
PUBLIC ${PROJECT_BINARY_DIR}
|
||||
PUBLIC ${PROJECT_SOURCE_DIR}/src
|
||||
|
||||
@@ -211,7 +211,6 @@ static void defaultConfig(FFinstance* instance)
|
||||
ffStrbufInitA(&instance->config.libEGL, 0);
|
||||
ffStrbufInitA(&instance->config.libGLX, 0);
|
||||
ffStrbufInitA(&instance->config.libOSMesa, 0);
|
||||
ffStrbufInitA(&instance->config.libCGL, 0);
|
||||
ffStrbufInitA(&instance->config.libOpenCL, 0);
|
||||
|
||||
instance->config.titleFQDN = false;
|
||||
@@ -431,9 +430,6 @@ void ffListFeatures()
|
||||
#ifdef FF_HAVE_OSMESA
|
||||
"osmesa\n"
|
||||
#endif
|
||||
#ifdef FF_HAVE_CGL
|
||||
"cgl\n"
|
||||
#endif
|
||||
#ifdef FF_HAVE_OPENCL
|
||||
"opencl\n"
|
||||
#endif
|
||||
|
||||
@@ -29,17 +29,8 @@ void CGSGetDisplayModeDescriptionOfLength(CGDirectDisplayID display, int idx, mo
|
||||
|
||||
static void detectResolution(FFDisplayServerResult* ds)
|
||||
{
|
||||
void* cg = dlopen(FASTFETCH_TARGET_DIR_ROOT"/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics", RTLD_LAZY);
|
||||
if(cg == NULL)
|
||||
return;
|
||||
|
||||
FF_LIBRARY_LOAD_SYMBOL(cg, CGGetOnlineDisplayList, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(cg, CGDisplayScreenSize, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(cg, CGSGetCurrentDisplayMode, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(cg, CGSGetDisplayModeDescriptionOfLength, )
|
||||
|
||||
CGDisplayCount screenCount;
|
||||
ffCGGetOnlineDisplayList(INT_MAX, NULL, &screenCount);
|
||||
CGGetOnlineDisplayList(INT_MAX, NULL, &screenCount);
|
||||
if(screenCount == 0)
|
||||
{
|
||||
dlclose(cg);
|
||||
@@ -47,21 +38,20 @@ static void detectResolution(FFDisplayServerResult* ds)
|
||||
}
|
||||
|
||||
CGDirectDisplayID* screens = malloc(screenCount * sizeof(CGDirectDisplayID));
|
||||
ffCGGetOnlineDisplayList(INT_MAX, screens, &screenCount);
|
||||
CGGetOnlineDisplayList(INT_MAX, screens, &screenCount);
|
||||
|
||||
for(uint32_t i = 0; i < screenCount; i++)
|
||||
{
|
||||
int modeID;
|
||||
ffCGSGetCurrentDisplayMode(screens[i], &modeID);
|
||||
CGSGetCurrentDisplayMode(screens[i], &modeID);
|
||||
modes_D4 mode;
|
||||
ffCGSGetDisplayModeDescriptionOfLength(screens[i], modeID, &mode, 0xD4);
|
||||
CGSGetDisplayModeDescriptionOfLength(screens[i], modeID, &mode, 0xD4);
|
||||
|
||||
uint32_t refreshRate = ffdsParseRefreshRate(mode.derived.freq);
|
||||
ffdsAppendResolution(ds, mode.derived.width, mode.derived.height, refreshRate);
|
||||
}
|
||||
|
||||
free(screens);
|
||||
dlclose(cg);
|
||||
}
|
||||
|
||||
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* instance)
|
||||
|
||||
@@ -24,57 +24,38 @@ void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
|
||||
gpu->temperature = FF_GPU_TEMP_UNSET;
|
||||
}
|
||||
|
||||
void* iokit = dlopen(FASTFETCH_TARGET_DIR_ROOT"/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_LAZY);
|
||||
if(iokit == NULL)
|
||||
return;
|
||||
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, IOServiceMatching, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, IOServiceGetMatchingServices, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, IOIteratorNext, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, IORegistryEntryCreateCFProperties, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, kCFAllocatorDefault, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, kCFAllocatorNull, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, CFDictionaryGetValue, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, CFGetTypeID, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringCreateWithCStringNoCopy, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringGetLength, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringGetCString, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, CFRelease, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, CFDataGetTypeID, )
|
||||
FF_LIBRARY_LOAD_SYMBOL(iokit, IOObjectRelease, )
|
||||
|
||||
CFMutableDictionaryRef matchDict = ffIOServiceMatching("IOPCIDevice");
|
||||
CFMutableDictionaryRef matchDict = IOServiceMatching("IOPCIDevice");
|
||||
io_iterator_t iterator;
|
||||
if(ffIOServiceGetMatchingServices(0, matchDict, &iterator) != kIOReturnSuccess)
|
||||
if(IOServiceGetMatchingServices(0, matchDict, &iterator) != kIOReturnSuccess)
|
||||
{
|
||||
dlclose(iokit);
|
||||
return;
|
||||
}
|
||||
|
||||
io_registry_entry_t registryEntry;
|
||||
while((registryEntry = ffIOIteratorNext(iterator)) != 0)
|
||||
while((registryEntry = IOIteratorNext(iterator)) != 0)
|
||||
{
|
||||
CFMutableDictionaryRef properties;
|
||||
if(ffIORegistryEntryCreateCFProperties(registryEntry, &properties, *ffkCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
|
||||
if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
|
||||
{
|
||||
ffIOObjectRelease(registryEntry);
|
||||
IOObjectRelease(registryEntry);
|
||||
continue;
|
||||
}
|
||||
|
||||
CFStringRef key = ffCFStringCreateWithCStringNoCopy(NULL, "model", kCFStringEncodingASCII, *ffkCFAllocatorNull);
|
||||
CFStringRef model = ffCFDictionaryGetValue(properties, key);
|
||||
if(model == NULL || ffCFGetTypeID(model) != ffCFDataGetTypeID())
|
||||
CFStringRef key = CFStringCreateWithCStringNoCopy(NULL, "model", kCFStringEncodingASCII, kCFAllocatorNull);
|
||||
CFStringRef model = CFDictionaryGetValue(properties, key);
|
||||
if(model == NULL || CFGetTypeID(model) != CFDataGetTypeID())
|
||||
{
|
||||
ffCFRelease(properties);
|
||||
ffIOObjectRelease(registryEntry);
|
||||
CFRelease(properties);
|
||||
IOObjectRelease(registryEntry);
|
||||
continue;
|
||||
}
|
||||
|
||||
FFGPUResult* gpu = ffListAdd(gpus);
|
||||
|
||||
uint32_t modelLength = (uint32_t) ffCFStringGetLength(model);
|
||||
uint32_t modelLength = (uint32_t) CFStringGetLength(model);
|
||||
ffStrbufInitA(&gpu->name, modelLength + 1);
|
||||
ffCFStringGetCString(model, gpu->name.chars, modelLength + 1, kCFStringEncodingASCII);
|
||||
CFStringGetCString(model, gpu->name.chars, modelLength + 1, kCFStringEncodingASCII);
|
||||
gpu->name.length = modelLength;
|
||||
gpu->name.chars[gpu->name.length] = '\0';
|
||||
|
||||
@@ -82,10 +63,9 @@ void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
|
||||
ffStrbufInitA(&gpu->driver, 0);
|
||||
gpu->temperature = FF_GPU_TEMP_UNSET;
|
||||
|
||||
ffCFRelease(properties);
|
||||
ffIOObjectRelease(registryEntry);
|
||||
CFRelease(properties);
|
||||
IOObjectRelease(registryEntry);
|
||||
}
|
||||
|
||||
ffIOObjectRelease(iterator);
|
||||
dlclose(iokit);
|
||||
IOObjectRelease(iterator);
|
||||
}
|
||||
|
||||
@@ -1258,7 +1258,6 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
"egl", FF_GL_TYPE_EGL,
|
||||
"glx", FF_GL_TYPE_GLX,
|
||||
"osmesa", FF_GL_TYPE_OSMESA,
|
||||
"cgl", FF_GL_TYPE_CGL,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
||||
+1
-3
@@ -50,8 +50,7 @@ typedef enum FFGLType
|
||||
FF_GL_TYPE_AUTO,
|
||||
FF_GL_TYPE_EGL,
|
||||
FF_GL_TYPE_GLX,
|
||||
FF_GL_TYPE_OSMESA,
|
||||
FF_GL_TYPE_CGL
|
||||
FF_GL_TYPE_OSMESA
|
||||
} FFGLType;
|
||||
|
||||
typedef struct FFModuleArgs
|
||||
@@ -148,7 +147,6 @@ typedef struct FFconfig
|
||||
FFstrbuf libEGL;
|
||||
FFstrbuf libGLX;
|
||||
FFstrbuf libOSMesa;
|
||||
FFstrbuf libCGL;
|
||||
FFstrbuf libOpenCL;
|
||||
|
||||
bool titleFQDN;
|
||||
|
||||
+11
-6
@@ -80,17 +80,22 @@ static const char* printOpenCL(FFinstance* instance)
|
||||
OpenCLData data;
|
||||
|
||||
#ifdef __APPLE__
|
||||
FF_LIBRARY_LOAD(opencl, instance->config.libOpenCL, "dlopen OpenCL failed", "/System/Library/Frameworks/OpenCL.framework/OpenCL", -1);
|
||||
data.ffclGetPlatformIDs = clGetPlatformIDs;
|
||||
data.ffclGetDeviceIDs = clGetDeviceIDs;
|
||||
data.ffclGetDeviceInfo = clGetDeviceInfo;
|
||||
#else
|
||||
FF_LIBRARY_LOAD(opencl, instance->config.libOpenCL, "dlopen libOpenCL.so failed", "libOpenCL.so", 1);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetPlatformIDs);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetDeviceIDs);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetDeviceInfo);
|
||||
#endif
|
||||
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetPlatformIDs);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetDeviceIDs);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetDeviceInfo);
|
||||
|
||||
const char* error = openCLHandelData(instance, &data);
|
||||
dlclose(opencl);
|
||||
|
||||
#ifndef __APPLE__
|
||||
dlclose(opencl);
|
||||
#endif
|
||||
|
||||
return error;
|
||||
}
|
||||
#endif
|
||||
|
||||
+17
-49
@@ -7,7 +7,7 @@
|
||||
#define FF_OPENGL_MODULE_NAME "OpenGL"
|
||||
#define FF_OPENGL_NUM_FORMAT_ARGS 4
|
||||
|
||||
#if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA) || defined(FF_HAVE_CGL)
|
||||
#if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA) || defined(__APPLE__)
|
||||
#define FF_HAVE_GL 1
|
||||
|
||||
#include "common/library.h"
|
||||
@@ -339,41 +339,36 @@ static const char* osMesaPrint(FFinstance* instance)
|
||||
|
||||
#endif //FF_HAVE_OSMESA
|
||||
|
||||
#ifdef FF_HAVE_CGL
|
||||
#ifdef __APPLE__
|
||||
|
||||
typedef struct CGLData
|
||||
{
|
||||
GLData glData;
|
||||
|
||||
FF_LIBRARY_SYMBOL(CGLChoosePixelFormat);
|
||||
FF_LIBRARY_SYMBOL(CGLCreateContext);
|
||||
FF_LIBRARY_SYMBOL(CGLSetCurrentContext);
|
||||
FF_LIBRARY_SYMBOL(CGLDestroyContext);
|
||||
FF_LIBRARY_SYMBOL(CGLDestroyPixelFormat);
|
||||
|
||||
CGLPixelFormatObj pixelFormat;
|
||||
CGLContextObj context;
|
||||
} CGLData;
|
||||
|
||||
static const char* cglHandleContext(FFinstance* instance, CGLData* data)
|
||||
{
|
||||
if(data->ffCGLSetCurrentContext(data->context) != kCGLNoError)
|
||||
if(CGLSetCurrentContext(data->context) != kCGLNoError)
|
||||
return "CGLSetCurrentContext() failed";
|
||||
|
||||
return glHandlePrint(instance, &data->glData);
|
||||
GLData glData;
|
||||
glData.ffglGetString = glGetString;
|
||||
|
||||
return glHandlePrint(instance, &glData);
|
||||
}
|
||||
|
||||
static const char* cglHandlePixelFormat(FFinstance* instance, CGLData* data)
|
||||
{
|
||||
if(data->ffCGLCreateContext(data->pixelFormat, NULL, &data->context) != kCGLNoError)
|
||||
if(CGLCreateContext(data->pixelFormat, NULL, &data->context) != kCGLNoError)
|
||||
return "CGLCreateContext() failed";
|
||||
|
||||
const char* error = cglHandleContext(instance, data);
|
||||
data->ffCGLDestroyContext(data->context);
|
||||
CGLDestroyContext(data->context);
|
||||
return error;
|
||||
}
|
||||
|
||||
static const char* cglHandleData(FFinstance* instance, CGLData* data)
|
||||
static const char* cglPrint(FFinstance* instance)
|
||||
{
|
||||
CGLPixelFormatAttribute attrs[] = {
|
||||
kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core,
|
||||
@@ -382,32 +377,15 @@ static const char* cglHandleData(FFinstance* instance, CGLData* data)
|
||||
};
|
||||
|
||||
GLint num;
|
||||
if (data->ffCGLChoosePixelFormat(attrs, &data->pixelFormat, &num) != kCGLNoError)
|
||||
if (CGLChoosePixelFormat(attrs, &data->pixelFormat, &num) != kCGLNoError)
|
||||
return "CGLChoosePixelFormat() failed";
|
||||
|
||||
const char* error = cglHandlePixelFormat(instance, data);
|
||||
data->ffCGLDestroyPixelFormat(data->pixelFormat);
|
||||
CGLDestroyPixelFormat(data->pixelFormat);
|
||||
return error;
|
||||
}
|
||||
|
||||
static const char* cglPrint(FFinstance* instance)
|
||||
{
|
||||
CGLData data;
|
||||
|
||||
FF_LIBRARY_LOAD(cgl, instance->config.libCGL, "dlopen cgl failed", "/System/Library/Frameworks/OpenGL.framework/OpenGL", -1);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data, CGLChoosePixelFormat);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data, CGLCreateContext);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data, CGLSetCurrentContext);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data, CGLDestroyContext);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data, CGLDestroyPixelFormat);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data.glData, glGetString);
|
||||
|
||||
const char* error = cglHandleData(instance, &data);
|
||||
dlclose(cgl);
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif //FF_HAVE_CGL
|
||||
#else // __APPLE__
|
||||
|
||||
static const char* glPrint(FFinstance* instance)
|
||||
{
|
||||
@@ -438,15 +416,6 @@ static const char* glPrint(FFinstance* instance)
|
||||
#endif
|
||||
}
|
||||
|
||||
if(instance->config.glType == FF_GL_TYPE_CGL)
|
||||
{
|
||||
#ifdef FF_HAVE_CGL
|
||||
return cglPrint(instance);
|
||||
#else
|
||||
return "fastfetch was compiled without cgl support";
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* error = ""; // not NULL dummy value
|
||||
|
||||
#ifdef FF_HAVE_EGL
|
||||
@@ -458,17 +427,14 @@ static const char* glPrint(FFinstance* instance)
|
||||
error = glxPrint(instance);
|
||||
#endif
|
||||
|
||||
#ifdef FF_HAVE_CGL
|
||||
if(error != NULL)
|
||||
error = cglPrint(instance);
|
||||
#endif
|
||||
|
||||
//We don't use osmesa in auto mode here, because it is a software implementation,
|
||||
//that doesn't reflect the opengl supported by the hardware
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif // !__APPLE__
|
||||
|
||||
#endif // FF_HAVE_GL
|
||||
|
||||
void ffPrintOpenGL(FFinstance* instance)
|
||||
@@ -477,6 +443,8 @@ void ffPrintOpenGL(FFinstance* instance)
|
||||
|
||||
#ifndef FF_HAVE_GL
|
||||
error = "Fastfetch was built without gl support.";
|
||||
#elif __APPLE__
|
||||
error = cglPrint(instance);
|
||||
#else
|
||||
error = glPrint(instance);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user