All: Make version.c
Jeffrey Pfau jeffrey@endrift.com
Fri, 15 May 2015 08:37:08 -0700
12 files changed,
95 insertions(+),
16 deletions(-)
M
CMakeLists.txt
→
CMakeLists.txt
@@ -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")@@ -95,8 +133,6 @@ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${PGO_POST_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PGO_POST_FLAGS}") 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)@@ -329,10 +365,13 @@ if(BUILD_STATIC)
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})
M
src/debugger/cli-debugger.c
→
src/debugger/cli-debugger.c
@@ -865,7 +865,7 @@
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");
M
src/gba/supervisor/config.c
→
src/gba/supervisor/config.c
@@ -129,12 +129,12 @@ #ifndef _WIN32
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 }
M
src/platform/libretro/libretro.c
→
src/platform/libretro/libretro.c
@@ -5,6 +5,8 @@ * 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 "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_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; }
M
src/platform/qt/GBAApp.cpp
→
src/platform/qt/GBAApp.cpp
@@ -28,8 +28,8 @@
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();
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -62,7 +62,7 @@ , m_mruMenu(nullptr)
, 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 @@ foreach (QAction* action, m_gameActions) {
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 @@ if (multiplayer && multiplayer->attached() > 1) {
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) {
M
src/platform/sdl/gl-sdl.c
→
src/platform/sdl/gl-sdl.c
@@ -75,7 +75,7 @@ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
#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);
M
src/platform/sdl/sw-sdl.c
→
src/platform/sdl/sw-sdl.c
@@ -28,7 +28,7 @@ #endif
#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);
M
src/util/common.h
→
src/util/common.h
@@ -21,6 +21,8 @@ #include <string.h>
#include <strings.h> #include <unistd.h> +#include "version.h" + #define UNUSED(V) (void)(V) #ifndef M_PI
A
src/util/version.c.in
@@ -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}";
A
src/util/version.h
@@ -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
A
version.cmake
@@ -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")