diff --git a/CMakeLists.txt b/CMakeLists.txt index ace8ca515..b88bfd1a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +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_APPLECGL "Enable apple-cgl" ON "APPLE" OFF) +cmake_dependent_option(ENABLE_CGL "Enable cgl" ON "APPLE" OFF) cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR APPLE" OFF) option(BUILD_TESTS "Build tests" OFF) # Also create test executables @@ -276,7 +276,7 @@ if(HAVE_SYSINFO_H) target_compile_definitions(libfastfetch PUBLIC FF_HAVE_SYSINFO_H) endif() -function(ff_check_lib VARNAME) +function(ff_lib_enable VARNAME) if(NOT ENABLE_${VARNAME}) return() endif() @@ -293,51 +293,28 @@ function(ff_check_lib VARNAME) message(WARNING "Package ${ARGV1} not found, building without support.") endfunction() -ff_check_lib(LIBPCI libpci) -ff_check_lib(VULKAN vulkan) -ff_check_lib(WAYLAND wayland-client) -ff_check_lib(XCB_RANDR xcb-randr) -ff_check_lib(XCB xcb) -ff_check_lib(XRANDR xrandr) -ff_check_lib(X11 x11) -ff_check_lib(GIO gio-2.0) -ff_check_lib(DCONF dconf) -ff_check_lib(DBUS dbus-1) -ff_check_lib(XFCONF libxfconf-0) -ff_check_lib(SQLITE3 sqlite3) -ff_check_lib(RPM rpm) -ff_check_lib(IMAGEMAGICK7 MagickCore-7.Q16HDRI MagickCore-7.Q16 /usr/lib/imagemagick7/pkgconfig/MagickCore-7.Q16HDRI.pc /usr/lib/imagemagick7/pkgconfig/MagickCore-7.Q16.pc) -ff_check_lib(IMAGEMAGICK6 MagickCore-6.Q16HDRI MagickCore-6.Q16 /usr/lib/imagemagick6/pkgconfig/MagickCore-6.Q16HDRI.pc /usr/lib/imagemagick6/pkgconfig/MagickCore-6.Q16.pc) -ff_check_lib(ZLIB zlib) -ff_check_lib(CHAFA chafa>=1.10) - -if(APPLE) - # Apple framework bundles can't be found by pkg-config - if(ENABLE_APPLECGL) - find_package(OpenGL) - if(OpenGL_FOUND) - target_compile_definitions(libfastfetch PRIVATE FF_HAVE_APPLECGL=1) - target_link_libraries(libfastfetch PRIVATE ${OPENGL_LIBRARIES}) - else() - message(WARNING "Package Apple-CGL not found, building without support.") - endif() - endif() - - if(ENABLE_OPENCL) - find_package(OpenCL) - if(OpenCL_FOUND) - target_compile_definitions(libfastfetch PRIVATE FF_HAVE_OPENCL=1) - target_link_libraries(libfastfetch PRIVATE ${OpenCL_LIBRARY}) - else() - message(WARNING "Package OpenCL not found, building without support.") - endif() - endif() -else() - ff_check_lib(EGL egl) - ff_check_lib(GLX glx) - ff_check_lib(OSMESA osmesa) - ff_check_lib(OPENCL OpenCL) -endif() +ff_lib_enable(LIBPCI libpci) +ff_lib_enable(VULKAN vulkan) +ff_lib_enable(WAYLAND wayland-client) +ff_lib_enable(XCB_RANDR xcb-randr) +ff_lib_enable(XCB xcb) +ff_lib_enable(XRANDR xrandr) +ff_lib_enable(X11 x11) +ff_lib_enable(GIO gio-2.0) +ff_lib_enable(DCONF dconf) +ff_lib_enable(DBUS dbus-1) +ff_lib_enable(XFCONF libxfconf-0) +ff_lib_enable(SQLITE3 sqlite3) +ff_lib_enable(RPM rpm) +ff_lib_enable(IMAGEMAGICK7 MagickCore-7.Q16HDRI MagickCore-7.Q16 /usr/lib/imagemagick7/pkgconfig/MagickCore-7.Q16HDRI.pc /usr/lib/imagemagick7/pkgconfig/MagickCore-7.Q16.pc) +ff_lib_enable(IMAGEMAGICK6 MagickCore-6.Q16HDRI MagickCore-6.Q16 /usr/lib/imagemagick6/pkgconfig/MagickCore-6.Q16HDRI.pc /usr/lib/imagemagick6/pkgconfig/MagickCore-6.Q16.pc) +ff_lib_enable(ZLIB zlib) +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) target_include_directories(libfastfetch PUBLIC ${PROJECT_BINARY_DIR} diff --git a/src/common/init.c b/src/common/init.c index 76701d4bc..5fa0dce8d 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -211,6 +211,7 @@ 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; @@ -430,8 +431,8 @@ void ffListFeatures() #ifdef FF_HAVE_OSMESA "osmesa\n" #endif - #ifdef FF_HAVE_APPLECGL - "apple-cgl\n" + #ifdef FF_HAVE_CGL + "cgl\n" #endif #ifdef FF_HAVE_OPENCL "opencl\n" diff --git a/src/common/library.c b/src/common/library.c index 1bbf8562b..730b85258 100644 --- a/src/common/library.c +++ b/src/common/library.c @@ -6,7 +6,7 @@ static void* libraryLoad(const char* path, int maxVersion) { void* result = dlopen(path, RTLD_LAZY); - if(result != NULL) + if(result != NULL || maxVersion < 0) return result; FFstrbuf pathbuf; diff --git a/src/fastfetch.c b/src/fastfetch.c index 6a8a8f30f..004cc2d58 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1258,7 +1258,7 @@ 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, - "apple-cgl", FF_GL_TYPE_APPLECGL, + "cgl", FF_GL_TYPE_CGL, NULL ); } diff --git a/src/fastfetch.h b/src/fastfetch.h index 61ac46ad9..5b766222d 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -51,7 +51,7 @@ typedef enum FFGLType FF_GL_TYPE_EGL, FF_GL_TYPE_GLX, FF_GL_TYPE_OSMESA, - FF_GL_TYPE_APPLECGL + FF_GL_TYPE_CGL } FFGLType; typedef struct FFModuleArgs @@ -148,6 +148,7 @@ typedef struct FFconfig FFstrbuf libEGL; FFstrbuf libGLX; FFstrbuf libOSMesa; + FFstrbuf libCGL; FFstrbuf libOpenCL; bool titleFQDN; diff --git a/src/modules/opencl.c b/src/modules/opencl.c index 93e527ec0..994991623 100644 --- a/src/modules/opencl.c +++ b/src/modules/opencl.c @@ -80,20 +80,17 @@ static const char* printOpenCL(FFinstance* instance) OpenCLData data; #ifdef __APPLE__ - data.ffclGetPlatformIDs = clGetPlatformIDs; - data.ffclGetDeviceIDs = clGetDeviceIDs; - data.ffclGetDeviceInfo = clGetDeviceInfo; + FF_LIBRARY_LOAD(opencl, instance->config.libOpenCL, "dlopen OpenCL failed", "/System/Library/Frameworks/OpenCL.framework/OpenCL", -1); #else - FF_LIBRARY_LOAD(opencl, instance->config.libOpenCL, "dlopen libOpenCL.so failed", "libOpenCL.so", 1); + FF_LIBRARY_LOAD(opencl, instance->config.libOpenCL, "dlopen libOpenCL.so failed", "libOpenCL.so", 1); + #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); - #endif const char* error = openCLHandelData(instance, &data); - #ifndef __APPLE__ dlclose(opencl); - #endif return error; } #endif diff --git a/src/modules/opengl.c b/src/modules/opengl.c index f7a3f41d1..e3af8945b 100644 --- a/src/modules/opengl.c +++ b/src/modules/opengl.c @@ -7,14 +7,16 @@ #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_APPLECGL) +#if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA) || defined(FF_HAVE_CGL) #define FF_HAVE_GL 1 + #include "common/library.h" + #ifdef __APPLE__ -#define GL_SILENCE_DEPRECATION -#include + #define GL_SILENCE_DEPRECATION + #include #else -#include + #include #endif #define FF_OPENGL_BUFFER_WIDTH 1 @@ -337,44 +339,75 @@ static const char* osMesaPrint(FFinstance* instance) #endif //FF_HAVE_OSMESA -#ifdef FF_HAVE_APPLECGL +#ifdef FF_HAVE_CGL -#include - -static const char* appleCglPrint(FFinstance* instance) +typedef struct CGLData { - CGLPixelFormatAttribute attrs[] = { - kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, - kCGLPFAAccelerated, - 0 - }; - CGLPixelFormatObj pix; - GLint num; - if (CGLChoosePixelFormat(attrs, &pix, &num) != kCGLNoError) { - return "CGLChoosePixelFormat() failed"; - } + GLData glData; - CGLContextObj ctx; - if (CGLCreateContext(pix, NULL, &ctx) != kCGLNoError) { - return "CGLCreateContext() failed"; - } - if (CGLSetCurrentContext(ctx) != kCGLNoError) { + 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) return "CGLSetCurrentContext() failed"; - } - GLData glData = { - .ffglGetString = glGetString - }; + return glHandlePrint(instance, &data->glData); +} - const char* error = glHandlePrint(instance, &glData); - - CGLDestroyContext(ctx); - CGLDestroyPixelFormat(pix); +static const char* cglHandlePixelFormat(FFinstance* instance, CGLData* data) +{ + if(data->ffCGLCreateContext(data->pixelFormat, NULL, &data->context) != kCGLNoError) + return "CGLCreateContext() failed"; + const char* error = cglHandleContext(instance, data); + data->ffCGLDestroyContext(data->context); return error; } -#endif //FF_HAVE_APPLECGL +static const char* cglHandleData(FFinstance* instance, CGLData* data) +{ + CGLPixelFormatAttribute attrs[] = { + kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core, + kCGLPFAAccelerated, + 0 + }; + + GLint num; + if (data->ffCGLChoosePixelFormat(attrs, &data->pixelFormat, &num) != kCGLNoError) + return "CGLChoosePixelFormat() failed"; + + const char* error = cglHandlePixelFormat(instance, data); + data->ffCGLDestroyPixelFormat(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 static const char* glPrint(FFinstance* instance) { @@ -405,12 +438,12 @@ static const char* glPrint(FFinstance* instance) #endif } - if(instance->config.glType == FF_GL_TYPE_APPLECGL) + if(instance->config.glType == FF_GL_TYPE_CGL) { - #ifdef FF_HAVE_APPLECGL - return appleCglPrint(instance); + #ifdef FF_HAVE_CGL + return cglPrint(instance); #else - return "fastfetch was compiled without apple-cgl support"; + return "fastfetch was compiled without cgl support"; #endif } @@ -425,9 +458,9 @@ static const char* glPrint(FFinstance* instance) error = glxPrint(instance); #endif - #ifdef FF_HAVE_APPLECGL + #ifdef FF_HAVE_CGL if(error != NULL) - error = appleCglPrint(instance); + error = cglPrint(instance); #endif //We don't use osmesa in auto mode here, because it is a software implementation,