Generate version string at compile time from CMakeLists.txt and from bzr revision
* Move StratagusMajorVersion, StratagusMinorVersion, StratagusPatchLevel and StratagusPatchLevel2 to CMakeLists.txt * Added tool genversion.cpp which (re)generate file version-generated.h from cmake if needed * Fill VERSION macro from other values with C preprocessor instead hardcoded values * Remove macros StratagusFormatString and StratagusFormatArgs from code, use only VERSION
This commit is contained in:
parent
f1602c25e2
commit
a0ff593ed8
6 changed files with 155 additions and 30 deletions
|
@ -26,9 +26,27 @@
|
|||
#
|
||||
#
|
||||
|
||||
#########################
|
||||
# Version configuration #
|
||||
#########################
|
||||
# Stratagus major version
|
||||
set(STRATAGUS_MAJOR_VERSION 2)
|
||||
# Stratagus minor version (maximal 99)
|
||||
set(STRATAGUS_MINOR_VERSION 2)
|
||||
# Stratagus patch level (maximal 99)
|
||||
set(STRATAGUS_PATCH_LEVEL 7)
|
||||
# Stratagus patch level 2
|
||||
set(STRATAGUS_PATCH_LEVEL2 0)
|
||||
#########################
|
||||
|
||||
project(stratagus)
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
set(STRATAGUS_VERSION 2.2.7)
|
||||
|
||||
set(STRATAGUS_VERSION "${STRATAGUS_MAJOR_VERSION}.${STRATAGUS_MINOR_VERSION}.${STRATAGUS_PATCH_LEVEL}")
|
||||
|
||||
if(${STRATAGUS_PATCH_LEVEL2} GREATER 0)
|
||||
set(STRATAGUS_VERSION "${STRATAGUS_VERSION}.${STRATAGUS_PATCH_LEVEL2}")
|
||||
endif()
|
||||
|
||||
# Stratagus sources
|
||||
|
||||
|
@ -36,6 +54,7 @@ include_directories(
|
|||
src/include
|
||||
src/guichan/include
|
||||
src/guichan/include/guichan
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
set(action_SRCS
|
||||
|
@ -954,13 +973,32 @@ message("==================================")
|
|||
|
||||
# Compile Stratagus
|
||||
|
||||
set(genversion_SRCS tools/genversion.cpp)
|
||||
source_group(genversion FILES ${genversion_SRCS})
|
||||
add_executable(genversion ${genversion_SRCS})
|
||||
|
||||
########### next target ###############
|
||||
|
||||
add_custom_target(version-generated.h ALL
|
||||
${CMAKE_CURRENT_BINARY_DIR}/genversion ${CMAKE_CURRENT_BINARY_DIR}/version-generated.h "${STRATAGUS_VERSION}"
|
||||
DEPENDS genversion
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
VERBATIM
|
||||
)
|
||||
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES version-generated.h)
|
||||
|
||||
########### next target ###############
|
||||
|
||||
add_custom_command(OUTPUT tolua.cpp
|
||||
COMMAND ${TOLUA++_APP} ARGS -L stratagus.lua -o ${CMAKE_CURRENT_BINARY_DIR}/tolua.cpp stratagus.pkg
|
||||
DEPENDS ${tolua_FILES}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/tolua
|
||||
)
|
||||
|
||||
########### next target ###############
|
||||
|
||||
add_executable(stratagus WIN32 ${stratagus_SRCS} ${stratagus_HDRS})
|
||||
add_dependencies(stratagus version-generated.h)
|
||||
target_link_libraries(stratagus ${stratagus_LIBS})
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include "version-generated.h"
|
||||
|
||||
/// Name
|
||||
#ifdef _WIN64
|
||||
#define NAME "Stratagus (64 bit)"
|
||||
|
@ -5,33 +7,30 @@
|
|||
#define NAME "Stratagus"
|
||||
#endif
|
||||
|
||||
// Description
|
||||
/// Description
|
||||
#define DESCRIPTION NAME " - Strategy Gaming Engine"
|
||||
|
||||
/// Engine version shown
|
||||
#define VERSION "2.2.7"
|
||||
/// Engine version string
|
||||
#define _version_stringify_(s) #s
|
||||
#define _version_stringify(s) _version_stringify_(s)
|
||||
|
||||
/// Stratagus major version
|
||||
#define StratagusMajorVersion 2
|
||||
#define _version_str1 _version_stringify(StratagusMajorVersion) "." _version_stringify(StratagusMinorVersion) "." _version_stringify(StratagusPatchLevel)
|
||||
|
||||
/// Stratagus minor version (maximal 99)
|
||||
#define StratagusMinorVersion 2
|
||||
#if StratagusPatchLevel2 > 0
|
||||
#define _version_str2 _version_str1 "." _version_stringify(StratagusPatchLevel2)
|
||||
#else
|
||||
#define _version_str2 _version_str1
|
||||
#endif
|
||||
|
||||
/// Stratagus patch level (maximal 99)
|
||||
#define StratagusPatchLevel 7
|
||||
|
||||
/// Stratagus patch level 2
|
||||
#define StratagusPatchLevel2 0
|
||||
#ifdef StratagusBzrRev
|
||||
#define VERSION _version_str2 "-bzr" _version_stringify(StratagusBzrRev)
|
||||
#else
|
||||
#define VERSION _version_str2
|
||||
#endif
|
||||
|
||||
/// Stratagus version (1,2,3) -> 10203
|
||||
#define StratagusVersion (StratagusMajorVersion * 10000 + StratagusMinorVersion * 100 + StratagusPatchLevel)
|
||||
|
||||
/// Stratagus printf format string
|
||||
#define StratagusFormatString "%d.%d.%d"
|
||||
|
||||
/// Stratagus printf format arguments
|
||||
#define StratagusFormatArgs(v) (v) / 10000, ((v) / 100) % 100, (v) % 100
|
||||
|
||||
/// Homepage
|
||||
#define HOMEPAGE "https://launchpad.net/stratagus"
|
||||
|
||||
|
|
|
@ -116,8 +116,8 @@ void CMap::Save(CFile &file) const
|
|||
|
||||
file.printf("StratagusMap(\n");
|
||||
|
||||
file.printf(" \"version\", \"" StratagusFormatString "\",\n",
|
||||
StratagusFormatArgs(StratagusVersion));
|
||||
file.printf(" \"version\", \"%s\",\n", VERSION);
|
||||
|
||||
file.printf(" \"description\", \"%s\",\n", this->Info.Description.c_str());
|
||||
|
||||
file.printf(" \"the-map\", {\n");
|
||||
|
|
|
@ -64,7 +64,7 @@ static int CclStratagusMap(lua_State *l)
|
|||
char buf[32];
|
||||
|
||||
const char *version = LuaToString(l, j + 1);
|
||||
snprintf(buf, sizeof(buf), StratagusFormatString, StratagusFormatArgs(StratagusVersion));
|
||||
strncpy(buf, VERSION, sizeof(buf));
|
||||
if (strcmp(buf, version)) {
|
||||
fprintf(stderr, "Warning not saved with this version.\n");
|
||||
}
|
||||
|
|
|
@ -1137,11 +1137,10 @@ static void ClientParseConnecting(const CInitMessage &msg)
|
|||
|
||||
case ICMEngineMismatch: // Stratagus engine version doesn't match
|
||||
fprintf(stderr, "Incompatible Stratagus version "
|
||||
StratagusFormatString " <-> "
|
||||
StratagusFormatString "\n"
|
||||
"%d <-> %d\n"
|
||||
"from %d.%d.%d.%d:%d\n",
|
||||
StratagusFormatArgs((int)ntohl(msg.Stratagus)),
|
||||
StratagusFormatArgs(StratagusVersion),
|
||||
(int)ntohl(msg.Stratagus),
|
||||
StratagusVersion,
|
||||
NIPQUAD(ntohl(NetLastHost)), ntohs(NetLastPort));
|
||||
NetLocalState = ccs_incompatibleengine;
|
||||
NetConnectRunning = 0; // End the menu..
|
||||
|
@ -1870,11 +1869,10 @@ static int CheckVersions(const CInitMessage &msg)
|
|||
|
||||
if (ntohl(msg.Stratagus) != StratagusVersion) {
|
||||
fprintf(stderr, "Incompatible Stratagus version "
|
||||
StratagusFormatString " <-> "
|
||||
StratagusFormatString "\n"
|
||||
"%d <-> %d\n"
|
||||
"from %d.%d.%d.%d:%d\n",
|
||||
StratagusFormatArgs((int)ntohl(msg.Stratagus)),
|
||||
StratagusFormatArgs(StratagusVersion),
|
||||
(int)ntohl(msg.Stratagus),
|
||||
StratagusVersion,
|
||||
NIPQUAD(ntohl(NetLastHost)), ntohs(NetLastPort));
|
||||
|
||||
message.Type = MessageInitReply;
|
||||
|
|
90
tools/genversion.cpp
Normal file
90
tools/genversion.cpp
Normal file
|
@ -0,0 +1,90 @@
|
|||
// _________ __ __
|
||||
// / _____// |_____________ _/ |______ ____ __ __ ______
|
||||
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
|
||||
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
|
||||
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
|
||||
// \/ \/ \//_____/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// Stratagus - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name genversion.cpp - Generate Stratagus header file version-generated.h */
|
||||
//
|
||||
// (c) Copyright 2013 by Pali Rohár <pali.rohar@gmail.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; only version 2 of the License.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
/* usage: genversion "/path/to/version-generated.h" "major.minor.path.patch2" */
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
|
||||
FILE * file;
|
||||
int old_ver[5] = { -1, -1, -1, -1, -1 };
|
||||
int new_ver[5] = { -1, -1, -1, -1, -1 };
|
||||
|
||||
if ( argc != 3 )
|
||||
return 1;
|
||||
|
||||
if ( sscanf(argv[2], "%d.%d.%d.%d", &new_ver[0], &new_ver[1], &new_ver[2], &new_ver[3]) != 4 ) {
|
||||
new_ver[3] = 0;
|
||||
if ( sscanf(argv[2], "%d.%d.%d", &new_ver[0], &new_ver[1], &new_ver[2]) != 3 )
|
||||
return 1;
|
||||
}
|
||||
|
||||
file = fopen(argv[1], "r");
|
||||
if ( file ) {
|
||||
if ( fscanf(file, "/* %d %d %d %d %d */", &old_ver[0], &old_ver[1], &old_ver[2], &old_ver[3], &old_ver[4]) != 5 ) {
|
||||
old_ver[0] = -1;
|
||||
old_ver[1] = -1;
|
||||
old_ver[2] = -1;
|
||||
old_ver[3] = -1;
|
||||
old_ver[4] = -1;
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
file = fopen(".bzr/branch/last-revision", "r");
|
||||
if ( file ) {
|
||||
if ( fscanf(file, "%d", &new_ver[4]) != 1 )
|
||||
new_ver[4] = -1;
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
if ( memcmp(old_ver, new_ver, sizeof(old_ver)) == 0 )
|
||||
return 0;
|
||||
|
||||
file = fopen(argv[1], "w");
|
||||
if ( ! file )
|
||||
return 1;
|
||||
|
||||
fprintf(file, "/* %d %d %d %d %d */\n", new_ver[0], new_ver[1], new_ver[2], new_ver[3], new_ver[4]);
|
||||
fprintf(file, "/* This file is autogenerated, do not modify it! */\n");
|
||||
fprintf(file, "#define StratagusMajorVersion %d\n", new_ver[0]);
|
||||
fprintf(file, "#define StratagusMinorVersion %d\n", new_ver[1]);
|
||||
fprintf(file, "#define StratagusPatchLevel %d\n", new_ver[2]);
|
||||
fprintf(file, "#define StratagusPatchLevel2 %d\n", new_ver[3]);
|
||||
|
||||
if ( new_ver[4] >= 0 )
|
||||
fprintf(file, "#define StratagusBzrRev %d\n", new_ver[4]);
|
||||
|
||||
fclose(file);
|
||||
return 0;
|
||||
|
||||
}
|
Loading…
Reference in a new issue