diff --git a/.github/workflows/build-no-features-test.yml b/.github/workflows/build-no-features-test.yml index 499cdc14e3..755c90a406 100644 --- a/.github/workflows/build-no-features-test.yml +++ b/.github/workflows/build-no-features-test.yml @@ -20,6 +20,10 @@ jobs: - name: uname -a run: uname -a + # ENABLE_DRM=OFF still permits GPU detection via the kernel headers. + - name: hide kernel DRM headers + run: sudo dpkg-divert --local --rename --add /usr/include/drm/drm.h + - name: configure project run: cmake -DSET_TWEAK=Off -DBUILD_TESTS=On -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_C_FLAGS="-fno-pie" -DCMAKE_EXE_LINKER_FLAGS="-no-pie" . -DENABLE_VULKAN=OFF -DENABLE_WAYLAND=OFF -DENABLE_XCB_RANDR=OFF -DENABLE_XCB=OFF -DENABLE_XRANDR=OFF -DENABLE_X11=OFF -DENABLE_DRM=OFF -DENABLE_DRM_AMDGPU=OFF -DENABLE_GIO=OFF -DENABLE_DCONF=OFF -DENABLE_DBUS=OFF -DENABLE_SQLITE3=OFF -DENABLE_RPM=OFF -DENABLE_IMAGEMAGICK7=OFF -DENABLE_IMAGEMAGICK6=OFF -DENABLE_CHAFA=OFF -DENABLE_ZLIB=OFF -DENABLE_EGL=OFF -DENABLE_GLX=OFF -DENABLE_OPENCL=OFF -DENABLE_FREETYPE=OFF -DENABLE_ELF=OFF -DENABLE_EET=OFF -DENABLE_THREADS=OFF -DENABLE_IMAGE_LOGO=OFF diff --git a/CHANGELOG.md b/CHANGELOG.md index b2bfed4380..27be11ddaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased Bugfixes: +* Fixed building on Linux when neither libdrm nor the kernel DRM headers are installed. (#2766, GPU, Linux) * Fixed building with dconf enabled but gio disabled (`-DENABLE_GIO=OFF`). (General) # 2.72.0 diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index 584a18b70b..93e7ccfe01 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -86,6 +86,7 @@ void ffGPUFillVendorAndName(uint8_t subclass, uint16_t vendor, uint16_t device, void ffGPUQueryAmdGpuName(uint16_t deviceId, uint8_t revisionId, FFGPUResult* gpu); #if FF_HAVE_DRM || __has_include() + #define FF_GPU_HAS_DRM 1 const char* ffDrmDetectRadeon(const FFGPUOptions* options, FFGPUResult* gpu, const char* renderPath); const char* ffDrmDetectAmdgpu(const FFGPUOptions* options, FFGPUResult* gpu, const char* renderPath); const char* ffDrmDetectI915(FFGPUResult* gpu, int fd); diff --git a/src/detection/gpu/gpu_drm.c b/src/detection/gpu/gpu_drm.c index 15d31a31a2..3a51e46806 100644 --- a/src/detection/gpu/gpu_drm.c +++ b/src/detection/gpu/gpu_drm.c @@ -1,6 +1,6 @@ #include "gpu.h" -#if FF_HAVE_DRM || __has_include() +#ifdef FF_GPU_HAS_DRM #include #include @@ -365,7 +365,7 @@ const char* ffDrmDetectNouveau(FFGPUResult* gpu, int fd) { return nullptr; } -#endif // FF_HAVE_DRM +#endif // FF_GPU_HAS_DRM #include "gpu_driver_specific.h" diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 007e0633a4..28ec982c33 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -51,7 +51,8 @@ static bool detectDriverFromSysfs(FFstrbuf* result, FFstrbuf* pciDir, FFstrbuf* return true; } -[[maybe_unused]] static const char* drmFindRenderFromCard(const char* drmCardKey, FFstrbuf* result) { +#ifdef FF_GPU_HAS_DRM +static const char* drmFindRenderFromCard(const char* drmCardKey, FFstrbuf* result) { char path[PATH_MAX]; sprintf(path, "/sys/class/drm/%s/device/drm", drmCardKey); FF_AUTO_CLOSE_DIR DIR* dirp = opendir(path); @@ -83,6 +84,7 @@ static const char* drmDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult return ffDrmDetectAmdgpu(options, gpu, buffer->chars); } } +#endif static void pciDetectAmdSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) { // https://www.kernel.org/doc/html/v5.10/gpu/amdgpu.html#mem-info-vis-vram-total @@ -210,6 +212,7 @@ static void pciDetectIntelSpecific(const FFGPUOptions* options, FFGPUResult* gpu } } +#ifdef FF_GPU_HAS_DRM static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey, FFstrbuf* buffer) { ffStrbufSetS(buffer, "/dev/dri/"); ffStrbufAppendS(buffer, drmKey); @@ -227,6 +230,7 @@ static const char* drmDetectIntelSpecific(FFGPUResult* gpu, const char* drmKey, FF_DEBUG("Unknown Intel GPU driver"); return "Unknown Intel GPU driver"; } +#endif static const char* pciDetectTempGeneral(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) { if (options->temp) { @@ -255,6 +259,7 @@ static const char* pciDetectTempGeneral(const FFGPUOptions* options, FFGPUResult return nullptr; } +#ifdef FF_GPU_HAS_DRM static const char* drmDetectNouveauSpecific(FFGPUResult* gpu, const char* drmKey, FFstrbuf* buffer) { ffStrbufSetS(buffer, "/dev/dri/"); ffStrbufAppendS(buffer, drmKey); @@ -266,6 +271,7 @@ static const char* drmDetectNouveauSpecific(FFGPUResult* gpu, const char* drmKey return ffDrmDetectNouveau(gpu, fd); } +#endif static const char* pciDetectZxSpecific(const FFGPUOptions* options, FFGPUResult* gpu, FFstrbuf* pciDir, FFstrbuf* buffer) { gpu->type = FF_GPU_TYPE_INTEGRATED; @@ -479,9 +485,11 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_AMD) { bool ok = false; +#ifdef FF_GPU_HAS_DRM if (drmKey && options->driverSpecific) { ok = drmDetectAmdSpecific(options, gpu, drmKey, buffer) == nullptr; } +#endif if (!ok) { pciDetectAmdSpecific(options, gpu, deviceDir, buffer); @@ -500,14 +508,18 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf } else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_INTEL) { pciDetectIntelSpecific(options, gpu, deviceDir, buffer, drmKey); ffStrbufSubstrBefore(deviceDir, drmDirPathLength); +#ifdef FF_GPU_HAS_DRM if (options->driverSpecific && drmKey) { drmDetectIntelSpecific(gpu, drmKey, buffer); } +#endif } else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && ffStrbufEqualS(&gpu->driver, "nouveau")) { pciDetectTempGeneral(options, gpu, deviceDir, buffer); +#ifdef FF_GPU_HAS_DRM if (options->driverSpecific && drmKey) { drmDetectNouveauSpecific(gpu, drmKey, buffer); } +#endif } else if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_ZHAOXIN && ffStrbufStartsWithS(&gpu->driver, "zx")) { pciDetectTempGeneral(options, gpu, deviceDir, buffer); pciDetectZxSpecific(options, gpu, deviceDir, buffer); @@ -573,12 +585,14 @@ static const char* detectPci(const FFGPUOptions* options, FFlist* gpus, FFstrbuf } ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_APPLE); + #ifdef FF_GPU_HAS_DRM ffStrbufSetS(buffer, "/dev/dri/"); ffStrbufAppendS(buffer, drmKey); FF_AUTO_CLOSE_FD int fd = open(buffer->chars, O_RDONLY | O_CLOEXEC); if (fd >= 0) { return ffDrmDetectAsahi(gpu, fd); } + #endif return nullptr; }