From 39e7f60c5a5ba71a0605dedd676efcb15bb9770d Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Tue, 11 Mar 2025 16:48:39 +0000 Subject: [PATCH] build: Get minor MSVC version from host registry --- CMakeLists.txt | 18 ++++++++++++++++-- src/lib/arch/win32/ArchMiscWindows.cpp | 17 ++--------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fb2be894d..9acd2c10d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,8 +94,22 @@ set(REQUIRED_OPENSSL_VERSION 3.0) set(REQUIRED_LIBEI_VERSION 1.3) set(REQUIRED_LIBPORTAL_VERSION 0.8) set(REQUIRED_QT_VERSION 6.7.0) -set(REQUIRED_MSVC_RUNTIME_MAJOR 14) -set(REQUIRED_MSVC_RUNTIME_MINOR 42) + +if (MSVC) + # On Windows, require that the same MSVC runtime is used as on the host. + # Mitigates things like access violations caused by accidental ABI-compatibility breakage. + set(REQUIRED_MSVC_RUNTIME_MAJOR 14) + cmake_host_system_information( + RESULT REQUIRED_MSVC_RUNTIME_MINOR + QUERY WINDOWS_REGISTRY + "HKLM/SOFTWARE/Microsoft/VisualStudio/${REQUIRED_MSVC_RUNTIME_MAJOR}.0/VC/Runtimes/x64" + VALUE "Minor") + if (REQUIRED_MSVC_RUNTIME_MINOR) + message(STATUS "MSVC runtime: ${REQUIRED_MSVC_RUNTIME_MAJOR}.${REQUIRED_MSVC_RUNTIME_MINOR}") + else() + message(FATAL_ERROR "MSVC runtime registry entry not found") + endif() +endif() # Control debug item visibility # When not set logging is forced to DEBUG and show code locations diff --git a/src/lib/arch/win32/ArchMiscWindows.cpp b/src/lib/arch/win32/ArchMiscWindows.cpp index 33fd3ff77..80efd379a 100644 --- a/src/lib/arch/win32/ArchMiscWindows.cpp +++ b/src/lib/arch/win32/ArchMiscWindows.cpp @@ -17,19 +17,6 @@ #include #include -// See table of the compiler versions and the matching runtime DLL versions: -// https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd -#if _MSC_VER >= 1942 // Visual Studio 2022 Update 12 (v17.12.4) -const auto kRequiredMajor = kWindowsRuntimeMajor; -const auto kRequiredMinor = kWindowsRuntimeMinor; -#elif _MSC_VER >= 1920 // Visual Studio 2019 Update 7 (v16.7) -const auto kRequiredMajor = 14; -const auto kRequiredMinor = 27; -#else -#pragma message("MSC version: " STRINGIFY(_MSC_VER)) -#error "Unsupported MSC version" -#endif - // Useful for debugging Windows specific bootstrapping code before the logging system is initialized. // This output can be viewed by attaching a Microsoft debugger or by using the DebugView program. #define MS_LOG_DEBUG(message, ...) \ @@ -606,12 +593,12 @@ void ArchMiscWindows::guardRuntimeVersion() // NOSONAR - `noreturn` is not avail MS_LOG_DEBUG("msvc runtime dll version: %d.%d.%d", currentMajor, currentMinor, currentBuild); - if (currentMajor < kRequiredMajor || currentMinor < kRequiredMinor) { + if (currentMajor < kWindowsRuntimeMajor || currentMinor < kWindowsRuntimeMinor) { const auto message = deskflow::string::sprintf( "Installed Microsoft Visual C++ Runtime v%d.%d.%d is outdated.\n\n" "Minimum required version: v%d.%d\n\n" "Please update to the latest Microsoft Visual C++ Redistributable.", - currentMajor, currentMinor, currentBuild, kRequiredMajor, kRequiredMinor + currentMajor, currentMinor, currentBuild, kWindowsRuntimeMajor, kWindowsRuntimeMinor ); MessageBoxA(nullptr, message.c_str(), "Dependency Error", MB_ICONERROR | MB_OK); exit(1);