From e4e80568da9641696da79d96960afa938dba3725 Mon Sep 17 00:00:00 2001 From: Mars Date: Wed, 5 Mar 2025 13:44:56 -0500 Subject: [PATCH] mewo --- meson.build | 78 +++++++++++++++++++++++++++++----------------- src/main.cpp | 17 +++++----- src/os/windows.cpp | 18 ++++++++--- src/util/types.h | 8 +++-- 4 files changed, 76 insertions(+), 45 deletions(-) diff --git a/meson.build b/meson.build index 17a3516..1f9416e 100644 --- a/meson.build +++ b/meson.build @@ -5,8 +5,9 @@ project( default_options: [ 'default_library=static', 'warning_level=everything', - 'buildtype=release', + 'buildtype=debug', 'cpp_args=-fvisibility=hidden', + 'cpp_std=c++latest' ], ) @@ -35,28 +36,36 @@ if host_machine.system() == 'darwin' ) endif -common_cpp_args = [ - '-std=c++26', - '-Wno-c++20-compat', - '-Wno-c++20-extensions', - '-Wno-c++98-compat', - '-Wno-c++98-compat-pedantic', - '-Wno-disabled-macro-expansion', - '-Wno-missing-prototypes', - '-Wno-padded', - '-Wno-pre-c++20-compat-pedantic', - '-Wno-switch-default', - '-Wunused-function', - '-fno-strict-enums', - '-nostdlib++', - '-march=native', -] +common_cpp_args = [] -if host_machine.system() == 'windows' - common_cpp_args += ['-DCURL_STATICLIB'] +if cpp.get_id() == 'msvc' or cpp.get_id() == 'clang-cl' + common_cpp_args += [ + '/std:c++latest', + '/Zc:__cplusplus', + '-DNOMINMAX', + ] + + add_project_arguments(common_cpp_args, language: 'cpp') +else + common_cpp_args += [ + '-std=c++26', + '-Wno-c++20-compat', + '-Wno-c++20-extensions', + '-Wno-c++98-compat', + '-Wno-c++98-compat-pedantic', + '-Wno-disabled-macro-expansion', + '-Wno-missing-prototypes', + '-Wno-padded', + '-Wno-pre-c++20-compat-pedantic', + '-Wunused-function', + '-fno-strict-enums', + '-nostdlib++', + '-march=native', + ] + + add_project_arguments(cpp.get_supported_arguments(common_cpp_args), language: 'cpp') endif -add_project_arguments(cpp.get_supported_arguments(common_cpp_args), language: 'cpp') source_file_names = ['src/main.cpp', 'src/config/config.cpp', 'src/config/weather.cpp'] @@ -81,7 +90,6 @@ endforeach deps = [ dependency('fmt', include_type: 'system', static: true), - dependency('openssl', include_type: 'system', static: true), dependency('libcurl', include_type: 'system', static: true), dependency('tomlplusplus', include_type: 'system', static: true), ] @@ -131,23 +139,35 @@ deps += ftxui_dep cmake_opts = cmake.subproject_options() -cmake_opts.add_cmake_defines( - { - 'CMAKE_CXX_FLAGS': '-Wno-everything', - }, -) - -cmake_opts.append_compile_args('cpp', '-Wno-everything') +if cpp.get_id() == 'msvc' + cmake_opts.add_cmake_defines( + { + 'CMAKE_CXX_FLAGS': '/w', + 'REFLECTCPP_USE_STD_EXPECTED': 'ON', + }, + ) + cmake_opts.append_compile_args('cpp', '/w') +else + cmake_opts.add_cmake_defines( + { + 'CMAKE_CXX_FLAGS': '-Wno-everything -std=c++26', + 'REFLECTCPP_USE_STD_EXPECTED': 'ON', + }, + ) + cmake_opts.append_compile_args('cpp', '-Wno-everything -std=c++26') +endif reflectcpp_proj = cmake.subproject('reflectcpp', options: cmake_opts) reflectcpp_dep = reflectcpp_proj.dependency('reflectcpp', include_type: 'system') deps += reflectcpp_dep objc_args = [] -link_args = ['-static-libgcc', '-static-libstdc++', '-static'] +link_args = [] if host_machine.system() == 'darwin' objc_args += ['-fobjc-arc'] +elif host_machine.system() == 'linux' + link_args += ['-static-libgcc', '-static-libstdc++', '-static'] endif executable( diff --git a/src/main.cpp b/src/main.cpp index a2fc31a..5189f14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -37,7 +38,7 @@ namespace { std::time_t now = std::time(nullptr); std::tm localTime; -#ifdef __WIN32__ +#ifdef _WIN32 if (localtime_s(&localTime, &now) != 0) ERROR_LOG("localtime_s failed"); #else @@ -53,11 +54,11 @@ namespace { date.erase(date.begin()); // Append appropriate suffix for the datE - if (date.ends_with("1") && date != "11") + if (date.back() == '1' && date != "11") date += "st"; - else if (date.ends_with("2") && date != "12") + else if (date.back() == '2' && date != "12") date += "nd"; - else if (date.ends_with("3") && date != "13") + else if (date.back() == '3' && date != "13") date += "rd"; else date += "th"; @@ -89,9 +90,9 @@ namespace { data.os_version = GetOSVersion(); data.mem_info = GetMemInfo(); - // Desktop environment info (not relevant for Windows) - data.desktop_environment = std::nullopt; - data.window_manager = "Windows"; + // Desktop environment info + data.desktop_environment = GetDesktopEnvironment(); + data.window_manager = GetWindowManager(); // Parallel execution for disk/shell only auto diskShell = std::async(std::launch::async, [] { @@ -287,7 +288,7 @@ namespace { DEBUG_LOG("DBus error: {}", std::get(error)); #endif -#ifdef __WIN32__ +#ifdef _WIN32 if (std::holds_alternative(error)) DEBUG_LOG("WinRT error: {}", to_string(std::get(error).message())); #endif diff --git a/src/os/windows.cpp b/src/os/windows.cpp index 3255ae2..0009821 100644 --- a/src/os/windows.cpp +++ b/src/os/windows.cpp @@ -1,4 +1,4 @@ -#ifdef __WIN32__ +#ifdef _WIN32 // clang-format off #define WIN32_LEAN_AND_MEAN @@ -11,6 +11,7 @@ #include // clang-format on +#include #include #include #include @@ -113,7 +114,7 @@ namespace { while (true) { if (pe32.th32ProcessID == pid) { // Explicitly cast array to string to avoid implicit array decay - processName = std::string(static_cast(pe32.szExeFile)); + processName = string(reinterpret_cast(pe32.szExeFile)); break; } @@ -239,7 +240,7 @@ fn GetWindowManager() -> string { if (windowManager.empty()) { BOOL compositionEnabled = FALSE; if (SUCCEEDED(DwmIsCompositionEnabled(&compositionEnabled))) - windowManager = compositionEnabled ? "Desktop Window Manager" : "Windows Manager (Basic)"; + windowManager = compositionEnabled ? "DWM" : "Windows Manager (Basic)"; else windowManager = "Windows Manager"; } @@ -252,8 +253,12 @@ fn GetDesktopEnvironment() -> optional { const string buildStr = GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "CurrentBuildNumber"); - if (buildStr.empty()) + DEBUG_LOG("buildStr: {}", buildStr); + + if (buildStr.empty()) { + DEBUG_LOG("Failed to get CurrentBuildNumber from registry"); return std::nullopt; + } try { const i32 build = stoi(buildStr); @@ -287,7 +292,10 @@ fn GetDesktopEnvironment() -> optional { // Older versions return "Classic"; - } catch (...) { return std::nullopt; } + } catch (...) { + DEBUG_LOG("Failed to parse CurrentBuildNumber"); + return std::nullopt; + } } fn GetShell() -> string { diff --git a/src/util/types.h b/src/util/types.h index 48a10ae..e37e29c 100644 --- a/src/util/types.h +++ b/src/util/types.h @@ -4,7 +4,9 @@ #include #include -#ifdef __WIN32__ +#ifdef _WIN32 +#include +#include #include #endif @@ -155,7 +157,7 @@ using LinuxError = std::string; * @brief Represents a macOS-specific error. */ using MacError = std::string; -#elif defined(__WIN32__) +#elif defined(_WIN32) /** * @typedef WindowsError * @brief Represents a Windows-specific error. @@ -170,7 +172,7 @@ using NowPlayingError = std::variant< LinuxError #elif defined(__APPLE__) MacError -#elif defined(__WIN32__) +#elif defined(_WIN32) WindowsError #endif >;