From efda6673b5b8e362c3683e0f7a58b3091363b1f2 Mon Sep 17 00:00:00 2001 From: dongresource Date: Wed, 16 Sep 2020 20:12:12 +0200 Subject: [PATCH] Print server version when starting up. Also added -ldl to fix cmake compilation on Unix systems. --- .gitignore | 1 + CMakeLists.txt | 8 +++++++- Makefile | 12 ++++++++++-- src/main.cpp | 3 +++ version.h.in | 1 + 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 version.h.in diff --git a/.gitignore b/.gitignore index 9f0a7da..073f909 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ build/ .vs/ .idea/ *.db +version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f21f984..e3c9189 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,8 @@ project(OpenFusion) set(CMAKE_CXX_STANDARD 17) +execute_process(COMMAND git describe --tags OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) + # OpenFusion supports multiple packet/struct versions # 104 is the default version to build which can be changed # For example: cmake -B build -DPROTOCOL_VERSION=728 @@ -33,10 +35,14 @@ endif() include_directories(src) -file(GLOB_RECURSE SOURCES src/**.cpp src/**.hpp src/**.c src/**.h) +file(GLOB_RECURSE SOURCES src/**.cpp src/**.hpp src/**.c src/**.h version.h) + +configure_file(version.h.in ${CMAKE_SOURCE_DIR}/version.h @ONLY) add_executable(openfusion ${SOURCES}) +target_link_libraries(openfusion dl) + set_target_properties(openfusion PROPERTIES OUTPUT_NAME ${BIN_NAME}) # Use pthreads if not generating a VS solution or MinGW makefile (because MinGW will prefer Win32 threads) diff --git a/Makefile b/Makefile index d3e2d93..aba5138 100644 --- a/Makefile +++ b/Makefile @@ -107,6 +107,8 @@ ifneq ($(shell $(WIN_CXX) --version | head -1 | egrep -o [0-9]+ | tail -3 | head WIN_CXX_OPT_DISABLES=$(WIN_CXX_VANILLA_MINGW_OPT_DISABLES) endif +CXXFLAGS+= -DGIT_VERSION=\"$(shell git describe --tags)\" + .SUFFIX: .o .c .cpp .h .hpp .c.o: @@ -122,13 +124,19 @@ $(SERVER): $(OBJ) $(CHDR) $(CXXHDR) mkdir -p bin $(CXX) $(OBJ) $(LDFLAGS) -o $(SERVER) +# compatibility with how cmake injects GIT_VERSION +version.h: + touch version.h + +src/main.o: version.h + .PHONY: all windows clean nuke # only gets rid of OpenFusion objects, so we don't need to # recompile the libs every time clean: - rm -f src/*.o $(SERVER) $(WIN_SERVER) + rm -f src/*.o $(SERVER) $(WIN_SERVER) version.h # gets rid of all compiled objects, including the libraries nuke: - rm -f $(OBJ) $(SERVER) $(WIN_SERVER) + rm -f $(OBJ) $(SERVER) $(WIN_SERVER) version.h diff --git a/src/main.cpp b/src/main.cpp index 0d7d97b..d517d41 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,8 @@ #include "settings.hpp" +#include "../version.h" + #if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS) #include "mingw/mingw.thread.h" #else @@ -84,6 +86,7 @@ int main() { initsignals(); #endif settings::init(); + std::cout << "[INFO] OpenFusion v" GIT_VERSION << std::endl; std::cout << "[INFO] Protocol version: " << PROTOCOL_VERSION << std::endl; std::cout << "[INFO] Intializing Packet Managers..." << std::endl; TableData::init(); diff --git a/version.h.in b/version.h.in new file mode 100644 index 0000000..1562e2f --- /dev/null +++ b/version.h.in @@ -0,0 +1 @@ +#define GIT_VERSION "@GIT_VERSION@"