Skip to content

Commit ac33043

Browse files
Link apple frameworks at compile time
1 parent 52275b8 commit ac33043

File tree

8 files changed

+67
-115
lines changed

8 files changed

+67
-115
lines changed

CMakeLists.txt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ cmake_dependent_option(ENABLE_ZLIB "Enable zlib" ON "ENABLE_IMAGEMAGICK6 OR ENAB
4343
cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX" OFF)
4444
cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX" OFF)
4545
cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX" OFF)
46-
cmake_dependent_option(ENABLE_CGL "Enable cgl" ON "APPLE" OFF)
47-
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR APPLE" OFF)
46+
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX" OFF)
4847

4948
option(BUILD_TESTS "Build tests" OFF) # Also create test executables
5049
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)
286285
if(${VARNAME}_FOUND)
287286
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_${VARNAME}=1)
288287
target_include_directories(libfastfetch PRIVATE ${${VARNAME}_INCLUDE_DIRS})
288+
target_link_directories(libfastfetch PRIVATE ${${VARNAME}_LIBRARY_DIRS})
289289
return()
290290
endif()
291291
endforeach()
@@ -313,9 +313,25 @@ ff_lib_enable(CHAFA chafa>=1.10)
313313
ff_lib_enable(EGL egl)
314314
ff_lib_enable(GLX glx)
315315
ff_lib_enable(OSMESA osmesa)
316-
ff_lib_enable(CGL, OpenGL)
317316
ff_lib_enable(OPENCL OpenCL)
318317

318+
function(ff_framwork_enable LIBNAME)
319+
if(NOT APPLE)
320+
return()
321+
endif()
322+
323+
find_package(${LIBNAME} REQUIRED)
324+
325+
target_include_directories(libfastfetch PRIVATE ${${LIBNAME}_INCLUDE_DIRS})
326+
target_link_directories(libfastfetch PRIVATE ${${LIBNAME}_LIBRARY_DIRS})
327+
target_link_libraries(libfastfetch PRIVATE ${${LIBNAME}_LIBRARIES})
328+
endfunction()
329+
330+
ff_framwork_enable(IOKit)
331+
ff_framwork_enable(CoreGraphics)
332+
ff_framwork_enable(OpenGL)
333+
ff_framwork_enable(OpenCL)
334+
319335
target_include_directories(libfastfetch
320336
PUBLIC ${PROJECT_BINARY_DIR}
321337
PUBLIC ${PROJECT_SOURCE_DIR}/src

src/common/init.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ static void defaultConfig(FFinstance* instance)
211211
ffStrbufInitA(&instance->config.libEGL, 0);
212212
ffStrbufInitA(&instance->config.libGLX, 0);
213213
ffStrbufInitA(&instance->config.libOSMesa, 0);
214-
ffStrbufInitA(&instance->config.libCGL, 0);
215214
ffStrbufInitA(&instance->config.libOpenCL, 0);
216215

217216
instance->config.titleFQDN = false;
@@ -431,9 +430,6 @@ void ffListFeatures()
431430
#ifdef FF_HAVE_OSMESA
432431
"osmesa\n"
433432
#endif
434-
#ifdef FF_HAVE_CGL
435-
"cgl\n"
436-
#endif
437433
#ifdef FF_HAVE_OPENCL
438434
"opencl\n"
439435
#endif

src/detection/displayserver/displayserver_apple.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,29 @@ void CGSGetDisplayModeDescriptionOfLength(CGDirectDisplayID display, int idx, mo
2929

3030
static void detectResolution(FFDisplayServerResult* ds)
3131
{
32-
void* cg = dlopen(FASTFETCH_TARGET_DIR_ROOT"/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics", RTLD_LAZY);
33-
if(cg == NULL)
34-
return;
35-
36-
FF_LIBRARY_LOAD_SYMBOL(cg, CGGetOnlineDisplayList, )
37-
FF_LIBRARY_LOAD_SYMBOL(cg, CGDisplayScreenSize, )
38-
FF_LIBRARY_LOAD_SYMBOL(cg, CGSGetCurrentDisplayMode, )
39-
FF_LIBRARY_LOAD_SYMBOL(cg, CGSGetDisplayModeDescriptionOfLength, )
40-
4132
CGDisplayCount screenCount;
42-
ffCGGetOnlineDisplayList(INT_MAX, NULL, &screenCount);
33+
CGGetOnlineDisplayList(INT_MAX, NULL, &screenCount);
4334
if(screenCount == 0)
4435
{
4536
dlclose(cg);
4637
return;
4738
}
4839

4940
CGDirectDisplayID* screens = malloc(screenCount * sizeof(CGDirectDisplayID));
50-
ffCGGetOnlineDisplayList(INT_MAX, screens, &screenCount);
41+
CGGetOnlineDisplayList(INT_MAX, screens, &screenCount);
5142

5243
for(uint32_t i = 0; i < screenCount; i++)
5344
{
5445
int modeID;
55-
ffCGSGetCurrentDisplayMode(screens[i], &modeID);
46+
CGSGetCurrentDisplayMode(screens[i], &modeID);
5647
modes_D4 mode;
57-
ffCGSGetDisplayModeDescriptionOfLength(screens[i], modeID, &mode, 0xD4);
48+
CGSGetDisplayModeDescriptionOfLength(screens[i], modeID, &mode, 0xD4);
5849

5950
uint32_t refreshRate = ffdsParseRefreshRate(mode.derived.freq);
6051
ffdsAppendResolution(ds, mode.derived.width, mode.derived.height, refreshRate);
6152
}
6253

6354
free(screens);
64-
dlclose(cg);
6555
}
6656

6757
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* instance)

src/detection/gpu/gpu_apple.c

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,68 +24,48 @@ void ffDetectGPUImpl(FFlist* gpus, const FFinstance* instance)
2424
gpu->temperature = FF_GPU_TEMP_UNSET;
2525
}
2626

27-
void* iokit = dlopen(FASTFETCH_TARGET_DIR_ROOT"/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_LAZY);
28-
if(iokit == NULL)
29-
return;
30-
31-
FF_LIBRARY_LOAD_SYMBOL(iokit, IOServiceMatching, )
32-
FF_LIBRARY_LOAD_SYMBOL(iokit, IOServiceGetMatchingServices, )
33-
FF_LIBRARY_LOAD_SYMBOL(iokit, IOIteratorNext, )
34-
FF_LIBRARY_LOAD_SYMBOL(iokit, IORegistryEntryCreateCFProperties, )
35-
FF_LIBRARY_LOAD_SYMBOL(iokit, kCFAllocatorDefault, )
36-
FF_LIBRARY_LOAD_SYMBOL(iokit, kCFAllocatorNull, )
37-
FF_LIBRARY_LOAD_SYMBOL(iokit, CFDictionaryGetValue, )
38-
FF_LIBRARY_LOAD_SYMBOL(iokit, CFGetTypeID, )
39-
FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringCreateWithCStringNoCopy, )
40-
FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringGetLength, )
41-
FF_LIBRARY_LOAD_SYMBOL(iokit, CFStringGetCString, )
42-
FF_LIBRARY_LOAD_SYMBOL(iokit, CFRelease, )
43-
FF_LIBRARY_LOAD_SYMBOL(iokit, CFDataGetTypeID, )
44-
FF_LIBRARY_LOAD_SYMBOL(iokit, IOObjectRelease, )
45-
46-
CFMutableDictionaryRef matchDict = ffIOServiceMatching("IOPCIDevice");
27+
CFMutableDictionaryRef matchDict = IOServiceMatching("IOPCIDevice");
4728
io_iterator_t iterator;
48-
if(ffIOServiceGetMatchingServices(0, matchDict, &iterator) != kIOReturnSuccess)
29+
if(IOServiceGetMatchingServices(0, matchDict, &iterator) != kIOReturnSuccess)
4930
{
5031
dlclose(iokit);
5132
return;
5233
}
5334

5435
io_registry_entry_t registryEntry;
55-
while((registryEntry = ffIOIteratorNext(iterator)) != 0)
36+
while((registryEntry = IOIteratorNext(iterator)) != 0)
5637
{
5738
CFMutableDictionaryRef properties;
58-
if(ffIORegistryEntryCreateCFProperties(registryEntry, &properties, *ffkCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
39+
if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
5940
{
60-
ffIOObjectRelease(registryEntry);
41+
IOObjectRelease(registryEntry);
6142
continue;
6243
}
6344

64-
CFStringRef key = ffCFStringCreateWithCStringNoCopy(NULL, "model", kCFStringEncodingASCII, *ffkCFAllocatorNull);
65-
CFStringRef model = ffCFDictionaryGetValue(properties, key);
66-
if(model == NULL || ffCFGetTypeID(model) != ffCFDataGetTypeID())
45+
CFStringRef key = CFStringCreateWithCStringNoCopy(NULL, "model", kCFStringEncodingASCII, kCFAllocatorNull);
46+
CFStringRef model = CFDictionaryGetValue(properties, key);
47+
if(model == NULL || CFGetTypeID(model) != CFDataGetTypeID())
6748
{
68-
ffCFRelease(properties);
69-
ffIOObjectRelease(registryEntry);
49+
CFRelease(properties);
50+
IOObjectRelease(registryEntry);
7051
continue;
7152
}
7253

7354
FFGPUResult* gpu = ffListAdd(gpus);
7455

75-
uint32_t modelLength = (uint32_t) ffCFStringGetLength(model);
56+
uint32_t modelLength = (uint32_t) CFStringGetLength(model);
7657
ffStrbufInitA(&gpu->name, modelLength + 1);
77-
ffCFStringGetCString(model, gpu->name.chars, modelLength + 1, kCFStringEncodingASCII);
58+
CFStringGetCString(model, gpu->name.chars, modelLength + 1, kCFStringEncodingASCII);
7859
gpu->name.length = modelLength;
7960
gpu->name.chars[gpu->name.length] = '\0';
8061

8162
ffStrbufInitA(&gpu->vendor, 0);
8263
ffStrbufInitA(&gpu->driver, 0);
8364
gpu->temperature = FF_GPU_TEMP_UNSET;
8465

85-
ffCFRelease(properties);
86-
ffIOObjectRelease(registryEntry);
66+
CFRelease(properties);
67+
IOObjectRelease(registryEntry);
8768
}
8869

89-
ffIOObjectRelease(iterator);
90-
dlclose(iokit);
70+
IOObjectRelease(iterator);
9171
}

src/fastfetch.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,6 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
12581258
"egl", FF_GL_TYPE_EGL,
12591259
"glx", FF_GL_TYPE_GLX,
12601260
"osmesa", FF_GL_TYPE_OSMESA,
1261-
"cgl", FF_GL_TYPE_CGL,
12621261
NULL
12631262
);
12641263
}

src/fastfetch.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ typedef enum FFGLType
5050
FF_GL_TYPE_AUTO,
5151
FF_GL_TYPE_EGL,
5252
FF_GL_TYPE_GLX,
53-
FF_GL_TYPE_OSMESA,
54-
FF_GL_TYPE_CGL
53+
FF_GL_TYPE_OSMESA
5554
} FFGLType;
5655

5756
typedef struct FFModuleArgs
@@ -148,7 +147,6 @@ typedef struct FFconfig
148147
FFstrbuf libEGL;
149148
FFstrbuf libGLX;
150149
FFstrbuf libOSMesa;
151-
FFstrbuf libCGL;
152150
FFstrbuf libOpenCL;
153151

154152
bool titleFQDN;

src/modules/opencl.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,22 @@ static const char* printOpenCL(FFinstance* instance)
8080
OpenCLData data;
8181

8282
#ifdef __APPLE__
83-
FF_LIBRARY_LOAD(opencl, instance->config.libOpenCL, "dlopen OpenCL failed", "/System/Library/Frameworks/OpenCL.framework/OpenCL", -1);
83+
data.ffclGetPlatformIDs = clGetPlatformIDs;
84+
data.ffclGetDeviceIDs = clGetDeviceIDs;
85+
data.ffclGetDeviceInfo = clGetDeviceInfo;
8486
#else
8587
FF_LIBRARY_LOAD(opencl, instance->config.libOpenCL, "dlopen libOpenCL.so failed", "libOpenCL.so", 1);
88+
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetPlatformIDs);
89+
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetDeviceIDs);
90+
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetDeviceInfo);
8691
#endif
8792

88-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetPlatformIDs);
89-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetDeviceIDs);
90-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetDeviceInfo);
91-
9293
const char* error = openCLHandelData(instance, &data);
93-
dlclose(opencl);
94+
95+
#ifndef __APPLE__
96+
dlclose(opencl);
97+
#endif
98+
9499
return error;
95100
}
96101
#endif

src/modules/opengl.c

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#define FF_OPENGL_MODULE_NAME "OpenGL"
88
#define FF_OPENGL_NUM_FORMAT_ARGS 4
99

10-
#if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA) || defined(FF_HAVE_CGL)
10+
#if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA) || defined(__APPLE__)
1111
#define FF_HAVE_GL 1
1212

1313
#include "common/library.h"
@@ -339,41 +339,36 @@ static const char* osMesaPrint(FFinstance* instance)
339339

340340
#endif //FF_HAVE_OSMESA
341341

342-
#ifdef FF_HAVE_CGL
342+
#ifdef __APPLE__
343343

344344
typedef struct CGLData
345345
{
346-
GLData glData;
347-
348-
FF_LIBRARY_SYMBOL(CGLChoosePixelFormat);
349-
FF_LIBRARY_SYMBOL(CGLCreateContext);
350-
FF_LIBRARY_SYMBOL(CGLSetCurrentContext);
351-
FF_LIBRARY_SYMBOL(CGLDestroyContext);
352-
FF_LIBRARY_SYMBOL(CGLDestroyPixelFormat);
353-
354346
CGLPixelFormatObj pixelFormat;
355347
CGLContextObj context;
356348
} CGLData;
357349

358350
static const char* cglHandleContext(FFinstance* instance, CGLData* data)
359351
{
360-
if(data->ffCGLSetCurrentContext(data->context) != kCGLNoError)
352+
if(CGLSetCurrentContext(data->context) != kCGLNoError)
361353
return "CGLSetCurrentContext() failed";
362354

363-
return glHandlePrint(instance, &data->glData);
355+
GLData glData;
356+
glData.ffglGetString = glGetString;
357+
358+
return glHandlePrint(instance, &glData);
364359
}
365360

366361
static const char* cglHandlePixelFormat(FFinstance* instance, CGLData* data)
367362
{
368-
if(data->ffCGLCreateContext(data->pixelFormat, NULL, &data->context) != kCGLNoError)
363+
if(CGLCreateContext(data->pixelFormat, NULL, &data->context) != kCGLNoError)
369364
return "CGLCreateContext() failed";
370365

371366
const char* error = cglHandleContext(instance, data);
372-
data->ffCGLDestroyContext(data->context);
367+
CGLDestroyContext(data->context);
373368
return error;
374369
}
375370

376-
static const char* cglHandleData(FFinstance* instance, CGLData* data)
371+
static const char* cglPrint(FFinstance* instance)
377372
{
378373
CGLPixelFormatAttribute attrs[] = {
379374
kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core,
@@ -382,32 +377,15 @@ static const char* cglHandleData(FFinstance* instance, CGLData* data)
382377
};
383378

384379
GLint num;
385-
if (data->ffCGLChoosePixelFormat(attrs, &data->pixelFormat, &num) != kCGLNoError)
380+
if (CGLChoosePixelFormat(attrs, &data->pixelFormat, &num) != kCGLNoError)
386381
return "CGLChoosePixelFormat() failed";
387382

388383
const char* error = cglHandlePixelFormat(instance, data);
389-
data->ffCGLDestroyPixelFormat(data->pixelFormat);
390-
return error;
391-
}
392-
393-
static const char* cglPrint(FFinstance* instance)
394-
{
395-
CGLData data;
396-
397-
FF_LIBRARY_LOAD(cgl, instance->config.libCGL, "dlopen cgl failed", "/System/Library/Frameworks/OpenGL.framework/OpenGL", -1);
398-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data, CGLChoosePixelFormat);
399-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data, CGLCreateContext);
400-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data, CGLSetCurrentContext);
401-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data, CGLDestroyContext);
402-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data, CGLDestroyPixelFormat);
403-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(cgl, data.glData, glGetString);
404-
405-
const char* error = cglHandleData(instance, &data);
406-
dlclose(cgl);
384+
CGLDestroyPixelFormat(data->pixelFormat);
407385
return error;
408386
}
409387

410-
#endif //FF_HAVE_CGL
388+
#else // __APPLE__
411389

412390
static const char* glPrint(FFinstance* instance)
413391
{
@@ -438,15 +416,6 @@ static const char* glPrint(FFinstance* instance)
438416
#endif
439417
}
440418

441-
if(instance->config.glType == FF_GL_TYPE_CGL)
442-
{
443-
#ifdef FF_HAVE_CGL
444-
return cglPrint(instance);
445-
#else
446-
return "fastfetch was compiled without cgl support";
447-
#endif
448-
}
449-
450419
const char* error = ""; // not NULL dummy value
451420

452421
#ifdef FF_HAVE_EGL
@@ -458,17 +427,14 @@ static const char* glPrint(FFinstance* instance)
458427
error = glxPrint(instance);
459428
#endif
460429

461-
#ifdef FF_HAVE_CGL
462-
if(error != NULL)
463-
error = cglPrint(instance);
464-
#endif
465-
466430
//We don't use osmesa in auto mode here, because it is a software implementation,
467431
//that doesn't reflect the opengl supported by the hardware
468432

469433
return error;
470434
}
471435

436+
#endif // !__APPLE__
437+
472438
#endif // FF_HAVE_GL
473439

474440
void ffPrintOpenGL(FFinstance* instance)
@@ -477,6 +443,8 @@ void ffPrintOpenGL(FFinstance* instance)
477443

478444
#ifndef FF_HAVE_GL
479445
error = "Fastfetch was built without gl support.";
446+
#elif __APPLE__
447+
error = cglPrint(instance);
480448
#else
481449
error = glPrint(instance);
482450
#endif

0 commit comments

Comments
 (0)