From 8423efb6867d566514ba80f632d9cf2e7ad5efd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 7 Jan 2026 11:05:12 +0800 Subject: [PATCH] CMake (Windows): introduces a flag to remove Win7 compat mode --- CMakeLists.txt | 17 +++++++++++++++-- src/common/impl/processing_windows.c | 4 ++-- src/detection/cpuusage/cpuusage_windows.c | 2 +- src/detection/gpu/gpu_windows.c | 4 ++-- src/detection/uptime/uptime_windows.c | 2 +- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14a8496e8..1b7603f2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,13 @@ cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID OR Dragon cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF) cmake_dependent_option(ENABLE_PCIACCESS "Enable libpciaccess" ON "GNU" OFF) +if(WIN32) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") + set(WIN32_WOA ON) + endif() + cmake_dependent_option(ENABLE_WIN7_COMPAT "Enable Windows 7 compatibility" OFF "WIN32_WOA" ON) +endif() + option(ENABLE_ZLIB "Enable zlib" ON) option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF) option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF) @@ -1419,6 +1426,13 @@ if(WIN32) if(HAVE_MSVC_MSIZE) target_compile_definitions(libfastfetch PUBLIC FF_HAVE_MSVC_MSIZE=1) endif() + + if(ENABLE_WIN7_COMPAT) + message(STATUS "Enabling Windows 7 compatibility mode") + target_compile_definitions(libfastfetch PUBLIC FF_WIN7_COMPAT=1) + else() + target_compile_definitions(libfastfetch PUBLIC FF_WIN7_COMPAT=0) + endif() else() check_function_exists(malloc_usable_size HAVE_MALLOC_USABLE_SIZE) if(HAVE_MALLOC_USABLE_SIZE) @@ -1692,8 +1706,7 @@ elseif(WIN32) PRIVATE "propsys" PRIVATE "secur32" ) - if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") - # WoA only works on Windows 10 or higher + if(NOT ENABLE_WIN7_COMPAT) target_link_libraries(libfastfetch PRIVATE "mincore" ) diff --git a/src/common/impl/processing_windows.c b/src/common/impl/processing_windows.c index 4a5ec4373..b128d1438 100644 --- a/src/common/impl/processing_windows.c +++ b/src/common/impl/processing_windows.c @@ -152,7 +152,7 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) switch (GetLastError()) { case ERROR_IO_PENDING: - #if __aarch64__ + #if !FF_WIN7_COMPAT if (!GetOverlappedResultEx(hChildPipeRead, &overlapped, &nRead, timeout < 0 ? INFINITE : (DWORD) timeout, FALSE)) #else // To support Windows 7 @@ -172,7 +172,7 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer) CancelIo(hChildPipeRead); TerminateProcess(hProcess, 1); return "GetOverlappedResult" - #if __aarch64__ + #if !FF_WIN7_COMPAT "Ex" #endif "(hChildPipeRead) failed"; diff --git a/src/detection/cpuusage/cpuusage_windows.c b/src/detection/cpuusage/cpuusage_windows.c index 1679350d4..89ce1a1a0 100644 --- a/src/detection/cpuusage/cpuusage_windows.c +++ b/src/detection/cpuusage/cpuusage_windows.c @@ -155,7 +155,7 @@ static const char* getInfoByPerflib(FFlist* cpuTimes) const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { - #if __aarch64__ + #if !FF_WIN7_COMPAT static uint8_t winver = 10; // Assume Windows 10 or later for WoA #else static uint8_t winver = 0; diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index 75f0c2b8c..85ce19f1d 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -330,7 +330,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* if (gpu->type == FF_GPU_TYPE_UNKNOWN && adapterLuid > 0) { FF_DEBUG("Trying to determine GPU type using D3DKMT APIs"); - #if __aarch64__ + #if !FF_WIN7_COMPAT D3DKMT_OPENADAPTERFROMLUID openAdapterFromLuid = { .AdapterLuid = *(LUID*)&adapterLuid }; if (NT_SUCCESS(D3DKMTOpenAdapterFromLuid(&openAdapterFromLuid))) #else @@ -438,7 +438,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* FF_DEBUG("Failed to get GPU temperature or temperature is 0"); } } - #if !__aarch64__ + #if FF_WIN7_COMPAT } else { diff --git a/src/detection/uptime/uptime_windows.c b/src/detection/uptime/uptime_windows.c index 030b58bed..c5cd7245a 100644 --- a/src/detection/uptime/uptime_windows.c +++ b/src/detection/uptime/uptime_windows.c @@ -7,7 +7,7 @@ const char* ffDetectUptime(FFUptimeResult* result) { - #ifndef __aarch64__ + #if FF_WIN7_COMPAT HMODULE hKernelBase = GetModuleHandleW(L"KernelBase.dll"); if (__builtin_expect(!!hKernelBase, true)) {