Skip to content

Commit 5a8f425

Browse files
authored
Merge pull request #39 from AhmedAredah/server
Server
2 parents 4bd03a3 + bcc6587 commit 5a8f425

614 files changed

Lines changed: 13083 additions & 147238 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
BasedOnStyle: LLVM
2+
Language: Cpp
3+
4+
# Maximum line width
5+
ColumnLimit: 60
6+
7+
# Use spaces, 4-wide
8+
IndentWidth: 4
9+
TabWidth: 4
10+
UseTab: Never
11+
12+
# Control exactly how braces are broken
13+
BreakBeforeBraces: Custom
14+
BraceWrapping:
15+
AfterClass: true
16+
AfterControlStatement: true
17+
AfterEnum: true
18+
AfterFunction: true
19+
AfterNamespace: true
20+
AfterObjCDeclaration: true
21+
AfterStruct: true
22+
AfterUnion: true
23+
BeforeCatch: true
24+
BeforeElse: true
25+
IndentBraces: false
26+
27+
# Keep access specifiers (public:, private:, protected:) unindented
28+
AccessModifierOffset: -4
29+
30+
# Align consecutive statements for readability
31+
AlignAfterOpenBracket: Align
32+
AlignConsecutiveAssignments: true
33+
AlignConsecutiveDeclarations: true
34+
AlignOperands: true
35+
AlignTrailingComments: true
36+
37+
# Disallow short forms on a single line
38+
AllowShortBlocksOnASingleLine: false
39+
AllowShortFunctionsOnASingleLine: Empty
40+
AllowShortIfStatementsOnASingleLine: Never
41+
AllowShortLoopsOnASingleLine: false
42+
43+
# Break constructor initializer lists before commas
44+
BreakConstructorInitializers: BeforeComma
45+
46+
# Break before binary operators (except `=`) for clarity
47+
BreakBeforeBinaryOperators: NonAssignment
48+
49+
# Limit consecutive blank lines
50+
MaxEmptyLinesToKeep: 1

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,7 @@ NeTrainSim.pro.user
103103
#NeTrainSimInstaller
104104
#-------------------
105105
/src/NeTrainSimInstaller/packages/com.VTTICSM.NeTrainSim/data/*
106-
/src/NeTrainSimInstaller/packages/com.VTTICSM.NeTrainSimGUI/data/*
106+
/src/NeTrainSimInstaller/packages/com.VTTICSM.NeTrainSimGUI/data/*
107+
108+
build/*
109+
build-*/*

CMakeLists.txt

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
# min required cmake version
2+
cmake_minimum_required(VERSION 3.24)
3+
4+
include(InstallRequiredSystemLibraries)
5+
6+
# RPATH configuration for portable/relocatable installs
7+
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
8+
if(UNIX AND NOT APPLE)
9+
# Use $ORIGIN-based RPATH for portable installs on Linux
10+
# $ORIGIN/../lib: executables in bin/ find libs in lib/
11+
# $ORIGIN: shared libs in lib/ find peer libs in same directory
12+
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib;$ORIGIN")
13+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
14+
else()
15+
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
16+
endif()
17+
18+
# Define the project name (NeTrainSim) and
19+
# the programming language used (CXX for C++)
20+
set(NeTrainSim_VERSION "0.1.3" CACHE STRING "Project version" FORCE)
21+
set(NETRAINSIM_NAME "NeTrainSim" CACHE STRING "Project name" FORCE)
22+
set(NETRAINSIM_VENDOR "(C) 2022-2023 Virginia Tech Transportation Institute - Center for Sustainable Mobility." CACHE STRING "Project vendor" FORCE)
23+
# Get the current date and time
24+
string(TIMESTAMP BUILD_DATE "%Y-%m-%d %H:%M:%S")
25+
# Set the BUILD_DATE variable
26+
set(BUILD_DATE ${BUILD_DATE} CACHE STRING "Project build time" FORCE)
27+
28+
# Extract major, minor, and patch version from NeTrainSim_VERSION
29+
string(REPLACE "." ";" VERSION_LIST ${NeTrainSim_VERSION})
30+
list(GET VERSION_LIST 0 NeTrainSim_VERSION_MAJOR)
31+
list(GET VERSION_LIST 1 NeTrainSim_VERSION_MINOR)
32+
list(GET VERSION_LIST 2 NeTrainSim_VERSION_PATCH)
33+
34+
project(${NETRAINSIM_NAME} VERSION ${NeTrainSim_VERSION} LANGUAGES CXX)
35+
36+
if(CMAKE_CONFIGURATION_TYPES)
37+
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;MinSizeRel;RelWithDebInfo" CACHE STRING "" FORCE)
38+
endif()
39+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
40+
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
41+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
42+
endif()
43+
44+
45+
# Set a default build type if none was specified
46+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
47+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
48+
# Set the possible values of build type for cmake-gui
49+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
50+
endif()
51+
52+
# Compiler settings
53+
# Set the C++20 standard to be used for compiling
54+
set(CMAKE_CXX_STANDARD 23)
55+
# Ensure that the selected C++ standard is a
56+
# requirement for the compiler
57+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
58+
# Enable Qt's Automatic User Interface Compiler (UIC)
59+
set(CMAKE_AUTOUIC ON)
60+
# Enable Qt's Meta-Object Compiler (MOC) which allows
61+
# the use of Qt features such as signals and slots
62+
set(CMAKE_AUTOMOC ON)
63+
# Enable Qt's Resource Compiler (RCC) for compiling
64+
# resource files into binary format
65+
set(CMAKE_AUTORCC ON)
66+
67+
# Platform-specific compiler flags
68+
if(MSVC)
69+
# MSVC-specific flags
70+
add_compile_options(/W4 /MP)
71+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
72+
add_compile_options(/Od /Zi)
73+
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
74+
add_compile_options(/O2)
75+
endif()
76+
else()
77+
# GCC/Clang-specific flags
78+
add_compile_options(-Wall)
79+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
80+
add_compile_options(-O0 -g)
81+
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
82+
add_compile_options(-O3)
83+
endif()
84+
endif()
85+
86+
# Add definitions based on build type
87+
if (CMAKE_BUILD_TYPE STREQUAL "Release")
88+
add_definitions(-DQT_NO_DEBUG_OUTPUT)
89+
endif()
90+
91+
# -------------------------------------------------------
92+
# -------------- BUILD TYPE SUFFIXES --------------------
93+
# -------------------------------------------------------
94+
# Set output name suffixes for different build configurations
95+
# This ensures libraries/executables have unique names per build type:
96+
# Debug: *d (e.g., libNeTrainSimCored.so)
97+
# Release: (none)
98+
# RelWithDebInfo: *rd
99+
# MinSizeRel: *s
100+
set(CMAKE_DEBUG_POSTFIX "d")
101+
set(CMAKE_RELEASE_POSTFIX "")
102+
set(CMAKE_RELWITHDEBINFO_POSTFIX "rd")
103+
set(CMAKE_MINSIZEREL_POSTFIX "s")
104+
105+
# -------------------------------------------------------
106+
# --------------------- OPTIONS -------------------------
107+
# -------------------------------------------------------
108+
109+
# Option to build GUI components
110+
option(BUILD_GUI "Build the GUI components" ON)
111+
# Cache the option so it's stored between runs
112+
set(BUILD_GUI ${BUILD_GUI} CACHE BOOL "Build the GUI components" FORCE)
113+
114+
# Option to build Server components
115+
option(BUILD_SERVER "Build the SERVER components" ON)
116+
# Cache the option so it's stored between runs
117+
set(BUILD_SERVER ${BUILD_SERVER} CACHE BOOL "Build the SERVER components" FORCE)
118+
119+
# Option to build the installer
120+
option(BUILD_INSTALLER "Build the installer" ON)
121+
set(BUILD_INSTALLER ${BUILD_INSTALLER} CACHE BOOL "Build the INSTALLER components" FORCE)
122+
123+
# -------------------------------------------------------
124+
# -------------------- Qt Paths -------------------------
125+
# -------------------------------------------------------
126+
127+
# Allow the user to specify the Qt binary directory
128+
if(WIN32)
129+
set(QT_BIN_DIR "C:/Qt/6.4.2/msvc2019_64/bin" CACHE PATH "Path to the Qt binary directory")
130+
elseif(UNIX AND NOT APPLE)
131+
# Derive Qt paths from Qt6_DIR (set by user or find_package)
132+
if(DEFINED Qt6_DIR)
133+
get_filename_component(QT_PREFIX_DIR "${Qt6_DIR}/../../.." ABSOLUTE)
134+
set(QT_BIN_DIR "${QT_PREFIX_DIR}/bin" CACHE PATH "Path to the Qt binary directory")
135+
set(QT_LIB_DIR "${QT_PREFIX_DIR}/lib" CACHE PATH "Path to the Qt library directory")
136+
set(QT_PLUGINS_DIR "${QT_PREFIX_DIR}/plugins" CACHE PATH "Path to the Qt plugins directory")
137+
endif()
138+
endif()
139+
140+
# -------------------------------------------------------
141+
# --------------------- Libraries -----------------------
142+
# --------------- Define Default Paths ------------------
143+
# -------------------------------------------------------
144+
145+
if(BUILD_GUI)
146+
if(WIN32)
147+
set(KDREPORTS_DIR "C:/Program Files/KDAB/KDReports/cmake" CACHE PATH "Path to KDReports CMake directory")
148+
elseif(APPLE)
149+
set(KDREPORTS_DIR "/usr/local/KDAB/KDReports-2.3.95/lib/cmake/KDReports-qt6" CACHE PATH "Path to KDReports CMake directory")
150+
elseif(UNIX)
151+
set(KDREPORTS_DIR "/usr/local/KDAB/KDReports-2.3.95/lib/cmake/KDReports-qt6" CACHE PATH "Path to KDReports CMake directory")
152+
endif()
153+
154+
# Use the KDReports CMake package
155+
find_package(KDReports-qt6 REQUIRED CONFIG PATHS ${KDREPORTS_DIR})
156+
endif()
157+
158+
if(BUILD_SERVER)
159+
if(WIN32)
160+
# Windows-specific paths
161+
set(CONTAINER_SEARCH_PATHS "C:/Program Files/Container/cmake" CACHE PATH "Default path to container's library")
162+
set(RABBITMQ_CMAKE_DIR "C:/Program Files/rabbitmq-c/lib/cmake/rabbitmq-c" CACHE PATH "Default path to RabbitMQ-C library on Windows")
163+
elseif(APPLE)
164+
# macOS-specific paths
165+
set(CONTAINER_SEARCH_PATHS "/usr/local/lib/cmake/Container" CACHE PATH "Default path to container's library on macOS")
166+
set(RABBITMQ_CMAKE_DIR "/usr/local/lib/rabbitmq-c/cmake" CACHE PATH "Default path to RabbitMQ-C library on macOS")
167+
elseif(UNIX)
168+
# Linux-specific paths
169+
set(CONTAINER_SEARCH_PATHS "/usr/local/lib/cmake/Container" CACHE PATH "Default path to container's library on Linux")
170+
set(RABBITMQ_CMAKE_DIR "/usr/local/lib/cmake/rabbitmq-c" CACHE PATH "Default path to RabbitMQ-C library on Linux")
171+
else()
172+
message(FATAL_ERROR "Unsupported platform. Please set paths for CONTAINER_CMAKE_DIR and RABBITMQ_CMAKE_DIR manually.")
173+
endif()
174+
175+
176+
# Find the installed Container library
177+
set(CONTAINER_CMAKE_DIR "${CONTAINER_SEARCH_PATHS}" CACHE PATH "Path to Container library's CMake files")
178+
179+
find_package(Container REQUIRED PATHS ${CONTAINER_CMAKE_DIR} NO_DEFAULT_PATH)
180+
181+
if (NOT Container_FOUND)
182+
message(FATAL_ERROR "Container not found. Please specify the correct path to the Container Library cmake installation.")
183+
endif()
184+
185+
# Check if the directory exists
186+
if(NOT EXISTS "${CONTAINER_LIB_DIR}")
187+
message(FATAL_ERROR "The specified CONTAINER_LIB_DIR does not exist: ${CONTAINER_LIB_DIR}")
188+
endif()
189+
190+
find_package(RabbitMQ-C REQUIRED CONFIG PATHS ${RABBITMQ_CMAKE_DIR})
191+
192+
if (NOT RabbitMQ-C_FOUND)
193+
message(FATAL_ERROR "RabbitMQ-C not found. Please specify the correct path to the RabbitMQ-C cmake installation.")
194+
endif()
195+
196+
# Set and cache the path to the RabbitMQ bin directory using RABBITMQ_CMAKE_DIR
197+
if(WIN32)
198+
# For Windows, use /bin
199+
set(RABBITMQ_SHRD_LIB_DIR "${RABBITMQ_CMAKE_DIR}/../../../bin" CACHE PATH "Path to the RabbitMQ-C library's bin directory")
200+
elseif(UNIX AND NOT APPLE)
201+
# For Linux, use /lib or /lib64 (adjust based on your setup)
202+
set(RABBITMQ_SHRD_LIB_DIR "${RABBITMQ_CMAKE_DIR}/../../" CACHE PATH "Path to the RabbitMQ-C library's bin directory")
203+
elseif(APPLE)
204+
# For macOS, use /lib or /lib64 (adjust based on your setup)
205+
set(RABBITMQ_SHRD_LIB_DIR "${RABBITMQ_CMAKE_DIR}/../../" CACHE PATH "Path to the RabbitMQ-C library's bin directory")
206+
endif()
207+
endif()
208+
209+
210+
# -------------------------------------------------------
211+
# ---------------- RULES AND SUB PROJECTS ---------------
212+
# -------------------------------------------------------
213+
214+
# include src directory
215+
add_subdirectory(src)
216+
217+

NeTrainSim.pro

Lines changed: 0 additions & 19 deletions
This file was deleted.

build_with_admin.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Check if running with admin privileges
4+
if [[ $EUID -ne 0 ]]; then
5+
echo "Requesting admin privileges..."
6+
sudo "$0" "$@"
7+
exit
8+
fi
9+
10+
# Change to the directory where the script is located
11+
cd "$(dirname "$0")"
12+
13+
# Remove existing build directory
14+
rm -rf build
15+
16+
# Create build directory
17+
mkdir build
18+
cd build
19+
20+
# Set the Qt path
21+
QT_PATH="/home/ahmed/Qt/6.8.0/gcc_64/lib/cmake/Qt6"
22+
Container_PATH="/usr/local/cmake"
23+
24+
# Configure and build in Debug mode
25+
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH="$QT_PATH" -DContainer_DIR="$Container_PATH"
26+
make install -j$(nproc)
27+
28+
# Configure and build in Release mode
29+
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$QT_PATH" -DContainer_DIR="$Container_PATH"
30+
make install -j$(nproc)
31+
32+
echo "Build process completed."

src/CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Indicate that this directory contains additional CMakeLists.txt that should be processed
2+
cmake_minimum_required(VERSION 3.24)
3+
4+
# Set the variable 'QCustomPlot_LIB_TARGET_NAME' with the value "qcustomplotLib".
5+
# This can be used as the name of a library target in the project
6+
set(QCustomPlot_LIB_TARGET_NAME "qcustomplotLib")
7+
8+
# Core simulation engine DLL - build this first
9+
add_subdirectory(NeTrainSim)
10+
11+
# Executable program
12+
add_subdirectory(NeTrainSimConsole)
13+
14+
# GUI components
15+
if (BUILD_GUI)
16+
add_subdirectory(NeTrainSimGUI)
17+
endif()
18+
19+
# Server
20+
if (BUILD_SERVER)
21+
add_subdirectory(NeTrainSimServer)
22+
add_subdirectory(NeTrainSimRabbitMQConfig)
23+
endif()
24+
25+
# Installer - add when BUILD_INSTALLER is ON
26+
if(BUILD_INSTALLER)
27+
add_subdirectory(NeTrainSimInstaller)
28+
29+
# Add dependencies for the installer
30+
add_dependencies(NeTrainSimInstaller NeTrainSimCore NeTrainSimConsole)
31+
32+
if (BUILD_GUI)
33+
add_dependencies(NeTrainSimInstaller NeTrainSimGUI)
34+
endif()
35+
36+
if (BUILD_SERVER)
37+
add_dependencies(NeTrainSimInstaller NeTrainSimServer NeTrainSimRabbitMQConfig)
38+
endif()
39+
endif()
40+

0 commit comments

Comments
 (0)