From 318cf68e1b482c88add407a753e03668a4950298 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 15 Sep 2016 20:11:38 +0200 Subject: [PATCH 1/6] move version string into a single object file --- src/creport.c | 2 +- src/kernel/save.c | 2 +- src/kernel/version.c | 10 ++++++++++ src/kernel/version.h | 5 +---- src/main.c | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 src/kernel/version.c diff --git a/src/creport.c b/src/creport.c index 4cf778f23..2c49caf44 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1515,7 +1515,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) fprintf(F, "%d;Basis\n", 36); fprintf(F, "%d;Runde\n", turn); fprintf(F, "%d;Zeitalter\n", era); - fprintf(F, "\"%s\";Build\n", ERESSEA_VERSION); + fprintf(F, "\"%s\";Build\n", eressea_version()); if (mailto != NULL) { fprintf(F, "\"%s\";mailto\n", mailto); fprintf(F, "\"%s\";mailcmd\n", LOC(f->locale, "mailcmd")); diff --git a/src/kernel/save.c b/src/kernel/save.c index 5121e02ed..bffc339f9 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1898,7 +1898,7 @@ int writegame(const char *filename) fstream_init(&strm, F); binstore_init(&store, &strm); - WRITE_INT(&store, version_no(ERESSEA_VERSION)); + WRITE_INT(&store, version_no(eressea_version())); n = write_game(&gdata); binstore_done(&store); fstream_done(&strm); diff --git a/src/kernel/version.c b/src/kernel/version.c new file mode 100644 index 000000000..95d61f014 --- /dev/null +++ b/src/kernel/version.c @@ -0,0 +1,10 @@ +#include "version.h" + +#ifndef ERESSEA_VERSION +// the version number, if it was not passed to make with -D +#define ERESSEA_VERSION "3.10.0-devel" +#endif + +const char *eressea_version(void) { + return ERESSEA_VERSION; +} diff --git a/src/kernel/version.h b/src/kernel/version.h index 5b3bf0cf6..f71177f9f 100644 --- a/src/kernel/version.h +++ b/src/kernel/version.h @@ -10,7 +10,4 @@ without prior permission by the authors of Eressea. */ -#ifndef ERESSEA_VERSION -// the version number, if it was not passed to make with -D -#define ERESSEA_VERSION "3.10.0-devel" -#endif +const char *eressea_version(void); diff --git a/src/main.c b/src/main.c index d3d2cbe50..58a15edc0 100644 --- a/src/main.c +++ b/src/main.c @@ -166,7 +166,7 @@ static int parse_args(int argc, char **argv, int *exitcode) printf("\n%s PBEM host\n" "Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n" "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %s\n\n", - game_name(), ERESSEA_VERSION); + game_name(), eressea_version()); #ifdef USE_CURSES } else if (strcmp(argi + 2, "color") == 0) { From 10916bb0a15454ee140a63786623b0ebe5e10f92 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 15 Sep 2016 20:14:17 +0200 Subject: [PATCH 2/6] use add_definitions instead of CMAKE_C_FLAGS, define ERESSEA_VERSION only on version.c --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 12 +++++++----- src/kernel/CMakeLists.txt | 1 + 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7edf32d4f..1ad7b3528 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,7 @@ CONFIGURE_FILE ( ${CMAKE_CURRENT_SOURCE_DIR}/autoconf.h.in ${CMAKE_BINARY_DIR}/include/autoconf.h) INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/include) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_AUTOCONF") +add_definitions(-DUSE_AUTOCONF) add_subdirectory (cutest) add_subdirectory (cJSON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1414c851..4070dcbd6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,14 +13,16 @@ include_directories (${BSON_INCLUDE_DIR}) include_directories (${INIPARSER_INCLUDE_DIR}) IF(DEFINED ERESSEA_VERSION) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DERESSEA_VERSION=\\\"${ERESSEA_VERSION}\\\"") +set_source_files_properties(kernel/version.c PROPERTIES +COMPILE_DEFINITIONS ERESSEA_VERSION="${ERESSEA_VERSION}") ENDIF() IF(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) # SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wno-sign-conversion") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pedantic -Wsign-compare -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts -Wno-long-long") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -DHAVE__BOOL") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") + add_definitions(-DHAVE__BOOL) ELSEIF(MSVC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Wall /WX /MP") set(CMAKE_EXE_LINKER_FLAGS_DEBUG @@ -251,18 +253,18 @@ install(TARGETS eressea DESTINATION "bin") if (SQLITE3_FOUND) target_link_libraries(eressea ${SQLITE3_LIBRARIES}) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_SQLITE") +add_definitions(-DUSE_SQLITE) endif(SQLITE3_FOUND) if (CURSES_FOUND) include_directories (${CURSES_INCLUDE_DIR}) target_link_libraries(eressea ${CURSES_LIBRARIES}) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_CURSES") +add_definitions(-DUSE_CURSES) endif(CURSES_FOUND) if (LIBXML2_FOUND) include_directories (${LIBXML2_INCLUDE_DIR}) target_link_libraries(eressea ${LIBXML2_LIBRARIES}) target_link_libraries(test_eressea ${LIBXML2_LIBRARIES}) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_LIBXML2") +add_definitions(-DUSE_LIBXML2) endif (LIBXML2_FOUND) diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 9e829d4f4..016c8fb18 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -33,6 +33,7 @@ jsonconf.test.c ) SET(_FILES +version.c alliance.c ally.c build.c From 47526dd36b83213665a88f8dd59c162afb4a205a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 16 Sep 2016 09:39:59 +0200 Subject: [PATCH 3/6] smarter version.c build that avoids full rebuilds. --- src/CMakeLists.txt | 5 ++++- src/kernel/CMakeLists.txt | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4070dcbd6..ef3bc782f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -173,7 +173,10 @@ set (SERVER_SRC ${SERVER_SRC} ) endif(CURSES_FOUND) -add_library(game ${ERESSEA_SRC}) +add_library(version OBJECT ${VERSION_SRC}) +add_library(game ${ERESSEA_SRC} + $ +) add_executable(eressea ${SERVER_SRC}) target_link_libraries(eressea game diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 016c8fb18..2c9da7dc0 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -33,7 +33,6 @@ jsonconf.test.c ) SET(_FILES -version.c alliance.c ally.c build.c @@ -65,6 +64,8 @@ xmlreader.c jsonconf.c ) +SET(VERSION_SRC ${PROJECT_NAME}/version.c PARENT_SCOPE) + FOREACH(_FILE ${_FILES}) LIST(APPEND _SOURCES ${PROJECT_NAME}/${_FILE}) ENDFOREACH(_FILE) From dc004b2d7191485d65b88491f29b4ae8bcb185e4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 16 Sep 2016 09:49:53 +0200 Subject: [PATCH 4/6] require cmake version 2.8.8 (add_library OBJECT ...) --- s/travis-build | 1 + src/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/s/travis-build b/s/travis-build index 414a70f80..f2ec7e487 100755 --- a/s/travis-build +++ b/s/travis-build @@ -12,6 +12,7 @@ fi set -e [ -z $BUILD ] && BUILD=Debug ; export BUILD +cmake --version s/cmake-init s/build cd $ROOT diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ef3bc782f..e12f8971f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.6) +cmake_minimum_required(VERSION 2.8.8) project (server C) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) From b0799bd152a5654e33703673ef81658c997dc27b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 16 Sep 2016 10:55:38 +0200 Subject: [PATCH 5/6] fix travis build by not depending on CMake 2.8.8 --- src/CMakeLists.txt | 9 ++++----- src/kernel/CMakeLists.txt | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e12f8971f..e4d90c069 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8.8) +cmake_minimum_required(VERSION 2.8) project (server C) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) @@ -173,11 +173,10 @@ set (SERVER_SRC ${SERVER_SRC} ) endif(CURSES_FOUND) -add_library(version OBJECT ${VERSION_SRC}) -add_library(game ${ERESSEA_SRC} - $ -) +add_library(version STATIC ${VERSION_SRC}) +add_library(game ${ERESSEA_SRC}) add_executable(eressea ${SERVER_SRC}) +target_link_libraries(game version) target_link_libraries(eressea game ${TOLUA_LIBRARIES} diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 2c9da7dc0..6bb860ad7 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -1,3 +1,4 @@ +cmake_minimum_required(VERSION 2.6) project(kernel C) SET(_TEST_FILES From 55df24ffb8e9970eefddb386b532712a8aae55d4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 16 Sep 2016 16:54:41 +0200 Subject: [PATCH 6/6] all code review nitpicks fixed. --- s/runtests | 2 +- s/travis-build | 1 - src/CMakeLists.txt | 2 +- src/kernel/save.c | 6 ------ src/kernel/save.h | 1 - src/kernel/save.test.c | 1 + src/kernel/version.c | 7 +++++++ src/kernel/version.h | 14 +++++++++----- 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/s/runtests b/s/runtests index d0b3432e8..2f22402dc 100755 --- a/s/runtests +++ b/s/runtests @@ -20,6 +20,6 @@ $ROOT/$BUILD/eressea/eressea -v0 scripts/run-tests.lua $ROOT/$BUILD/eressea/eressea -v0 scripts/run-tests-e2.lua $ROOT/$BUILD/eressea/eressea -v0 scripts/run-tests-e3.lua $ROOT/$BUILD/eressea/eressea -v0 scripts/run-tests-e4.lua -rm -rf data reports orders.txt score score.alliances +rm -rf data reports orders.txt score score.alliances datum turn cd $OLDWPD diff --git a/s/travis-build b/s/travis-build index f2ec7e487..414a70f80 100755 --- a/s/travis-build +++ b/s/travis-build @@ -12,7 +12,6 @@ fi set -e [ -z $BUILD ] && BUILD=Debug ; export BUILD -cmake --version s/cmake-init s/build cd $ROOT diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e4d90c069..11bd860ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 2.6) project (server C) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/kernel/save.c b/src/kernel/save.c index bffc339f9..b9b522794 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1858,12 +1858,6 @@ static void clear_npc_orders(faction *f) } } -int version_no(const char *str) { - int maj = 0, min = 0, bld = 0; - sscanf(str, "%d.%d.%d", &maj, &min, &bld); - return (maj << 16) | (min << 8) | bld; -} - int writegame(const char *filename) { int n; diff --git a/src/kernel/save.h b/src/kernel/save.h index 27dd56661..3cd443926 100644 --- a/src/kernel/save.h +++ b/src/kernel/save.h @@ -79,7 +79,6 @@ extern "C" { int write_game(struct gamedata *data); int read_game(struct gamedata *data); - int version_no(const char *str); /* test-only functions that give access to internal implementation details (BAD) */ void _test_write_password(struct gamedata *data, const struct faction *f); diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index 95acbd4c0..00b5ff96c 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -5,6 +5,7 @@ #include #include "save.h" +#include "version.h" #include "unit.h" #include "group.h" #include "ally.h" diff --git a/src/kernel/version.c b/src/kernel/version.c index 95d61f014..220e113f7 100644 --- a/src/kernel/version.c +++ b/src/kernel/version.c @@ -1,5 +1,6 @@ #include "version.h" +#include #ifndef ERESSEA_VERSION // the version number, if it was not passed to make with -D #define ERESSEA_VERSION "3.10.0-devel" @@ -8,3 +9,9 @@ const char *eressea_version(void) { return ERESSEA_VERSION; } + +int version_no(const char *str) { + int maj = 0, min = 0, bld = 0; + sscanf(str, "%d.%d.%d", &maj, &min, &bld); + return (maj << 16) | (min << 8) | bld; +} diff --git a/src/kernel/version.h b/src/kernel/version.h index f71177f9f..c268e7bac 100644 --- a/src/kernel/version.h +++ b/src/kernel/version.h @@ -1,13 +1,17 @@ +#pragma once /* +-------------------+ | | Enno Rehling | Eressea PBEM host | Katja Zedel - | (c) 1998 - 2007 | Christian Schlittchen - | | + | (c) 1998 - 2016 | Christian Schlittchen + | | https://github.com/eressea/server +-------------------+ - - This program may not be used, modified or distributed - without prior permission by the authors of Eressea. */ +#ifndef H_KERNEL_VERSION +#define H_KERNEL_VERSION + const char *eressea_version(void); +int version_no(const char *str); + +#endif