All: Make version.c

This commit is contained in:
Jeffrey Pfau 2015-05-15 08:37:08 -07:00
parent 284f4df31b
commit 47d945bf75
12 changed files with 95 additions and 16 deletions

View File

@ -77,6 +77,44 @@ set(LIB_VERSION_PATCH 0)
set(LIB_VERSION_ABI 0.3)
set(LIB_VERSION_STRING ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH})
execute_process(COMMAND git describe --always --abbrev=40 --dirty OUTPUT_VARIABLE GIT_COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git describe --always --dirty OUTPUT_VARIABLE GIT_COMMIT_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git symbolic-ref --short HEAD OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND git rev-list HEAD --count OUTPUT_VARIABLE GIT_REV OUTPUT_STRIP_TRAILING_WHITESPACE)
if(GIT_REV STREQUAL "")
set(GIT_REV -1)
endif()
if(GIT_BRANCH STREQUAL "")
set(VERSION_STRING ${LIB_VERSION_STRING})
else()
if(GIT_BRANCH STREQUAL "master")
set(VERSION_STRING ${GIT_REV}-${GIT_COMMIT_SHORT})
else()
set(VERSION_STRING ${GIT_BRANCH}-${GIT_REV}-${GIT_COMMIT_SHORT})
endif()
if(NOT LIB_VERSION_ABI STREQUAL GIT_BRANCH)
set(VERSION_STRING ${LIB_VERSION_ABI}-${VERSION_STRING})
endif()
endif()
add_custom_target(version ALL touch ${CMAKE_SOURCE_DIR}/src/util/version.c.in
COMMAND ${CMAKE_COMMAND}
-DGIT_COMMIT=${GIT_COMMIT}
-DGIT_COMMIT_SHORT=${GIT_COMMIT_SHORT}
-DGIT_BRANCH=${GIT_BRANCH}
-DGIT_REV=${GIT_REV}
-DBINARY_NAME=${BINARY_NAME}
-DPROJECT_NAME=${PROJECT_NAME}
-DVERSION_STRING=${VERSION_STRING}
-D${BINARY_NAME}_SOURCE_DIR=${CMAKE_SOURCE_DIR}
-P ${CMAKE_SOURCE_DIR}/version.cmake
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
include(${CMAKE_SOURCE_DIR}/version.cmake)
list(APPEND UTIL_SRC ${CMAKE_BINARY_DIR}/version.c)
# Advanced settings
set(BUILD_LTO ON CACHE BOOL "Build with link-time optimization")
set(BUILD_PGO OFF CACHE BOOL "Build with profiling-guided optimization")
@ -96,8 +134,6 @@ elseif(BUILD_PGO AND PGO_STAGE_2)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${PGO_POST_FLAGS}")
endif()
add_definitions(-DBINARY_NAME="${BINARY_NAME}" -DPROJECT_NAME="${PROJECT_NAME}" -DPROJECT_VERSION="${LIB_VERSION_STRING}")
# Feature dependencies
set(FEATURES)
if(CMAKE_SYSTEM_NAME MATCHES .*BSD)
@ -329,11 +365,14 @@ if(BUILD_SHARED)
add_library(${BINARY_NAME}-static STATIC ${SRC})
set_target_properties(${BINARY_NAME}-static PROPERTIES COMPILE_DEFINITIONS "${FEATURE_DEFINES}")
install(TARGETS ${BINARY_NAME}-static DESTINATION lib COMPONENT lib${BINARY_NAME})
add_dependencies(${BINARY_NAME}-static version)
endif()
else()
add_library(${BINARY_NAME} STATIC ${SRC})
endif()
add_dependencies(${BINARY_NAME} version)
target_link_libraries(${BINARY_NAME} m ${DEBUGGER_LIB} ${OS_LIB} ${DEPENDENCY_LIB})
install(TARGETS ${BINARY_NAME} DESTINATION lib COMPONENT lib${BINARY_NAME})
set_target_properties(${BINARY_NAME} PROPERTIES VERSION ${LIB_VERSION_STRING} SOVERSION ${LIB_VERSION_ABI} COMPILE_DEFINITIONS "${FEATURE_DEFINES}")

View File

@ -865,7 +865,7 @@ static unsigned char _tabComplete(EditLine* elstate, int ch) {
static void _cliDebuggerInit(struct ARMDebugger* debugger) {
struct CLIDebugger* cliDebugger = (struct CLIDebugger*) debugger;
// TODO: get argv[0]
cliDebugger->elstate = el_init(BINARY_NAME, stdin, stdout, stderr);
cliDebugger->elstate = el_init(binaryName, stdin, stdout, stderr);
el_set(cliDebugger->elstate, EL_PROMPT, _prompt);
el_set(cliDebugger->elstate, EL_EDITOR, "emacs");

View File

@ -129,12 +129,12 @@ void GBAConfigDirectory(char* out, size_t outLength) {
char* home = getenv("HOME");
snprintf(out, outLength, "%s/.config", home);
mkdir(out, 0755);
snprintf(out, outLength, "%s/.config/%s", home, BINARY_NAME);
snprintf(out, outLength, "%s/.config/%s", home, binaryName);
mkdir(out, 0755);
#else
char home[MAX_PATH];
SHGetFolderPath(0, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, home);
snprintf(out, outLength, "%s\\%s", home, PROJECT_NAME);
snprintf(out, outLength, "%s\\%s", home, projectName);
CreateDirectoryA(out, NULL);
#endif
}

View File

@ -5,6 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "libretro.h"
#include "util/common.h"
#include "gba/gba.h"
#include "gba/renderers/video-software.h"
#include "gba/serialize.h"
@ -66,8 +68,8 @@ void retro_set_input_state(retro_input_state_t input) {
void retro_get_system_info(struct retro_system_info* info) {
info->need_fullpath = false;
info->valid_extensions = "gba";
info->library_version = PROJECT_VERSION;
info->library_name = PROJECT_NAME;
info->library_version = projectVersion;
info->library_name = projectName;
info->block_extract = false;
}

View File

@ -28,8 +28,8 @@ GBAApp::GBAApp(int& argc, char* argv[])
SocketSubsystemInit();
qRegisterMetaType<const uint32_t*>("const uint32_t*");
QApplication::setApplicationName(PROJECT_NAME);
QApplication::setApplicationVersion(PROJECT_VERSION);
QApplication::setApplicationName(projectName);
QApplication::setApplicationVersion(projectVersion);
#ifndef Q_OS_MAC
m_window.show();

View File

@ -62,7 +62,7 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
, m_shortcutController(new ShortcutController(this))
, m_playerId(playerId)
{
setWindowTitle(PROJECT_NAME);
setWindowTitle(projectName);
setFocusPolicy(Qt::StrongFocus);
setAcceptDrops(true);
m_controller = new GameController(this);
@ -506,7 +506,7 @@ void Window::gameStarted(GBAThread* context) {
action->setDisabled(false);
}
appendMRU(context->fname);
setWindowTitle(tr(PROJECT_NAME " - %1").arg(title));
setWindowTitle(tr("%1 - %2").arg(projectName).arg(title));
attachWidget(m_display);
#ifndef Q_OS_MAC
@ -523,7 +523,7 @@ void Window::gameStopped() {
foreach (QAction* action, m_gameActions) {
action->setDisabled(true);
}
setWindowTitle(tr(PROJECT_NAME));
setWindowTitle(projectName);
detachWidget(m_display);
m_screenWidget->setLockAspectRatio(m_logo.width(), m_logo.height());
m_screenWidget->setPixmap(m_logo);
@ -577,13 +577,13 @@ void Window::showFPS() {
title += tr(" - Player %1 of %2").arg(m_playerId + 1).arg(multiplayer->attached());
}
if (m_frameList.isEmpty()) {
setWindowTitle(tr(PROJECT_NAME " - %1").arg(title));
setWindowTitle(tr("%1 - %2").arg(projectName).arg(title));
return;
}
qint64 interval = m_frameList.first().msecsTo(m_frameList.last());
float fps = (m_frameList.count() - 1) * 10000.f / interval;
fps = round(fps) / 10.f;
setWindowTitle(tr(PROJECT_NAME " - %1 (%2 fps)").arg(title).arg(fps));
setWindowTitle(tr("%1 - %2 (%3 fps)").arg(projectName).arg(title).arg(fps));
}
void Window::openStateWindow(LoadSave ls) {

View File

@ -75,7 +75,7 @@ bool GBASDLGLInit(struct SDLSoftwareRenderer* renderer) {
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
renderer->window = SDL_CreateWindow(PROJECT_NAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer->viewportWidth, renderer->viewportHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | (SDL_WINDOW_FULLSCREEN_DESKTOP * renderer->player.fullscreen));
renderer->window = SDL_CreateWindow(projectName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer->viewportWidth, renderer->viewportHeight, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | (SDL_WINDOW_FULLSCREEN_DESKTOP * renderer->player.fullscreen));
SDL_GL_CreateContext(renderer->window);
SDL_GL_SetSwapInterval(1);
SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight);

View File

@ -28,7 +28,7 @@ bool GBASDLSWInit(struct SDLSoftwareRenderer* renderer) {
#endif
#if SDL_VERSION_ATLEAST(2, 0, 0)
renderer->window = SDL_CreateWindow(PROJECT_NAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer->viewportWidth, renderer->viewportHeight, SDL_WINDOW_OPENGL | (SDL_WINDOW_FULLSCREEN_DESKTOP * renderer->player.fullscreen));
renderer->window = SDL_CreateWindow(projectName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer->viewportWidth, renderer->viewportHeight, SDL_WINDOW_OPENGL | (SDL_WINDOW_FULLSCREEN_DESKTOP * renderer->player.fullscreen));
SDL_GetWindowSize(renderer->window, &renderer->viewportWidth, &renderer->viewportHeight);
renderer->player.window = renderer->window;
renderer->sdlRenderer = SDL_CreateRenderer(renderer->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

View File

@ -21,6 +21,8 @@
#include <strings.h>
#include <unistd.h>
#include "version.h"
#define UNUSED(V) (void)(V)
#ifndef M_PI

14
src/util/version.c.in Normal file
View File

@ -0,0 +1,14 @@
/* Copyright (c) 2013-2015 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "util/version.h"
const char* const gitCommit = "${GIT_COMMIT}";
const char* const gitCommitShort = "${GIT_COMMIT_SHORT}";
const char* const gitBranch = "${GIT_BRANCH}";
const int gitRevision = ${GIT_REV};
const char* const binaryName = "${BINARY_NAME}";
const char* const projectName = "${PROJECT_NAME}";
const char* const projectVersion = "${VERSION_STRING}";

17
src/util/version.h Normal file
View File

@ -0,0 +1,17 @@
/* Copyright (c) 2013-2015 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef VERSION_H
#define VERSION_H
extern const char* const gitCommit;
extern const char* const gitCommitShort;
extern const char* const gitBranch;
extern const int gitRevision;
extern const char* const binaryName;
extern const char* const projectName;
extern const char* const projectVersion;
#endif

5
version.cmake Normal file
View File

@ -0,0 +1,5 @@
if(NOT ${BINARY_NAME}_SOURCE_DIR)
set(${BINARY_NAME}_SOURCE_DIR ${CMAKE_SOURCE_DIR})
endif()
configure_file("${${BINARY_NAME}_SOURCE_DIR}/src/util/version.c.in" "${CMAKE_CURRENT_BINARY_DIR}/version.c")