Commit 2179215a authored by Rafael Kitover's avatar Rafael Kitover
Browse files

fix rebuilds on git changes

Use cmake to generate the version.h from version.h.in which is a cleaned
up version of the old version.h with the git short sha into the build
directory, and include the version.h from there.

Continue to use the GetGitRevisionDescription plugin to make the cmake
configuration state depend on the current sha of HEAD, but throw away
the results (for the time being.)

This makes rebuilds after git changes such as a commit only recompile a
couple of files instead of the whole tree.
parent 23ed930d
...@@ -102,27 +102,26 @@ if( NOT ENABLE_DEBUGGER AND ENABLE_SDL ) ...@@ -102,27 +102,26 @@ if( NOT ENABLE_DEBUGGER AND ENABLE_SDL )
message( SEND_ERROR "The SDL port can't be built without debugging support" ) message( SEND_ERROR "The SDL port can't be built without debugging support" )
endif( NOT ENABLE_DEBUGGER AND ENABLE_SDL ) endif( NOT ENABLE_DEBUGGER AND ENABLE_SDL )
# Set the version number with -DVERSION=X.X.X-uber find_package(Git)
IF( NOT VERSION ) if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
#Will need to change this over to git INCLUDE(GetGitRevisionDescription)
SET( VERSION "https://github.com/visualboyadvance-m/visualboyadvance-m" ) EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD OUTPUT_VARIABLE SHORT_SHA OUTPUT_STRIP_TRAILING_WHITESPACE)
#openmw does this SET(REVISION ${SHORT_SHA} CACHE STRING "git short sha" FORCE)
if(EXISTS ${PROJECT_SOURCE_DIR}/.git)
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/shallow) # only use the plugin to tie the configure state to the sha to force rebuilds
find_package(Git) # of files that depend on version.h
if(GIT_FOUND) include(GetGitRevisionDescription)
include(GetGitRevisionDescription) get_git_head_revision(REFSPEC COMMITHASH)
get_git_head_revision(REFSPEC COMMITHASH) else()
SET(VERSION "GIT Commit: ${COMMITHASH}") message(WARNING "Git not found, cannot set version info")
else(GIT_FOUND)
message(WARNING "Git executable not found") SET(REVISION "unknown")
endif(GIT_FOUND) endif()
else(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/shallow)
message(STATUS "Shallow Git clone detected, not attempting to retrieve version info") # generate version.h
endif(NOT EXISTS ${PROJECT_SOURCE_DIR}/.git/shallow) include_directories(${CMAKE_BINARY_DIR})
endif(EXISTS ${PROJECT_SOURCE_DIR}/.git) configure_file("${CMAKE_SOURCE_DIR}/src/version.h.in" "${CMAKE_BINARY_DIR}/version.h" @ONLY)
ENDIF( NOT VERSION )
IF(CMAKE_BUILD_TYPE STREQUAL "Debug") IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
ADD_DEFINITIONS(-DDEBUG) ADD_DEFINITIONS(-DDEBUG)
...@@ -212,7 +211,7 @@ INCLUDE(GNUInstallDirs) ...@@ -212,7 +211,7 @@ INCLUDE(GNUInstallDirs)
# C defines # C defines
ADD_DEFINITIONS (-DHAVE_NETINET_IN_H -DHAVE_ARPA_INET_H -DHAVE_ZLIB_H -DFINAL_VERSION -DSDL -DUSE_OPENGL -DSYSCONF_INSTALL_DIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}" -DWITH_LIRC=${WITHLIRC}) ADD_DEFINITIONS (-DHAVE_NETINET_IN_H -DHAVE_ARPA_INET_H -DHAVE_ZLIB_H -DFINAL_VERSION -DSDL -DUSE_OPENGL -DSYSCONF_INSTALL_DIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}" -DWITH_LIRC=${WITHLIRC})
ADD_DEFINITIONS (-DVERSION="${VERSION}" -DPKGDATADIR="${CMAKE_INSTALL_FULL_DATADIR}/vbam" -DPACKAGE=) ADD_DEFINITIONS (-DPKGDATADIR="${CMAKE_INSTALL_FULL_DATADIR}/vbam" -DPACKAGE=)
if( ENABLE_LINK ) if( ENABLE_LINK )
# IPC linking code needs sem_timedwait which can be either in librt or pthreads # IPC linking code needs sem_timedwait which can be either in librt or pthreads
...@@ -449,7 +448,6 @@ SET(HDR_MAIN ...@@ -449,7 +448,6 @@ SET(HDR_MAIN
src/AutoBuild.h src/AutoBuild.h
src/System.h src/System.h
src/Util.h src/Util.h
src/version.h
src/common/array.h src/common/array.h
src/common/ConfigManager.h src/common/ConfigManager.h
src/common/dictionary.h src/common/dictionary.h
......
...@@ -18,6 +18,12 @@ ...@@ -18,6 +18,12 @@
# and adjusting the output so that it tests false if there was no exact # and adjusting the output so that it tests false if there was no exact
# matching tag. # matching tag.
# #
# git_local_changes(<var>)
#
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
# Uses the return code of "git diff-index --quiet HEAD --".
# Does not regard untracked files.
#
# Requires CMake 2.6 or newer (uses the 'function' command) # Requires CMake 2.6 or newer (uses the 'function' command)
# #
# Original Author: # Original Author:
...@@ -31,7 +37,7 @@ ...@@ -31,7 +37,7 @@
# http://www.boost.org/LICENSE_1_0.txt) # http://www.boost.org/LICENSE_1_0.txt)
if(__get_git_revision_description) if(__get_git_revision_description)
return() return()
endif() endif()
set(__get_git_revision_description YES) set(__get_git_revision_description YES)
...@@ -40,116 +46,123 @@ set(__get_git_revision_description YES) ...@@ -40,116 +46,123 @@ set(__get_git_revision_description YES)
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
function(get_git_head_revision _refspecvar _hashvar) function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git") set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git # We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return() return()
endif() endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
set(GIT_DIR "${GIT_PARENT_DIR}/.git") endwhile()
endwhile() # check if this is a submodule
if(NOT IS_DIRECTORY ${GIT_DIR})
# check if this is a submodule file(READ ${GIT_DIR} submodule)
if(NOT IS_DIRECTORY ${GIT_DIR}) string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
file(READ ${GIT_DIR} submodule) get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) endif()
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
endif() if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") endif()
if(NOT EXISTS "${GIT_DATA}") if(NOT EXISTS "${GIT_DIR}/HEAD")
file(MAKE_DIRECTORY "${GIT_DATA}") return()
endif() endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
if(NOT EXISTS "${GIT_DIR}/HEAD") configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
return()
endif() configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
set(HEAD_FILE "${GIT_DATA}/HEAD") @ONLY)
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) include("${GIT_DATA}/grabRef.cmake")
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
"${GIT_DATA}/grabRef.cmake" @ONLY) set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
include("${GIT_DATA}/grabRef.cmake")
set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction() endfunction()
function(git_describe _var) function(git_describe _var)
#get_git_head_revision(refspec hash) if(NOT GIT_FOUND)
find_package(Git QUIET)
if(NOT GIT_FOUND) endif()
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) get_git_head_revision(refspec hash)
return() if(NOT GIT_FOUND)
endif() set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
#if(NOT hash) endif()
# set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) if(NOT hash)
# return() set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
#endif() return()
endif()
# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR # TODO sanitize
# (ARGN MATCHES "||") OR #if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "\\;")) # (ARGN MATCHES "||") OR
# message("Please report the following error to the project!") # (ARGN MATCHES "\\;"))
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") # message("Please report the following error to the project!")
#endif() # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()
#message(STATUS "Arguments to execute_process: ${ARGN}")
#message(STATUS "Arguments to execute_process: ${ARGN}")
execute_process(COMMAND
"${GIT_EXECUTABLE}" execute_process(COMMAND
describe "${GIT_EXECUTABLE}"
#${hash} describe
${ARGN} ${hash}
WORKING_DIRECTORY ${ARGN}
"${CMAKE_SOURCE_DIR}" WORKING_DIRECTORY
RESULT_VARIABLE "${CMAKE_CURRENT_SOURCE_DIR}"
res RESULT_VARIABLE
OUTPUT_VARIABLE res
out OUTPUT_VARIABLE
OUTPUT_STRIP_TRAILING_WHITESPACE) out
ERROR_QUIET
if(NOT res EQUAL 0) OUTPUT_STRIP_TRAILING_WHITESPACE)
set(out "${out}-${res}-NOTFOUND") if(NOT res EQUAL 0)
endif() set(out "${out}-${res}-NOTFOUND")
endif()
set(${_var} "${out}" PARENT_SCOPE)
set(${_var} "${out}" PARENT_SCOPE)
endfunction() endfunction()
function(get_git_tag_revision _var) function(git_get_exact_tag _var)
if(NOT GIT_FOUND) git_describe(out --exact-match ${ARGN})
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) set(${_var} "${out}" PARENT_SCOPE)
return()
endif()
execute_process(COMMAND
"${GIT_EXECUTABLE}"
rev-list
${ARGN}
WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()
set(${_var} "${out}" PARENT_SCOPE)
endfunction() endfunction()
function(git_local_changes _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
return()
endif()
execute_process(COMMAND
"${GIT_EXECUTABLE}"
diff-index --quiet HEAD --
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(res EQUAL 0)
set(${_var} "CLEAN" PARENT_SCOPE)
else()
set(${_var} "DIRTY" PARENT_SCOPE)
endif()
endfunction()
# #
# Internal file for GetGitRevisionDescription.cmake # Internal file for GetGitRevisionDescription.cmake
# #
# Requires CMake 2.6 or newer (uses the 'function' command) # Requires CMake 2.6 or newer (uses the 'function' command)
...@@ -23,9 +23,12 @@ if(HEAD_CONTENTS MATCHES "ref") ...@@ -23,9 +23,12 @@ if(HEAD_CONTENTS MATCHES "ref")
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}") if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}") else()
configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
set(HEAD_HASH "${HEAD_REF}") file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
set(HEAD_HASH "${CMAKE_MATCH_1}")
endif()
endif() endif()
else() else()
# detached HEAD # detached HEAD
......
...@@ -17,7 +17,7 @@ extern "C" { ...@@ -17,7 +17,7 @@ extern "C" {
#include <cmath> #include <cmath>
#include "../AutoBuild.h" #include "../AutoBuild.h"
#include "../version.h" #include "version.h"
#include "../common/Patch.h" #include "../common/Patch.h"
#include "../common/ConfigManager.h" #include "../common/ConfigManager.h"
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#include <time.h> #include <time.h>
#include "../AutoBuild.h" #include "../AutoBuild.h"
#include "../version.h" #include "version.h"
#include "SDL.h" #include "SDL.h"
...@@ -1640,11 +1640,7 @@ void handleRewinds() ...@@ -1640,11 +1640,7 @@ void handleRewinds()
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
#ifndef FINAL_BUILD fprintf(stdout, "%s\n", VBA_NAME_AND_SUBVERSION);
fprintf(stdout, "VBA-M version %s [SDL]\n", "Git:");
#else
fprintf(stdout, "VBA-M version %s [SDL]");
#endif
home = argv[0]; home = argv[0];
SetHome(home); SetHome(home);
......
...@@ -18,45 +18,28 @@ ...@@ -18,45 +18,28 @@
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define VBA_NAME "VisualBoyAdvance-M" #define VBA_NAME "VisualBoyAdvance-M"
#define VBA_CURRENT_VERSION "2.0.0"
#ifdef _WIN32
#ifndef FINAL_BUILD
#define SVN_REV_STR "Git:"
#endif
#else
#ifdef SVN_REV
#define SVN_REV_STR SVN_REV
#else
#define SVN_REV_STR ""
#endif
#endif
#define VBA_FEATURE_STRING "" #define VBA_FEATURE_STRING ""
#ifdef DEBUG #define _STRINGIFY(N) #N
#define VBA_SUBVERSION_STRING " debug"
#elif defined(PUBLIC_RELEASE) #if defined(PUBLIC_RELEASE)
#define VBA_SUBVERSION_STRING "" #define VBA_SUBVERSION_STRING ""
#else #else
#define VBA_SUBVERSION_STRING " (SVN" SVN_REV_STR ")" #define VBA_SUBVERSION_STRING "-" "@REVISION@"
#endif #endif
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define VBA_COMPILER "" #define VBA_COMPILER "msvc"
#define VBA_COMPILER_DETAIL " msvc " _Py_STRINGIZE(_MSC_VER) #define VBA_COMPILER_DETAIL _STRINGIFY(_MSC_VER)
#define _Py_STRINGIZE(X) _Py_STRINGIZE1((X))
#define _Py_STRINGIZE1(X) _Py_STRINGIZE2##X
#define _Py_STRINGIZE2(X) #X
// re:
// http://72.14.203.104/search?q=cache:HG-okth5NGkJ:mail.python.org/pipermail/python-checkins/2002-November/030704.html+_msc_ver+compiler+version+string&hl=en&gl=us&ct=clnk&cd=5
#else #else
// TODO: make for others compilers #define VBA_COMPILER ""
#define VBA_COMPILER "" #define VBA_COMPILER_DETAIL ""
#define VBA_COMPILER_DETAIL ""
#endif #endif
#define VBA_VERSION_STRING \ #define VBA_VERSION_STRING VBA_CURRENT_VERSION VBA_SUBVERSION_STRING VBA_FEATURE_STRING VBA_COMPILER
" " \ #define VBA_NAME_AND_VERSION VBA_NAME " " VBA_VERSION_STRING
"2.0.0" VBA_SUBVERSION_STRING VBA_FEATURE_STRING VBA_COMPILER #define VBA_NAME_AND_SUBVERSION VBA_NAME_AND_VERSION VBA_SUBVERSION_STRING
#define VBA_NAME_AND_VERSION " " VBA_NAME VBA_VERSION_STRING
#define VBA_NAME_AND_SUBVERSION " " VBA_NAME VBA_SUBVERSION_STRING #define VERSION VBA_CURRENT_VERSION VBA_SUBVERSION_STRING
...@@ -24,7 +24,7 @@ extern "C" { ...@@ -24,7 +24,7 @@ extern "C" {
#define CODEC_ID_NONE AV_CODEC_ID_NONE #define CODEC_ID_NONE AV_CODEC_ID_NONE
#endif #endif
#endif #endif
#include "../../version.h" #include "version.h"
#include "../common/ConfigManager.h" #include "../common/ConfigManager.h"
#include "../gb/gbPrinter.h" #include "../gb/gbPrinter.h"
#include "../gba/agbprint.h" #include "../gba/agbprint.h"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <wx/dcbuffer.h> #include <wx/dcbuffer.h>
#include <SDL_joystick.h> #include <SDL_joystick.h>
#include "../../version.h" #include "version.h"
#include "../common/ConfigManager.h" #include "../common/ConfigManager.h"
#include "../common/Patch.h" #include "../common/Patch.h"
#include "../gb/gbPrinter.h" #include "../gb/gbPrinter.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment