From 639aac68ca51a3d1203270c988cd571de94638b3 Mon Sep 17 00:00:00 2001 From: Lukas Forsberg Date: Mon, 23 Feb 2026 16:11:23 +0100 Subject: [PATCH] added version number to build --- CMakeLists.txt | 5 +++++ PKGBUILD | 5 +++-- source/Application.hpp | 26 ++++++++++++++++++++++++++ source/json_settings.cpp | 8 ++++---- source/main.cpp | 27 +++++++++++++++------------ 5 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 source/Application.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3410f1b..fe39611 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,8 +87,13 @@ target_link_options(${TARGET_NAME} PRIVATE $<$:-flto=auto> ) +if(NOT DEFINED APP_VERSION) + set(APP_VERSION "0.0.0") +endif() + target_compile_definitions(${TARGET_NAME} PRIVATE APPLICATION_NAME="${TARGET_NAME}" + APP_VERSION="${APP_VERSION}" SQLITE_THREADSAFE=1 # build sqlite with thread safty ASIO_STANDALONE # use asio without boost CROW_ENABLE_COMPRESSION # enable compression part of crow diff --git a/PKGBUILD b/PKGBUILD index b66d3a4..64637b5 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: Lukas Forsberg lukas96.forsberg@gmail.com pkgname=shadowrun-server -pkgver=0.1.3 +pkgver=0.1.4 pkgrel=1 arch=('x86_64') depends=() @@ -18,7 +18,8 @@ build() { cmake -S "${srcdir}" \ -B build \ -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=/usr + -DCMAKE_INSTALL_PREFIX=/usr \ + -DAPP_VERSION=${pkgver} cmake --build build } diff --git a/source/Application.hpp b/source/Application.hpp new file mode 100644 index 0000000..daf9560 --- /dev/null +++ b/source/Application.hpp @@ -0,0 +1,26 @@ +#ifndef __APPVERSION_H__ +#define __APPVERSION_H__ + +#include + +namespace Application { + +#ifndef APP_VERSION + #define APP_VERSION "0.0.0" +#endif + +#ifndef APPLICATION_NAME + #define APPLICATION_NAME "app" +#endif + +inline std::string version(){ + return std::string(APP_VERSION); +} + +inline std::string name(){ + return std::string(APPLICATION_NAME); +} + +} + +#endif // __APPVERSION_H__ \ No newline at end of file diff --git a/source/json_settings.cpp b/source/json_settings.cpp index 313f19a..28be498 100644 --- a/source/json_settings.cpp +++ b/source/json_settings.cpp @@ -1,8 +1,8 @@ #include #include "json.hpp" #include "json_settings.h" -#include "crow/logging.h" #include "utils.hpp" +#include using namespace std; using json = nlohmann::json; @@ -19,7 +19,7 @@ Settings AppSettings::deafult(){ Settings AppSettings::load() { ifstream file(settingsFile); if (!file.is_open()) { - CROW_LOG_ERROR << "Failed to load settings file" << settingsFile << " Loading default settings"; + std::cerr << "Failed to load settings file" << settingsFile << " Loading default settings" << std::endl; return AppSettings::deafult(); } @@ -29,14 +29,14 @@ Settings AppSettings::load() { auto result = utils::parseJson(fileContents); if(!result){ - CROW_LOG_ERROR << "failed to parse settings file, Loading default settings"; + std::cerr << "failed to parse settings file, Loading default settings" << std::endl; return AppSettings::deafult(); } try { return result.value().get(); } catch (...) { - CROW_LOG_ERROR << "failed to parse settings file, Loading default settings"; + std::cerr << "failed to parse settings file, Loading default settings"; return AppSettings::deafult(); } } diff --git a/source/main.cpp b/source/main.cpp index e1b69c4..543012f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -7,18 +7,21 @@ #include "ShadowrunApi.hpp" #include "databasepool.h" #include "crow/compression.h" +#include "Application.hpp" using namespace std; int main() { + std::cout << "Launching " << Application::name() << " version: " << Application::version() << std::endl; + AppSettings::Settings settings = AppSettings::load(); crow::App app; - + // init cors auto& cors = app.get_middleware(); cors.global() - .headers("Content-Type", "Authorization") - .methods("GET"_method, "POST"_method, "PUT"_method, "DELETE"_method, "OPTIONS"_method) + .headers("Content-Type", "Authorization") + .methods("GET"_method, "POST"_method, "PUT"_method, "DELETE"_method, "OPTIONS"_method) .allow_credentials() .origin(settings.domain) .max_age(86400); @@ -26,22 +29,22 @@ int main() { // create global database dbpool = std::make_unique(settings.db_path); if (!dbpool->init(std::thread::hardware_concurrency())){ - CROW_LOG_ERROR << "Failed to create database at : " << settings.db_path; - return 1; + std::cerr << "Failed to create database at : " << settings.db_path << std::endl; + std::exit(1); } auto opt_isPortOpen = utils::isLocalPortOpen(settings.http_port); if (opt_isPortOpen.has_value()){ if (opt_isPortOpen.value()){ - CROW_LOG_ERROR << "Local port : " << settings.http_port << " is already open"; - return 1; + std::cerr << "Local port : " << settings.http_port << " is already open" << std::endl; + std::exit(1); } } else { - CROW_LOG_ERROR << "failed to check if local port is open : " << opt_isPortOpen.error(); - return 1; + std::cerr << "failed to check if local port is open : " << opt_isPortOpen.error() << std::endl; + std::exit(1); } - + // Root route CROW_ROUTE(app, "/")([&]() { return utils::getFile(utils::build_dir / "index.html"); @@ -54,14 +57,14 @@ int main() { shadowrun::initApi(app); login::initLogin(app); - + // asssets is not svelte generated CROW_ROUTE(app, "/assets/") ([&](const std::string& p) { filesystem::path file_path = utils::assets_dir / p; return utils::getFile(file_path); }); - + // Catch-all route for static files and SPA fallback CROW_ROUTE(app, "/") ([&](const std::string& p) {