From 71225da13537d7d7a6fe01ac5a680f3577a7b0b7 Mon Sep 17 00:00:00 2001 From: Peter Tissen Date: Thu, 15 Jan 2015 02:58:11 +0100 Subject: [PATCH] don't distinguish between windows and unix for no reason --- rpcs3/CMakeLists.txt | 7 +++++++ rpcs3/Gui/AboutDialog.h | 6 +----- rpcs3/Gui/MainFrame.cpp | 6 ------ rpcs3/git-version.cmake | 42 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 rpcs3/git-version.cmake diff --git a/rpcs3/CMakeLists.txt b/rpcs3/CMakeLists.txt index 9245ac9125..c6eb5643db 100644 --- a/rpcs3/CMakeLists.txt +++ b/rpcs3/CMakeLists.txt @@ -5,6 +5,13 @@ include(cotire) project(rpcs3) +# Generate git-version.cpp at build time. +add_custom_target(GitVersion ALL + DEPENDS something_that_never_exists) +add_custom_command(OUTPUT something_that_never_exists + COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/git-version.cmake) + if (CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7.0) message(FATAL_ERROR "GCC ${CMAKE_CXX_COMPILER_VERSION} is too old.") diff --git a/rpcs3/Gui/AboutDialog.h b/rpcs3/Gui/AboutDialog.h index ed6897f2bb..78584d6d3d 100644 --- a/rpcs3/Gui/AboutDialog.h +++ b/rpcs3/Gui/AboutDialog.h @@ -36,11 +36,7 @@ AboutDialog::AboutDialog(wxWindow *parent) t_descr->SetForegroundColour(wxColor(255,255,255)); t_descr->SetPosition(wxPoint(12,50)); -#ifdef _WIN32 - wxStaticText* t_version = new wxStaticText(this, wxID_ANY, wxString::Format(_PRGNAME_" Version : " "git-" RPCS3_GIT_VERSION)); -#else - wxStaticText* t_version = new wxStaticText(this, wxID_ANY, wxString::Format(_PRGNAME_" Version : " _PRGVER_)); -#endif + wxStaticText* t_version = new wxStaticText(this, wxID_ANY, wxString::Format(_PRGNAME_" Version : " RPCS3_GIT_VERSION)); t_version->SetBackgroundColour(wxColor(100,100,100)); t_version->SetForegroundColour(wxColor(200,200,200)); t_version->SetPosition(wxPoint(12,66)); diff --git a/rpcs3/Gui/MainFrame.cpp b/rpcs3/Gui/MainFrame.cpp index 067d537b34..975af52f18 100644 --- a/rpcs3/Gui/MainFrame.cpp +++ b/rpcs3/Gui/MainFrame.cpp @@ -5,9 +5,7 @@ #include "rpcs3.h" #include "MainFrame.h" -#ifdef _WIN32 #include "git-version.h" -#endif #include "Ini.h" #include "Emu/SysCalls/Modules/cellSysutil.h" #include "Emu/RSX/sysutil_video.h" @@ -72,11 +70,7 @@ MainFrame::MainFrame() , m_sys_menu_opened(false) { -#ifdef _WIN32 SetLabel(wxString::Format(_PRGNAME_ " " RPCS3_GIT_VERSION)); -#else - SetLabel(wxString::Format(_PRGNAME_ " " _PRGVER_)); -#endif wxMenuBar* menubar = new wxMenuBar(); diff --git a/rpcs3/git-version.cmake b/rpcs3/git-version.cmake new file mode 100644 index 0000000000..e6b5c86f90 --- /dev/null +++ b/rpcs3/git-version.cmake @@ -0,0 +1,42 @@ +set(GIT_VERSION_FILE "${SOURCE_DIR}/git-version.h") +set(GIT_VERSION "unknown") +set(GIT_VERSION_UPDATE "1") + +find_package(Git) +if(GIT_FOUND) + execute_process(COMMAND ${GIT_EXECUTABLE} describe --always + WORKING_DIRECTORY ${SOURCE_DIR} + RESULT_VARIABLE exit_code + OUTPUT_VARIABLE GIT_VERSION) + if(NOT ${exit_code} EQUAL 0) + message(WARNING "git describe failed, unable to include version.") + endif() + string(STRIP ${GIT_VERSION} GIT_VERSION) +else() + message(WARNING "git not found, unable to include version.") +endif() + +if(EXISTS ${GIT_VERSION_FILE}) + # Don't update if marked not to update. + file(STRINGS ${GIT_VERSION_FILE} match + REGEX "RPCS3_GIT_VERSION_NO_UPDATE 1") + if(NOT ${match} EQUAL "") + set(GIT_VERSION_UPDATE "0") + endif() + + # Don't update if it's already the same. + file(STRINGS ${GIT_VERSION_FILE} match + REGEX "${GIT_VERSION}") + if(NOT ${match} EQUAL "") + set(GIT_VERSION_UPDATE "0") + endif() +endif() + +set(code_string "// This is a generated file.\n\n" + "#define RPCS3_GIT_VERSION \"${GIT_VERSION}\"\;\n\n" + "// If you don't want this file to update/recompile, change to 1.\n" + "#define RPCS3_GIT_VERSION_NO_UPDATE 0\n") + +if ("${GIT_VERSION_UPDATE}" EQUAL "1") + file(WRITE ${GIT_VERSION_FILE} ${code_string}) +endif() \ No newline at end of file