This commit is contained in:
Mars 2025-03-05 13:44:56 -05:00
parent 55f0027969
commit e4e80568da
4 changed files with 76 additions and 45 deletions

View file

@ -5,8 +5,9 @@ project(
default_options: [ default_options: [
'default_library=static', 'default_library=static',
'warning_level=everything', 'warning_level=everything',
'buildtype=release', 'buildtype=debug',
'cpp_args=-fvisibility=hidden', 'cpp_args=-fvisibility=hidden',
'cpp_std=c++latest'
], ],
) )
@ -35,28 +36,36 @@ if host_machine.system() == 'darwin'
) )
endif endif
common_cpp_args = [ 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',
]
if host_machine.system() == 'windows' if cpp.get_id() == 'msvc' or cpp.get_id() == 'clang-cl'
common_cpp_args += ['-DCURL_STATICLIB'] 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 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'] source_file_names = ['src/main.cpp', 'src/config/config.cpp', 'src/config/weather.cpp']
@ -81,7 +90,6 @@ endforeach
deps = [ deps = [
dependency('fmt', include_type: 'system', static: true), dependency('fmt', include_type: 'system', static: true),
dependency('openssl', include_type: 'system', static: true),
dependency('libcurl', include_type: 'system', static: true), dependency('libcurl', include_type: 'system', static: true),
dependency('tomlplusplus', 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 = cmake.subproject_options()
cmake_opts.add_cmake_defines( if cpp.get_id() == 'msvc'
{ cmake_opts.add_cmake_defines(
'CMAKE_CXX_FLAGS': '-Wno-everything', {
}, 'CMAKE_CXX_FLAGS': '/w',
) 'REFLECTCPP_USE_STD_EXPECTED': 'ON',
},
cmake_opts.append_compile_args('cpp', '-Wno-everything') )
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_proj = cmake.subproject('reflectcpp', options: cmake_opts)
reflectcpp_dep = reflectcpp_proj.dependency('reflectcpp', include_type: 'system') reflectcpp_dep = reflectcpp_proj.dependency('reflectcpp', include_type: 'system')
deps += reflectcpp_dep deps += reflectcpp_dep
objc_args = [] objc_args = []
link_args = ['-static-libgcc', '-static-libstdc++', '-static'] link_args = []
if host_machine.system() == 'darwin' if host_machine.system() == 'darwin'
objc_args += ['-fobjc-arc'] objc_args += ['-fobjc-arc']
elif host_machine.system() == 'linux'
link_args += ['-static-libgcc', '-static-libstdc++', '-static']
endif endif
executable( executable(

View file

@ -1,4 +1,5 @@
#include <ctime> #include <ctime>
#include <expected>
#include <fmt/chrono.h> #include <fmt/chrono.h>
#include <fmt/color.h> #include <fmt/color.h>
#include <fmt/core.h> #include <fmt/core.h>
@ -37,7 +38,7 @@ namespace {
std::time_t now = std::time(nullptr); std::time_t now = std::time(nullptr);
std::tm localTime; std::tm localTime;
#ifdef __WIN32__ #ifdef _WIN32
if (localtime_s(&localTime, &now) != 0) if (localtime_s(&localTime, &now) != 0)
ERROR_LOG("localtime_s failed"); ERROR_LOG("localtime_s failed");
#else #else
@ -53,11 +54,11 @@ namespace {
date.erase(date.begin()); date.erase(date.begin());
// Append appropriate suffix for the datE // Append appropriate suffix for the datE
if (date.ends_with("1") && date != "11") if (date.back() == '1' && date != "11")
date += "st"; date += "st";
else if (date.ends_with("2") && date != "12") else if (date.back() == '2' && date != "12")
date += "nd"; date += "nd";
else if (date.ends_with("3") && date != "13") else if (date.back() == '3' && date != "13")
date += "rd"; date += "rd";
else else
date += "th"; date += "th";
@ -89,9 +90,9 @@ namespace {
data.os_version = GetOSVersion(); data.os_version = GetOSVersion();
data.mem_info = GetMemInfo(); data.mem_info = GetMemInfo();
// Desktop environment info (not relevant for Windows) // Desktop environment info
data.desktop_environment = std::nullopt; data.desktop_environment = GetDesktopEnvironment();
data.window_manager = "Windows"; data.window_manager = GetWindowManager();
// Parallel execution for disk/shell only // Parallel execution for disk/shell only
auto diskShell = std::async(std::launch::async, [] { auto diskShell = std::async(std::launch::async, [] {
@ -287,7 +288,7 @@ namespace {
DEBUG_LOG("DBus error: {}", std::get<LinuxError>(error)); DEBUG_LOG("DBus error: {}", std::get<LinuxError>(error));
#endif #endif
#ifdef __WIN32__ #ifdef _WIN32
if (std::holds_alternative<WindowsError>(error)) if (std::holds_alternative<WindowsError>(error))
DEBUG_LOG("WinRT error: {}", to_string(std::get<WindowsError>(error).message())); DEBUG_LOG("WinRT error: {}", to_string(std::get<WindowsError>(error).message()));
#endif #endif

View file

@ -1,4 +1,4 @@
#ifdef __WIN32__ #ifdef _WIN32
// clang-format off // clang-format off
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
@ -11,6 +11,7 @@
#include <cstring> #include <cstring>
// clang-format on // clang-format on
#include <guiddef.h>
#include <winrt/Windows.Foundation.h> #include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Media.Control.h> #include <winrt/Windows.Media.Control.h>
#include <winrt/base.h> #include <winrt/base.h>
@ -113,7 +114,7 @@ namespace {
while (true) { while (true) {
if (pe32.th32ProcessID == pid) { if (pe32.th32ProcessID == pid) {
// Explicitly cast array to string to avoid implicit array decay // Explicitly cast array to string to avoid implicit array decay
processName = std::string(static_cast<const char*>(pe32.szExeFile)); processName = string(reinterpret_cast<const char*>(pe32.szExeFile));
break; break;
} }
@ -239,7 +240,7 @@ fn GetWindowManager() -> string {
if (windowManager.empty()) { if (windowManager.empty()) {
BOOL compositionEnabled = FALSE; BOOL compositionEnabled = FALSE;
if (SUCCEEDED(DwmIsCompositionEnabled(&compositionEnabled))) if (SUCCEEDED(DwmIsCompositionEnabled(&compositionEnabled)))
windowManager = compositionEnabled ? "Desktop Window Manager" : "Windows Manager (Basic)"; windowManager = compositionEnabled ? "DWM" : "Windows Manager (Basic)";
else else
windowManager = "Windows Manager"; windowManager = "Windows Manager";
} }
@ -252,8 +253,12 @@ fn GetDesktopEnvironment() -> optional<string> {
const string buildStr = const string buildStr =
GetRegistryValue(HKEY_LOCAL_MACHINE, R"(SOFTWARE\Microsoft\Windows NT\CurrentVersion)", "CurrentBuildNumber"); 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; return std::nullopt;
}
try { try {
const i32 build = stoi(buildStr); const i32 build = stoi(buildStr);
@ -287,7 +292,10 @@ fn GetDesktopEnvironment() -> optional<string> {
// Older versions // Older versions
return "Classic"; return "Classic";
} catch (...) { return std::nullopt; } } catch (...) {
DEBUG_LOG("Failed to parse CurrentBuildNumber");
return std::nullopt;
}
} }
fn GetShell() -> string { fn GetShell() -> string {

View file

@ -4,7 +4,9 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#ifdef __WIN32__ #ifdef _WIN32
#include <guiddef.h>
#include <variant>
#include <winrt/base.h> #include <winrt/base.h>
#endif #endif
@ -155,7 +157,7 @@ using LinuxError = std::string;
* @brief Represents a macOS-specific error. * @brief Represents a macOS-specific error.
*/ */
using MacError = std::string; using MacError = std::string;
#elif defined(__WIN32__) #elif defined(_WIN32)
/** /**
* @typedef WindowsError * @typedef WindowsError
* @brief Represents a Windows-specific error. * @brief Represents a Windows-specific error.
@ -170,7 +172,7 @@ using NowPlayingError = std::variant<
LinuxError LinuxError
#elif defined(__APPLE__) #elif defined(__APPLE__)
MacError MacError
#elif defined(__WIN32__) #elif defined(_WIN32)
WindowsError WindowsError
#endif #endif
>; >;