diff --git a/CMakeLists.txt b/CMakeLists.txt index 63d9e2001..f48ddacbb 100644 --- a/CMakeLists.txt +++ b/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") @@ -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}") diff --git a/src/debugger/cli-debugger.c b/src/debugger/cli-debugger.c index 60b75a32d..1da5207d1 100644 --- a/src/debugger/cli-debugger.c +++ b/src/debugger/cli-debugger.c @@ -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"); diff --git a/src/gba/supervisor/config.c b/src/gba/supervisor/config.c index b497218ab..a3e701c56 100644 --- a/src/gba/supervisor/config.c +++ b/src/gba/supervisor/config.c @@ -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 } diff --git a/src/platform/libretro/libretro.c b/src/platform/libretro/libretro.c index 844919765..ec569ebf1 100644 --- a/src/platform/libretro/libretro.c +++ b/src/platform/libretro/libretro.c @@ -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; } diff --git a/src/platform/qt/GBAApp.cpp b/src/platform/qt/GBAApp.cpp index f45a303d6..34b96bc57 100644 --- a/src/platform/qt/GBAApp.cpp +++ b/src/platform/qt/GBAApp.cpp @@ -28,8 +28,8 @@ GBAApp::GBAApp(int& argc, char* argv[]) SocketSubsystemInit(); qRegisterMetaType("const uint32_t*"); - QApplication::setApplicationName(PROJECT_NAME); - QApplication::setApplicationVersion(PROJECT_VERSION); + QApplication::setApplicationName(projectName); + QApplication::setApplicationVersion(projectVersion); #ifndef Q_OS_MAC m_window.show(); diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 814a3c191..b0dc1906e 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -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) { diff --git a/src/platform/sdl/gl-sdl.c b/src/platform/sdl/gl-sdl.c index 975166be7..6760b72cc 100644 --- a/src/platform/sdl/gl-sdl.c +++ b/src/platform/sdl/gl-sdl.c @@ -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); diff --git a/src/platform/sdl/sw-sdl.c b/src/platform/sdl/sw-sdl.c index f44fad38d..ee295e846 100644 --- a/src/platform/sdl/sw-sdl.c +++ b/src/platform/sdl/sw-sdl.c @@ -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); diff --git a/src/util/common.h b/src/util/common.h index 90746f082..baad47523 100644 --- a/src/util/common.h +++ b/src/util/common.h @@ -21,6 +21,8 @@ #include #include +#include "version.h" + #define UNUSED(V) (void)(V) #ifndef M_PI diff --git a/src/util/version.c.in b/src/util/version.c.in new file mode 100644 index 000000000..563361b21 --- /dev/null +++ b/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}"; diff --git a/src/util/version.h b/src/util/version.h new file mode 100644 index 000000000..610a7b610 --- /dev/null +++ b/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 diff --git a/version.cmake b/version.cmake new file mode 100644 index 000000000..32bf65821 --- /dev/null +++ b/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")