diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fc84ca60..ace8ca515 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,8 @@ 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_OPENCL "Enable opencl" ON "LINUX" OFF) +cmake_dependent_option(ENABLE_APPLECGL "Enable apple-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 option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds @@ -309,10 +310,34 @@ ff_check_lib(IMAGEMAGICK7 MagickCore-7.Q16HDRI MagickCore-7.Q16 /usr/lib/imagema 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) -ff_check_lib(EGL egl) -ff_check_lib(GLX glx) -ff_check_lib(OSMESA osmesa) -ff_check_lib(OPENCL OpenCL) + +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() target_include_directories(libfastfetch PUBLIC ${PROJECT_BINARY_DIR} diff --git a/src/common/init.c b/src/common/init.c index 3a769de11..76701d4bc 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -430,6 +430,9 @@ void ffListFeatures() #ifdef FF_HAVE_OSMESA "osmesa\n" #endif + #ifdef FF_HAVE_APPLECGL + "apple-cgl\n" + #endif #ifdef FF_HAVE_OPENCL "opencl\n" #endif diff --git a/src/fastfetch.c b/src/fastfetch.c index 6b674f321..6a8a8f30f 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1258,6 +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, NULL ); } diff --git a/src/fastfetch.h b/src/fastfetch.h index d47a689e6..61ac46ad9 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -50,7 +50,8 @@ typedef enum FFGLType FF_GL_TYPE_AUTO, FF_GL_TYPE_EGL, FF_GL_TYPE_GLX, - FF_GL_TYPE_OSMESA + FF_GL_TYPE_OSMESA, + FF_GL_TYPE_APPLECGL } FFGLType; typedef struct FFModuleArgs diff --git a/src/modules/opencl.c b/src/modules/opencl.c index 8fafe0d62..93e527ec0 100644 --- a/src/modules/opencl.c +++ b/src/modules/opencl.c @@ -10,7 +10,11 @@ #include #define CL_TARGET_OPENCL_VERSION 100 +#ifdef __APPLE__ +#include +#else #include +#endif typedef struct OpenCLData { @@ -75,13 +79,21 @@ static const char* printOpenCL(FFinstance* instance) { OpenCLData data; + #ifdef __APPLE__ + 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 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 d461c92e7..f7a3f41d1 100644 --- a/src/modules/opengl.c +++ b/src/modules/opengl.c @@ -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) +#if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA) || defined(FF_HAVE_APPLECGL) #define FF_HAVE_GL 1 #include "common/library.h" #ifdef __APPLE__ @@ -337,6 +337,45 @@ static const char* osMesaPrint(FFinstance* instance) #endif //FF_HAVE_OSMESA +#ifdef FF_HAVE_APPLECGL + +#include + +static const char* appleCglPrint(FFinstance* instance) +{ + CGLPixelFormatAttribute attrs[] = { + kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, + kCGLPFAAccelerated, + 0 + }; + CGLPixelFormatObj pix; + GLint num; + if (CGLChoosePixelFormat(attrs, &pix, &num) != kCGLNoError) { + return "CGLChoosePixelFormat() failed"; + } + + CGLContextObj ctx; + if (CGLCreateContext(pix, NULL, &ctx) != kCGLNoError) { + return "CGLCreateContext() failed"; + } + if (CGLSetCurrentContext(ctx) != kCGLNoError) { + return "CGLSetCurrentContext() failed"; + } + + GLData glData = { + .ffglGetString = glGetString + }; + + const char* error = glHandlePrint(instance, &glData); + + CGLDestroyContext(ctx); + CGLDestroyPixelFormat(pix); + + return error; +} + +#endif //FF_HAVE_APPLECGL + static const char* glPrint(FFinstance* instance) { if(instance->config.glType == FF_GL_TYPE_GLX) @@ -366,6 +405,15 @@ static const char* glPrint(FFinstance* instance) #endif } + if(instance->config.glType == FF_GL_TYPE_APPLECGL) + { + #ifdef FF_HAVE_APPLECGL + return appleCglPrint(instance); + #else + return "fastfetch was compiled without apple-cgl support"; + #endif + } + const char* error = ""; // not NULL dummy value #ifdef FF_HAVE_EGL @@ -377,6 +425,11 @@ static const char* glPrint(FFinstance* instance) error = glxPrint(instance); #endif + #ifdef FF_HAVE_APPLECGL + if(error != NULL) + error = appleCglPrint(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