updated build system

This commit is contained in:
Scott E. Graves 2025-02-20 11:55:09 -06:00
parent 731400c009
commit bb79480f76
8 changed files with 260 additions and 225 deletions

View File

@ -1,15 +1,15 @@
set(BINUTILS_VERSION 2.43) set(BINUTILS_VERSION 2.43)
set(BOOST2_MAJOR_VERSION 1)
set(BOOST2_MINOR_VERSION 76)
set(BOOST2_PATCH_VERSION 0)
set(BOOST_MAJOR_VERSION 1) set(BOOST_MAJOR_VERSION 1)
set(BOOST_MINOR_VERSION 87) set(BOOST_MINOR_VERSION 87)
set(BOOST_PATCH_VERSION 0) set(BOOST_PATCH_VERSION 0)
set(BOOST2_MAJOR_VERSION 1)
set(BOOST2_MINOR_VERSION 76)
set(BOOST2_PATCH_VERSION 0)
set(CPP_HTTPLIB_VERSION 0.18.1) set(CPP_HTTPLIB_VERSION 0.18.1)
set(CURL2_VERSION 8_11_0)
set(CURL_VERSION 8.11.0) set(CURL_VERSION 8.11.0)
set(EXPAT2_VERSION 2_6_4) set(CURL2_VERSION 8_11_0)
set(EXPAT_VERSION 2.6.4) set(EXPAT_VERSION 2.6.4)
set(EXPAT2_VERSION 2_6_4)
set(GCC_VERSION 14.2.0) set(GCC_VERSION 14.2.0)
set(GTEST_VERSION 1.15.2) set(GTEST_VERSION 1.15.2)
set(ICU_VERSION 76-1) set(ICU_VERSION 76-1)

View File

@ -1,24 +1,3 @@
/*
Copyright <2018-2025> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#if defined(PROJECT_ENABLE_CURL) #if defined(PROJECT_ENABLE_CURL)
#include "curl/curl.h" #include "curl/curl.h"
#endif // defined(PROJECT_ENABLE_CURL) #endif // defined(PROJECT_ENABLE_CURL)
@ -44,6 +23,7 @@
#if defined(PROJECT_ENABLE_SPDLOG) #if defined(PROJECT_ENABLE_SPDLOG)
#include <chrono> #include <chrono>
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#endif // defined(PROJECT_ENABLE_SPDLOG) #endif // defined(PROJECT_ENABLE_SPDLOG)
@ -53,6 +33,12 @@
#include "utils/path.hpp" #include "utils/path.hpp"
#endif // defined(PROJECT_REQUIRE_ALPINE) && !defined (PROJECT_IS_MINGW) #endif // defined(PROJECT_REQUIRE_ALPINE) && !defined (PROJECT_IS_MINGW)
#if defined(PROJECT_ENABLE_SPDLOG)
namespace {
std::shared_ptr<spdlog::logger> console_sink;
}
#endif // defined(PROJECT_ENABLE_SPDLOG)
namespace monitarr { namespace monitarr {
auto project_initialize() -> bool { auto project_initialize() -> bool {
#if defined(PROJECT_REQUIRE_ALPINE) && !defined(PROJECT_IS_MINGW) #if defined(PROJECT_REQUIRE_ALPINE) && !defined(PROJECT_IS_MINGW)
@ -73,6 +59,8 @@ auto project_initialize() -> bool {
spdlog::drop_all(); spdlog::drop_all();
spdlog::flush_every(std::chrono::seconds(10)); spdlog::flush_every(std::chrono::seconds(10));
spdlog::set_pattern("%Y-%m-%d|%T.%e|%^%l%$|%v"); spdlog::set_pattern("%Y-%m-%d|%T.%e|%^%l%$|%v");
console_sink = spdlog::stdout_color_mt("console");
#endif // defined(PROJECT_ENABLE_SPDLOG) #endif // defined(PROJECT_ENABLE_SPDLOG)
#if defined(PROJECT_ENABLE_LIBSODIUM) #if defined(PROJECT_ENABLE_LIBSODIUM)

View File

@ -79,9 +79,6 @@ auto main(int argc, char **argv) -> int {
auto ret{0}; auto ret{0};
try { try {
spdlog::drop("console");
auto console = spdlog::stdout_color_mt("console");
std::string cfg_file; std::string cfg_file;
auto cfg{load_config(cfg_file)}; auto cfg{load_config(cfg_file)};
if (has_arg("-b", argc, argv)) { if (has_arg("-b", argc, argv)) {

View File

@ -1,117 +0,0 @@
#include "utils/config.hpp"
#include "utils/error.hpp"
namespace monitarr {
struct monitarr_exception_handler final
: public utils::error::i_exception_handler {
void handle_debug(std::string_view function_name,
std::string_view msg) const override {
spdlog::get("console")->debug(
utils::error::create_error_message(function_name, {msg}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->debug(utils::error::create_error_message(function_name, {msg}));
}
void handle_error(std::string_view function_name,
std::string_view msg) const override {
spdlog::get("console")->error(
utils::error::create_error_message(function_name, {msg}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->error(utils::error::create_error_message(function_name, {msg}));
}
void handle_exception(std::string_view function_name) const override {
spdlog::get("console")->error(utils::error::create_error_message(
function_name, {
"exception",
"unknown exception",
}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->error(utils::error::create_error_message(function_name,
{
"exception",
"unknown exception",
}));
}
void handle_exception(std::string_view function_name,
const std::exception &ex) const override {
spdlog::get("console")->error(utils::error::create_error_message(
function_name, {
"exception",
(ex.what() == nullptr ? "unknown" : ex.what()),
}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->error(utils::error::create_error_message(
function_name, {
"exception",
(ex.what() == nullptr ? "unknown" : ex.what()),
}));
}
void handle_info(std::string_view function_name,
std::string_view msg) const override {
spdlog::get("console")->info(
utils::error::create_error_message(function_name, {msg}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->info(utils::error::create_error_message(function_name, {msg}));
}
void handle_trace(std::string_view function_name,
std::string_view msg) const override {
spdlog::get("console")->trace(
utils::error::create_error_message(function_name, {msg}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->trace(utils::error::create_error_message(function_name, {msg}));
}
void handle_warn(std::string_view function_name,
std::string_view msg) const override {
spdlog::get("console")->warn(
utils::error::create_error_message(function_name, {msg}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->warn(utils::error::create_error_message(function_name, {msg}));
}
};
static const auto handler = ([]() {
auto ptr = std::make_unique<monitarr_exception_handler>();
utils::error::set_exception_handler(ptr.get());
return ptr;
})();
} // namespace monitarr

View File

@ -98,7 +98,35 @@ struct iostream_exception_handler final : public i_exception_handler {
#endif // defined(PROJECT_ENABLE_V2_ERRORS) #endif // defined(PROJECT_ENABLE_V2_ERRORS)
}; };
#if defined(PROJECT_ENABLE_SPDLOG) && defined(PROJECT_ENABLE_V2_ERRORS)
struct spdlog_exception_handler final : public i_exception_handler {
void handle_debug(std::string_view function_name,
std::string_view msg) const override;
void handle_error(std::string_view function_name,
std::string_view msg) const override;
void handle_exception(std::string_view function_name) const override;
void handle_exception(std::string_view function_name,
const std::exception &ex) const override;
void handle_info(std::string_view function_name,
std::string_view msg) const override;
void handle_trace(std::string_view function_name,
std::string_view msg) const override;
void handle_warn(std::string_view function_name,
std::string_view msg) const override;
};
#endif // defined(PROJECT_ENABLE_SPDLOG) && defined(PROJECT_ENABLE_V2_ERRORS)
#if defined(PROJECT_ENABLE_SPDLOG) && defined(PROJECT_ENABLE_V2_ERRORS)
inline const spdlog_exception_handler default_exception_handler{};
#else // !defined(PROJECT_ENABLE_SPDLOG) || !defined(PROJECT_ENABLE_V2_ERRORS)
inline const iostream_exception_handler default_exception_handler{}; inline const iostream_exception_handler default_exception_handler{};
#endif // defined(PROJECT_ENABLE_SPDLOG) && defined(PROJECT_ENABLE_V2_ERRORS)
#if defined(PROJECT_ENABLE_TESTING) #if defined(PROJECT_ENABLE_TESTING)
extern std::atomic<const i_exception_handler *> exception_handler; extern std::atomic<const i_exception_handler *> exception_handler;

View File

@ -22,85 +22,6 @@
#include "utils/error.hpp" #include "utils/error.hpp"
namespace monitarr::utils::error { namespace monitarr::utils::error {
#if defined(PROJECT_ENABLE_V2_ERRORS)
void iostream_exception_handler::handle_debug(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"debug",
function_name,
msg,
})
<< std::endl;
}
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
void iostream_exception_handler::handle_error(std::string_view function_name,
std::string_view msg) const {
std::cerr << create_error_message({
"error",
function_name,
msg,
})
<< std::endl;
}
void iostream_exception_handler::handle_exception(
std::string_view function_name) const {
std::cerr << create_error_message({
"error",
function_name,
"exception",
"unknown",
})
<< std::endl;
}
void iostream_exception_handler::handle_exception(
std::string_view function_name, const std::exception &ex) const {
std::cerr << create_error_message({
"error",
function_name,
"exception",
(ex.what() == nullptr ? "unknown" : ex.what()),
})
<< std::endl;
}
#if defined(PROJECT_ENABLE_V2_ERRORS)
void iostream_exception_handler::handle_info(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"info",
function_name,
msg,
})
<< std::endl;
}
void iostream_exception_handler::handle_trace(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"trace",
function_name,
msg,
})
<< std::endl;
}
void iostream_exception_handler::handle_warn(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"warn",
function_name,
msg,
})
<< std::endl;
}
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
std::atomic<const i_exception_handler *> exception_handler{
&default_exception_handler};
auto create_error_message(std::vector<std::string_view> items) -> std::string { auto create_error_message(std::vector<std::string_view> items) -> std::string {
std::stringstream stream{}; std::stringstream stream{};
for (std::size_t idx = 0U; idx < items.size(); ++idx) { for (std::size_t idx = 0U; idx < items.size(); ++idx) {

View File

@ -0,0 +1,211 @@
/*
Copyright <2018-2025> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "utils/config.hpp"
#include "utils/error.hpp"
namespace monitarr::utils::error {
std::atomic<const i_exception_handler *> exception_handler{
&default_exception_handler};
#if defined(PROJECT_ENABLE_V2_ERRORS)
void iostream_exception_handler::handle_debug(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"debug",
function_name,
msg,
})
<< std::endl;
}
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
void iostream_exception_handler::handle_error(std::string_view function_name,
std::string_view msg) const {
std::cerr << create_error_message({
"error",
function_name,
msg,
})
<< std::endl;
}
void iostream_exception_handler::handle_exception(
std::string_view function_name) const {
std::cerr << create_error_message({
"error",
function_name,
"exception",
"unknown",
})
<< std::endl;
}
void iostream_exception_handler::handle_exception(
std::string_view function_name, const std::exception &ex) const {
std::cerr << create_error_message({
"error",
function_name,
"exception",
(ex.what() == nullptr ? "unknown" : ex.what()),
})
<< std::endl;
}
#if defined(PROJECT_ENABLE_V2_ERRORS)
void iostream_exception_handler::handle_info(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"info",
function_name,
msg,
})
<< std::endl;
}
void iostream_exception_handler::handle_trace(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"trace",
function_name,
msg,
})
<< std::endl;
}
void iostream_exception_handler::handle_warn(std::string_view function_name,
std::string_view msg) const {
std::cout << create_error_message({
"warn",
function_name,
msg,
})
<< std::endl;
}
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
#if defined(PROJECT_ENABLE_SPDLOG) && defined(PROJECT_ENABLE_V2_ERRORS)
void spdlog_exception_handler::handle_debug(std::string_view function_name,
std::string_view msg) const {
spdlog::get("console")->debug(
utils::error::create_error_message(function_name, {msg}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->debug(utils::error::create_error_message(function_name, {msg}));
}
void spdlog_exception_handler::handle_error(std::string_view function_name,
std::string_view msg) const {
spdlog::get("console")->error(
utils::error::create_error_message(function_name, {msg}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->error(utils::error::create_error_message(function_name, {msg}));
}
void spdlog_exception_handler::handle_exception(
std::string_view function_name) const {
spdlog::get("console")->error(
utils::error::create_error_message(function_name, {
"exception",
"unknown exception",
}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->error(
utils::error::create_error_message(function_name, {
"exception",
"unknown exception",
}));
}
void spdlog_exception_handler::handle_exception(
std::string_view function_name, const std::exception &ex) const {
spdlog::get("console")->error(utils::error::create_error_message(
function_name, {
"exception",
(ex.what() == nullptr ? "unknown" : ex.what()),
}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->error(utils::error::create_error_message(
function_name, {
"exception",
(ex.what() == nullptr ? "unknown" : ex.what()),
}));
}
void spdlog_exception_handler::handle_info(std::string_view function_name,
std::string_view msg) const {
spdlog::get("console")->info(
utils::error::create_error_message(function_name, {msg}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->info(utils::error::create_error_message(function_name, {msg}));
}
void spdlog_exception_handler::handle_trace(std::string_view function_name,
std::string_view msg) const {
spdlog::get("console")->trace(
utils::error::create_error_message(function_name, {msg}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->trace(utils::error::create_error_message(function_name, {msg}));
}
void spdlog_exception_handler::handle_warn(std::string_view function_name,
std::string_view msg) const {
spdlog::get("console")->warn(
utils::error::create_error_message(function_name, {msg}));
auto file = spdlog::get("file");
if (not file) {
return;
}
file->warn(utils::error::create_error_message(function_name, {msg}));
}
#endif // defined(PROJECT_ENABLE_SPDLOG) && defined(PROJECT_ENABLE_V2_ERRORS)
} // namespace monitarr::utils::error

View File

@ -29,10 +29,17 @@ TEST(utils_error, check_default_exception_handler) {
EXPECT_TRUE(utils::error::get_exception_handler() != nullptr); EXPECT_TRUE(utils::error::get_exception_handler() != nullptr);
if (&utils::error::default_exception_handler == if (&utils::error::default_exception_handler ==
utils::error::get_exception_handler()) { utils::error::get_exception_handler()) {
#if defined(PROJECT_ENABLE_SPDLOG) && defined(PROJECT_ENABLE_V2_ERRORS)
auto default_handler_is_spdlog =
is_decay_equ<decltype(utils::error::default_exception_handler),
utils::error::spdlog_exception_handler>;
EXPECT_TRUE(default_handler_is_spdlog);
#else // !defined(PROJECT_ENABLE_SPDLOG) || !defined(PROJECT_ENABLE_V2_ERRORS)
auto default_handler_is_iostream = auto default_handler_is_iostream =
is_decay_equ<decltype(utils::error::default_exception_handler), is_decay_equ<decltype(utils::error::default_exception_handler),
utils::error::iostream_exception_handler>; utils::error::iostream_exception_handler>;
EXPECT_TRUE(default_handler_is_iostream); EXPECT_TRUE(default_handler_is_iostream);
#endif
} }
} }