Skip to content

Commit

Permalink
feat: build appimage on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenapte committed Feb 26, 2024
1 parent 7331758 commit 3655bcb
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
11 changes: 10 additions & 1 deletion BallanceMMOServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(BMMO_LIB_DIR ${PROJECT_BINARY_DIR}/lib)
set(BMMO_RUNTIME_DIR ${PROJECT_BINARY_DIR})

# sets RPATH for *install*ed files
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:\$ORIGIN:lib") # Note CMake escaping around '$' sign.
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:\$ORIGIN:lib:../lib") # Note CMake escaping around '$' sign.
# *built* files will also use RPATH which has been set before
set(CMAKE_BUILD_WITH_INSTALL_RPATH on)
# if (CMAKE_SYSTEM_NAME MATCHES "Windows")
Expand Down Expand Up @@ -107,4 +107,13 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
# configure_file(${CMAKE_CURRENT_SOURCE_DIR}/postbuild.bat ${CMAKE_CURRENT_BINARY_DIR}/postbuild.bat COPYONLY)
else()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/start_ballancemmo_loop.sh ${BMMO_RUNTIME_DIR}/start_ballancemmo_loop.sh COPYONLY)
install(TARGETS BallanceMMOServer BallanceMMOMockClient BallanceMMORecordParser DESTINATION bin)
install(TARGETS GameNetworkingSockets yaml-cpp DESTINATION lib)
endif()

option(BUILD_SERVER_APPIMAGE "Build BallanceMMO Server AppImage" OFF)

if (BUILD_SERVER_APPIMAGE)
add_executable(BallanceMMOLaunchSelector appimage/launch_selector.cpp)
install(TARGETS BallanceMMOLaunchSelector DESTINATION bin)
endif()
10 changes: 10 additions & 0 deletions BallanceMMOServer/appimage/BMMOLaunchSelector.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Desktop Entry]
Version=1.0
Type=Application
Name=BallanceMMOLaunchSelector
Comment=BMMO Server
Exec=BallanceMMOLaunchSelector
Icon=BallanceMMO
GenericName=Game Server
Categories=Game
Terminal=true
37 changes: 37 additions & 0 deletions BallanceMMOServer/appimage/BallanceMMO.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions BallanceMMOServer/appimage/launch_selector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>

const char* const available_binaries[] = { "Server", "MockClient", "RecordParser" };
const char* target;

bool select_target(char* test_name) {
for (const char* name: available_binaries) {
if (std::strcmp(test_name, name) != 0) continue;
target = name;
return true;
}
return false;
}

int parse_args(int argc, char** argv) {
using namespace std;
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
printf("Usage: %s [OPTION]...\n", argv[0]);
puts("Options:");
puts(" -h, --help\t\t Display this help and exit.");
puts(" -l, --launch [Target]\t Launch the selected target.");
puts("Additional options will be forwarded to the target.");
printf("Available targets (default: `%s`):\n", available_binaries[0]);
for (const char* name: available_binaries)
printf(" %s\n", name);
puts("Examples:");
printf(" To see the server help:\n\t%s --launch Server --help\n", argv[0]);
printf(" To launch a mock client with a custom name:\n\t%s -l MockClient -n Name\n", argv[0]);
return 0;
}
else if (strcmp(argv[1], "-l") == 0 || strcmp(argv[1], "--launch") == 0) {
if (argc <= 2) {
target = available_binaries[0];
return argc;
}
if (select_target(argv[2])) {
return 3;
}
fprintf(stderr, "Error: target `%s` not found.\n", argv[2]);
return -1;
}
return 0;
}

int main(int argc, char** argv) {
std::string cmd = "$APPDIR/usr/bin/BallanceMMO";

if (argc < 1) return -1;

if (argc == 1) {
target = available_binaries[0];
argc = 0;
}
else {
int index = parse_args(argc, argv);
if (index <= 0) return index;
argc -= index, argv += index;
}
cmd += target;
for (int i = 0; i < argc; ++i) {
cmd += ' ';
cmd += argv[i];
}

return std::system(cmd.c_str());
}

0 comments on commit 3655bcb

Please sign in to comment.