From dfabc25ef8d8e30eef8b0de12213ffddfecc3ddb Mon Sep 17 00:00:00 2001 From: Mars Date: Tue, 3 Sep 2024 00:02:09 -0400 Subject: [PATCH] switch to xmake (hopefully everything works) --- .clang-tidy | 1 + .clangd | 4 +- .gitignore | 1 + meson.build | 116 ------------------------------------------ src/config/config.cpp | 19 ++++--- src/main.cpp | 3 +- xmake.lua | 70 +++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 128 deletions(-) delete mode 100644 meson.build create mode 100644 xmake.lua diff --git a/.clang-tidy b/.clang-tidy index 198b03f..d686033 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,7 @@ # noinspection SpellCheckingInspection Checks: > *, + -ctad-maybe-unsupported, -abseil-*, -altera-*, -bugprone-easily-swappable-parameters, diff --git a/.clangd b/.clangd index cdb379e..3cbc5dd 100644 --- a/.clangd +++ b/.clangd @@ -1,2 +1,4 @@ Diagnostics: - Suppress: -Wmissing-template-arg-list-after-template-kw \ No newline at end of file + Suppress: > + -Wmissing-template-arg-list-after-template-kw, + -Wctad-maybe-unsupported diff --git a/.gitignore b/.gitignore index f6a4d28..e67dd66 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .idea/ .vs/ .vscode/ +.xmake/ bin/ build/ diff --git a/meson.build b/meson.build deleted file mode 100644 index f1948c9..0000000 --- a/meson.build +++ /dev/null @@ -1,116 +0,0 @@ -project( - 'draconis++', 'cpp', - version: '0.1.0', - default_options: [ - 'cpp_std=c++20', - 'default_library=static', - 'warning_level=everything', - 'buildtype=release' - ] -) - -cpp = meson.get_compiler('cpp') - -if host_machine.system() == 'darwin' - add_languages('objcpp') - objcpp = meson.get_compiler('objcpp') - add_project_arguments( - objcpp.get_supported_arguments([ - '-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', - '-fvisibility=hidden' - ]), - language: 'objcpp' - ) -endif - -common_cpp_args = [ - '-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', - '-fvisibility=hidden' -] - -if host_machine.system() == 'windows' - common_cpp_args += ['-DCURL_STATICLIB'] -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' -] - -if host_machine.system() == 'linux' - source_file_names += ['src/os/linux.cpp'] -elif host_machine.system() == 'freebsd' - source_file_names += ['src/os/freebsd.cpp'] -elif host_machine.system() == 'darwin' - source_file_names += [ - 'src/os/macos.cpp', - 'src/os/macos/bridge.mm', - ] -elif host_machine.system() == 'windows' - source_file_names += ['src/os/windows.cpp'] -endif - -sources = [] - -foreach file : source_file_names - sources += files(file) -endforeach - -deps = [ - dependency('fmt'), - dependency('libcurl'), - dependency('tomlplusplus'), - dependency('yyjson') -] - -if host_machine.system() == 'darwin' - deps += dependency('Foundation') - deps += dependency('MediaPlayer') - deps += dependency('SystemConfiguration') - deps += dependency('iconv') -elif host_machine.system() == 'linux' or host_machine.system() == 'freebsd' - deps += dependency('sdbus-c++') - deps += dependency('x11') -endif - -objc_args = [] -link_args = [] - -if host_machine.system() == 'darwin' - objc_args += ['-fobjc-arc'] -elif host_machine.system() == 'windows' - windows_sdk_lib_dir = 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/um/x64' - link_args += ['-L' + windows_sdk_lib_dir, '-lwindowsapp', '-static'] -endif - -executable( - 'draconis++', - sources, - objc_args: objc_args, - link_args: link_args, - dependencies: deps -) diff --git a/src/config/config.cpp b/src/config/config.cpp index 7ec87b5..087bb51 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "config.h" @@ -27,17 +28,15 @@ inline fn GetConfigPath() -> std::string { } fn Config::getInstance() -> Config { - try { - fs::path configPath = GetConfigPath(); - configPath /= "draconis++/config.toml"; + fs::path configPath = GetConfigPath(); + configPath /= "draconis++/config.toml"; - const Result result = rfl::toml::load(configPath.string()); + const Result result = rfl::toml::load(configPath.string()); - if (result) - return result.value(); + if (!result) { + fmt::println(stderr, "Failed to load config file: {}", result.error()->what()); + exit(1); + } - fmt::println("Failed to load config file: {}", result.error().value().what()); - } catch (const std::exception& e) { fmt::println("Error getting config path: {}", e.what()); } - - return {}; + return result.value(); } diff --git a/src/main.cpp b/src/main.cpp index 501dd15..fe7f5ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,7 +84,8 @@ fn main() -> i32 { const string nowPlaying = GetNowPlaying(); if (!nowPlaying.empty()) fmt::println("{}", nowPlaying); - else fmt::println("No song playing"); + else + fmt::println("No song playing"); } return 0; diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..a62d8e3 --- /dev/null +++ b/xmake.lua @@ -0,0 +1,70 @@ +---@diagnostic disable: undefined-field, undefined-global + +add_requires("fmt", "libcurl", "tomlplusplus", "yyjson") + +if os.host() == "macosx" then + add_requires("Foundation", "MediaPlayer", "SystemConfiguration", "iconv") +elseif os.host() == "linux" or os.host() == "bsd" then + add_requires("sdbus-c++", "x11") +end + +add_cxxflags( + "-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", + "-fvisibility=hidden" +) + +if os.host() == "macosx" then + add_mxxflags( + "-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", + "-fvisibility=hidden", + "-fobjc-arc" + ) +elseif os.host() == "windows" then + add_cxxflags("-DCURL_STATICLIB") + add_ldflags("-LC:/Program Files (x86)/Windows Kits/10/Lib/10.0.22621.0/um/x64", "-lwindowsapp", "static") +end + +target("draconis++") +set_languages("c++20") +set_kind("binary") + +add_rules("plugin.compile_commands.autoupdate", { outputdir = "." }) +add_rules("mode.debug", "mode.release") + +add_files("src/main.cpp", "src/config/config.cpp", "src/config/weather.cpp") + +if os.host() == "bsd" then + add_files("src/os/freebsd.cpp") +elseif os.host() == "linux" then + add_files("src/os/linux.cpp") +elseif os.host() == "macosx" then + add_files("src/os/macos.cpp", "src/os/macos/bridge.mm") +elseif os.host() == "windows" then + add_files("src/os/windows.cpp") +end + +add_packages("fmt", "libcurl", "tomlplusplus", "yyjson") + +if os.host() == "macosx" then + add_packages("Foundation", "MediaPlayer", "SystemConfiguration", "iconv") +elseif os.host() == "linux" or os.host() == "bsd" then + add_packages("sdbus-c++", "x11") +end