Merge pull request #4194 from AaronVanGeffen/git-info

Define Git variables for CMake, move those to static strings to avoid unnecessary recompilation.
This commit is contained in:
Ted John 2016-08-01 17:51:29 +01:00 committed by GitHub
commit 61afcbcadf
6 changed files with 117 additions and 22 deletions

View File

@ -31,6 +31,36 @@ add_definitions(-DORCT2_RESOURCE_DIR="${ORCT2_RESOURCE_DIR}")
add_definitions(-DHAVE_CONFIG_H)
add_definitions(-DCURL_STATICLIB)
# Define current git branch.
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE OPENRCT2_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
add_definitions(-DOPENRCT2_BRANCH="${OPENRCT2_BRANCH}")
# Define commit hash.
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE OPENRCT2_COMMIT_SHA1
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
add_definitions(-DOPENRCT2_COMMIT_SHA1="${OPENRCT2_COMMIT_SHA1}")
# Define short commit hash.
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE OPENRCT2_COMMIT_SHA1_SHORT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
add_definitions(-DOPENRCT2_COMMIT_SHA1_SHORT="${OPENRCT2_COMMIT_SHA1_SHORT}")
INCLUDE(FindPkgConfig)
# Options

View File

@ -346,6 +346,7 @@
D49766831D03B9FE002222CD /* SoftwareDrawingEngine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D49766811D03B9FE002222CD /* SoftwareDrawingEngine.cpp */; };
D49766861D03BAA5002222CD /* NewDrawing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D49766841D03BAA5002222CD /* NewDrawing.cpp */; };
D49766891D03BABB002222CD /* rain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D49766871D03BABB002222CD /* rain.cpp */; };
D4CA88661D4E64C800060C11 /* version.c in Sources */ = {isa = PBXBuildFile; fileRef = D4CA88651D4E64C800060C11 /* version.c */; };
D4EC48E61C2637710024B507 /* g2.dat in Resources */ = {isa = PBXBuildFile; fileRef = D4EC48E31C2637710024B507 /* g2.dat */; };
D4EC48E71C2637710024B507 /* language in Resources */ = {isa = PBXBuildFile; fileRef = D4EC48E41C2637710024B507 /* language */; };
D4EC48E81C2637710024B507 /* title in Resources */ = {isa = PBXBuildFile; fileRef = D4EC48E51C2637710024B507 /* title */; };
@ -1007,6 +1008,7 @@
D497668A1D03BAC8002222CD /* IDrawingContext.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; path = IDrawingContext.h; sourceTree = "<group>"; usesTabs = 0; };
D497668B1D03BAC8002222CD /* IDrawingEngine.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; path = IDrawingEngine.h; sourceTree = "<group>"; usesTabs = 0; };
D497D0781C20FD52002BF46A /* OpenRCT2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OpenRCT2.app; sourceTree = BUILT_PRODUCTS_DIR; };
D4CA88651D4E64C800060C11 /* version.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = version.c; sourceTree = "<group>"; };
D4EC48E31C2637710024B507 /* g2.dat */ = {isa = PBXFileReference; lastKnownFileType = file; name = g2.dat; path = data/g2.dat; sourceTree = SOURCE_ROOT; };
D4EC48E41C2637710024B507 /* language */ = {isa = PBXFileReference; lastKnownFileType = folder; name = language; path = data/language; sourceTree = SOURCE_ROOT; };
D4EC48E51C2637710024B507 /* title */ = {isa = PBXFileReference; lastKnownFileType = folder; name = title; path = data/title; sourceTree = SOURCE_ROOT; };
@ -1256,6 +1258,7 @@
D44271821CC81B3200D84D28 /* scenario_sources.c */,
D44271831CC81B3200D84D28 /* scenario.c */,
D44271861CC81B3200D84D28 /* title.c */,
D4CA88651D4E64C800060C11 /* version.c */,
D44270CE1CC81B3200D84D28 /* addresses.h */,
D44270D51CC81B3200D84D28 /* cheats.h */,
D44270DD1CC81B3200D84D28 /* common.h */,
@ -2011,6 +2014,7 @@
D4EC48E91C264FC20024B507 /* Download Libraries */,
D4EC012A1C25532B00DAFE69 /* Setup AppIcon */,
D40F4E1D1C2528D5009582C9 /* Create Segment Files */,
D4CA88671D4E962100060C11 /* Get Git Variables */,
D497D0741C20FD52002BF46A /* Sources */,
D497D0751C20FD52002BF46A /* Frameworks */,
D41B74201C210B190080A7B9 /* Embed Frameworks */,
@ -2108,6 +2112,21 @@
shellPath = /bin/sh;
shellScript = "\"${TARGET_BUILD_DIR}/${EXECUTABLE_PATH}\" sprite build \"${SRCROOT}/data/g2.dat\" \"${SRCROOT}/resources/g2/\"";
};
D4CA88671D4E962100060C11 /* Get Git Variables */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Get Git Variables";
outputPaths = (
"$(DERIVED_FILE_DIR)/gitversion.h",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "echo \"#define\" OPENRCT2_BRANCH \\\"$(git rev-parse --abbrev-ref HEAD)\\\" > \"${DERIVED_FILE_DIR}/gitversion.h\"\necho \"#define\" OPENRCT2_COMMIT_SHA1 \\\"$(git rev-parse HEAD)\\\" >> \"${DERIVED_FILE_DIR}/gitversion.h\"\necho \"#define\" OPENRCT2_COMMIT_SHA1_SHORT \\\"$(git rev-parse --short HEAD)\\\" >> \"${DERIVED_FILE_DIR}/gitversion.h\"";
};
D4EC012A1C25532B00DAFE69 /* Setup AppIcon */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@ -2285,6 +2304,7 @@
D44272931CC81B3200D84D28 /* top_toolbar.c in Sources */,
D43407DA1D0E14BE00C2B3D4 /* FillRectShader.cpp in Sources */,
D464FEBE1D31A66E00CBABAC /* MemoryStream.cpp in Sources */,
D4CA88661D4E64C800060C11 /* version.c in Sources */,
D44271F61CC81B3200D84D28 /* audio.c in Sources */,
D442728A1CC81B3200D84D28 /* tile_inspector.c in Sources */,
D43407D91D0E14BE00C2B3D4 /* DrawLineShader.cpp in Sources */,
@ -2513,6 +2533,7 @@
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
OPENGL_NO_LINK,
"OPENRCT2_BUILD_INFO_HEADER=\"\\\"$(DERIVED_FILE_DIR)/gitversion.h\\\"\"",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
@ -2555,7 +2576,10 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_PREPROCESSOR_DEFINITIONS = OPENGL_NO_LINK;
GCC_PREPROCESSOR_DEFINITIONS = (
OPENGL_NO_LINK,
"OPENRCT2_BUILD_INFO_HEADER=\"\\\"$(DERIVED_FILE_DIR)/gitversion.h\\\"\"",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES;

View File

@ -273,6 +273,7 @@
<ClCompile Include="src\title.c" />
<ClCompile Include="src\util\sawyercoding.c" />
<ClCompile Include="src\util\util.c" />
<ClCompile Include="src\version.c" />
<ClCompile Include="src\windows\about.c" />
<ClCompile Include="src\windows\banner.c" />
<ClCompile Include="src\windows\cheats.c" />

View File

@ -37,6 +37,7 @@
#include "title.h"
#include "util/sawyercoding.h"
#include "util/util.h"
#include "version.h"
#include "world/mapgen.h"
#if defined(__unix__)
@ -87,14 +88,14 @@ void openrct2_write_full_version_info(utf8 *buffer, size_t bufferSize)
strcat(buffer, OPENRCT2_VERSION);
// Build information
if (!str_is_null_or_empty(OPENRCT2_BRANCH)) {
sprintf(strchr(buffer, 0), "-%s", OPENRCT2_BRANCH);
if (!str_is_null_or_empty(gGitBranch)) {
sprintf(strchr(buffer, 0), "-%s", gGitBranch);
}
if (!str_is_null_or_empty(OPENRCT2_COMMIT_SHA1_SHORT)) {
sprintf(strchr(buffer, 0), " build %s", OPENRCT2_COMMIT_SHA1_SHORT);
if (!str_is_null_or_empty(gCommitSha1Short)) {
sprintf(strchr(buffer, 0), " build %s", gCommitSha1Short);
}
if (!str_is_null_or_empty(OPENRCT2_BUILD_SERVER)) {
sprintf(strchr(buffer, 0), " provided by %s", OPENRCT2_BUILD_SERVER);
if (!str_is_null_or_empty(gBuildServer)) {
sprintf(strchr(buffer, 0), " provided by %s", gBuildServer);
}
#if DEBUG

49
src/version.c Normal file
View File

@ -0,0 +1,49 @@
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 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, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#ifdef OPENRCT2_BUILD_INFO_HEADER
#include OPENRCT2_BUILD_INFO_HEADER
#endif
#ifdef OPENRCT2_BUILD_NUMBER
const char *gBuildNumber = OPENRCT2_BUILD_NUMBER;
#else
const char *gBuildNumber = "";
#endif
#ifdef OPENRCT2_BUILD_SERVER
const char *gBuildServer = OPENRCT2_BUILD_SERVER;
#else
const char *gBuildServer = "";
#endif
#ifdef OPENRCT2_BRANCH
const char *gGitBranch = OPENRCT2_BRANCH;
#else
const char *gGitBranch = "";
#endif
#ifdef OPENRCT2_COMMIT_SHA1
const char *gCommitSha1 = OPENRCT2_COMMIT_SHA1;
#else
const char *gCommitSha1 = "";
#endif
#ifdef OPENRCT2_COMMIT_SHA1_SHORT
const char *gCommitSha1Short = OPENRCT2_COMMIT_SHA1_SHORT;
#else
const char *gCommitSha1Short = "";
#endif

View File

@ -40,20 +40,10 @@
#define OPENRCT2_TIMESTAMP __DATE__ " " __TIME__
// The following constants are for automated build servers
#ifndef OPENRCT2_BUILD_NUMBER
#define OPENRCT2_BUILD_NUMBER ""
#endif
#ifndef OPENRCT2_BUILD_SERVER
#define OPENRCT2_BUILD_SERVER ""
#endif
#ifndef OPENRCT2_BRANCH
#define OPENRCT2_BRANCH "develop"
#endif
#ifndef OPENRCT2_COMMIT_SHA1
#define OPENRCT2_COMMIT_SHA1 ""
#endif
#ifndef OPENRCT2_COMMIT_SHA1_SHORT
#define OPENRCT2_COMMIT_SHA1_SHORT ""
#endif
extern const char *gBuildNumber;
extern const char *gBuildServer;
extern const char *gGitBranch;
extern const char *gCommitSha1;
extern const char *gCommitSha1Short;
#endif