added version number to build

This commit is contained in:
2026-02-23 16:11:23 +01:00
parent 4d00936719
commit 639aac68ca
5 changed files with 53 additions and 18 deletions

View File

@@ -87,8 +87,13 @@ target_link_options(${TARGET_NAME} PRIVATE
$<$<CONFIG:Release>:-flto=auto> $<$<CONFIG:Release>:-flto=auto>
) )
if(NOT DEFINED APP_VERSION)
set(APP_VERSION "0.0.0")
endif()
target_compile_definitions(${TARGET_NAME} PRIVATE target_compile_definitions(${TARGET_NAME} PRIVATE
APPLICATION_NAME="${TARGET_NAME}" APPLICATION_NAME="${TARGET_NAME}"
APP_VERSION="${APP_VERSION}"
SQLITE_THREADSAFE=1 # build sqlite with thread safty SQLITE_THREADSAFE=1 # build sqlite with thread safty
ASIO_STANDALONE # use asio without boost ASIO_STANDALONE # use asio without boost
CROW_ENABLE_COMPRESSION # enable compression part of crow CROW_ENABLE_COMPRESSION # enable compression part of crow

View File

@@ -1,7 +1,7 @@
# Maintainer: Lukas Forsberg lukas96.forsberg@gmail.com # Maintainer: Lukas Forsberg lukas96.forsberg@gmail.com
pkgname=shadowrun-server pkgname=shadowrun-server
pkgver=0.1.3 pkgver=0.1.4
pkgrel=1 pkgrel=1
arch=('x86_64') arch=('x86_64')
depends=() depends=()
@@ -18,7 +18,8 @@ build() {
cmake -S "${srcdir}" \ cmake -S "${srcdir}" \
-B build \ -B build \
-DCMAKE_BUILD_TYPE=Release \ -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_PREFIX=/usr \
-DAPP_VERSION=${pkgver}
cmake --build build cmake --build build
} }

26
source/Application.hpp Normal file
View File

@@ -0,0 +1,26 @@
#ifndef __APPVERSION_H__
#define __APPVERSION_H__
#include <string>
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__

View File

@@ -1,8 +1,8 @@
#include <fstream> #include <fstream>
#include "json.hpp" #include "json.hpp"
#include "json_settings.h" #include "json_settings.h"
#include "crow/logging.h"
#include "utils.hpp" #include "utils.hpp"
#include <iostream>
using namespace std; using namespace std;
using json = nlohmann::json; using json = nlohmann::json;
@@ -19,7 +19,7 @@ Settings AppSettings::deafult(){
Settings AppSettings::load() { Settings AppSettings::load() {
ifstream file(settingsFile); ifstream file(settingsFile);
if (!file.is_open()) { 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(); return AppSettings::deafult();
} }
@@ -29,14 +29,14 @@ Settings AppSettings::load() {
auto result = utils::parseJson(fileContents); auto result = utils::parseJson(fileContents);
if(!result){ 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(); return AppSettings::deafult();
} }
try { try {
return result.value().get<Settings>(); return result.value().get<Settings>();
} catch (...) { } 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(); return AppSettings::deafult();
} }
} }

View File

@@ -7,18 +7,21 @@
#include "ShadowrunApi.hpp" #include "ShadowrunApi.hpp"
#include "databasepool.h" #include "databasepool.h"
#include "crow/compression.h" #include "crow/compression.h"
#include "Application.hpp"
using namespace std; using namespace std;
int main() { int main() {
std::cout << "Launching " << Application::name() << " version: " << Application::version() << std::endl;
AppSettings::Settings settings = AppSettings::load(); AppSettings::Settings settings = AppSettings::load();
crow::App<crow::CORSHandler> app; crow::App<crow::CORSHandler> app;
// init cors // init cors
auto& cors = app.get_middleware<crow::CORSHandler>(); auto& cors = app.get_middleware<crow::CORSHandler>();
cors.global() cors.global()
.headers("Content-Type", "Authorization") .headers("Content-Type", "Authorization")
.methods("GET"_method, "POST"_method, "PUT"_method, "DELETE"_method, "OPTIONS"_method) .methods("GET"_method, "POST"_method, "PUT"_method, "DELETE"_method, "OPTIONS"_method)
.allow_credentials() .allow_credentials()
.origin(settings.domain) .origin(settings.domain)
.max_age(86400); .max_age(86400);
@@ -26,20 +29,20 @@ int main() {
// create global database // create global database
dbpool = std::make_unique<DatabasePool>(settings.db_path); dbpool = std::make_unique<DatabasePool>(settings.db_path);
if (!dbpool->init(std::thread::hardware_concurrency())){ if (!dbpool->init(std::thread::hardware_concurrency())){
CROW_LOG_ERROR << "Failed to create database at : " << settings.db_path; std::cerr << "Failed to create database at : " << settings.db_path << std::endl;
return 1; std::exit(1);
} }
auto opt_isPortOpen = utils::isLocalPortOpen(settings.http_port); auto opt_isPortOpen = utils::isLocalPortOpen(settings.http_port);
if (opt_isPortOpen.has_value()){ if (opt_isPortOpen.has_value()){
if (opt_isPortOpen.value()){ if (opt_isPortOpen.value()){
CROW_LOG_ERROR << "Local port : " << settings.http_port << " is already open"; std::cerr << "Local port : " << settings.http_port << " is already open" << std::endl;
return 1; std::exit(1);
} }
} }
else { else {
CROW_LOG_ERROR << "failed to check if local port is open : " << opt_isPortOpen.error(); std::cerr << "failed to check if local port is open : " << opt_isPortOpen.error() << std::endl;
return 1; std::exit(1);
} }
// Root route // Root route