Skip to content

Commit

Permalink
- Added git revision SHA1 to be included in version string automatica…
Browse files Browse the repository at this point in the history
…lly.

- Added "GetGitRevisionDescription" cmake modules.
- Added vim swapfiles to ".gitignore".
  • Loading branch information
rooker committed Aug 24, 2013
1 parent 356beff commit 054932e
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
?uild*
.*.swp
28 changes: 21 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# CMake integration by Christian Frisson
SET (CMAKE_C_COMPILER "/usr/bin/clang")
SET (CMAKE_CXX_COMPILER "/usr/bin/clang++")
cmake_minimum_required(VERSION 2.8)
PROJECT(shotdetect)

SET(CMAKE_C_COMPILER "/usr/bin/clang")
SET(CMAKE_CXX_COMPILER "/usr/bin/clang++")
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")


# Get git version information for automatic embedding in version string:

include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
# Take the first 12 characters of the SHA1 as short identifier:
STRING(SUBSTRING ${GIT_SHA1} 0 11 GIT_SHA1_SHORT)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/version.cc.in" "${CMAKE_CURRENT_BINARY_DIR}/version.cc" @ONLY)
list(APPEND SOURCES "${CMAKE_CURRENT_BINARY_DIR}/version.cc" src/version.h)

# Miscellaneous compilation options:

OPTION(USE_WXWIDGETS "Compile GUI app with wxWidgets, otherwise commandline app" ON)
OPTION(USE_POSTGRESQL "Compile with PostgreSQL support" OFF)

Expand Down Expand Up @@ -175,15 +189,15 @@ ELSEIF(WIN32)
ENDIF()

IF(USE_WXWIDGETS AND wxWidgets_FOUND)
SET(${TARGET_NAME}_GUI_SRCS src/main.cc src/ui/dialog_help.cc src/ui/dialog_shotdetect.cc src/ui/process_video_thread.cc)
SET(${TARGET_NAME}_GUI_HDRS src/ui/dialog_help.h src/ui/dialog_shotdetect.h src/ui/process_video_thread.h)
ADD_EXECUTABLE(${TARGET_NAME}-gui ${APP_TYPE} ${${TARGET_NAME}_GUI_SRCS} ${${TARGET_NAME}_GUI_HDRS})
LIST(APPEND ${TARGET_NAME}_GUI_SRCS src/main.cc src/ui/dialog_help.cc src/ui/dialog_shotdetect.cc src/ui/process_video_thread.cc)
LIST(APPEND ${TARGET_NAME}_GUI_HDRS src/ui/dialog_help.h src/ui/dialog_shotdetect.h src/ui/process_video_thread.h)
ADD_EXECUTABLE(${TARGET_NAME}-gui ${APP_TYPE} ${SOURCES} ${${TARGET_NAME}_GUI_SRCS} ${${TARGET_NAME}_GUI_HDRS})
TARGET_LINK_LIBRARIES(${TARGET_NAME}-gui ${TARGET_NAME})
# Make this target optional to install:
SET(TARGETS_TO_INSTALL ${TARGET_NAME}-gui)
ELSE()
SET(${TARGET_NAME}_COMMANDLINE_SRCS src/commandline.cc)
ADD_EXECUTABLE(${TARGET_NAME}-cmd ${${TARGET_NAME}_COMMANDLINE_SRCS})
LIST(APPEND ${TARGET_NAME}_COMMANDLINE_SRCS src/commandline.cc)
ADD_EXECUTABLE(${TARGET_NAME}-cmd ${SOURCES} ${${TARGET_NAME}_COMMANDLINE_SRCS})
TARGET_LINK_LIBRARIES(${TARGET_NAME}-cmd ${TARGET_NAME})
# Make this target optional to install:
SET(TARGETS_TO_INSTALL ${TARGET_NAME}-cmd)
Expand Down
123 changes: 123 additions & 0 deletions cmake/GetGitRevisionDescription.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)

# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)

function(get_git_head_revision _refspecvar _hashvar)
set(GIT_PARENT_DIR "${CMAKE_SOURCE_DIR}")
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories
set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
# We have reached the root directory, we are not in git
set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
return()
endif()
set(GIT_DIR "${GIT_PARENT_DIR}/.git")
endwhile()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()

if(NOT EXISTS "${GIT_DIR}/HEAD")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)

configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake"
@ONLY)
include("${GIT_DATA}/grabRef.cmake")

set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
endfunction()

function(git_describe _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()

# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()

#message(STATUS "Arguments to execute_process: ${ARGN}")

execute_process(COMMAND
"${GIT_EXECUTABLE}"
describe
${hash}
${ARGN}
WORKING_DIRECTORY
"${CMAKE_SOURCE_DIR}"
RESULT_VARIABLE
res
OUTPUT_VARIABLE
out
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()

set(${_var} "${out}" PARENT_SCOPE)
endfunction()

function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var} "${out}" PARENT_SCOPE)
endfunction()
38 changes: 38 additions & 0 deletions cmake/GetGitRevisionDescription.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright Iowa State University 2009-2010.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

set(HEAD_HASH)

file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)

string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}")
configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
set(HEAD_HASH "${HEAD_REF}")
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()

if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()
11 changes: 11 additions & 0 deletions cmake/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Information about used CMake modules and their sources:

*) GetGitRevisionDescription.cmake
Revision: edf459d9f60dd161b973106881f34caa416cd101
Source: https://github.com/rpavlik/cmake-modules

*) GetGitRevisionDescription.cmake.in
Revision: de68fc045649f88c00c1d6c350085b2dfcf5d041
Source: https://github.com/rpavlik/cmake-modules


5 changes: 2 additions & 3 deletions src/commandline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
*/
#include <stdlib.h>

#include "src/version.h"
#include "src/film.h"
#include "src/xml.h"

#define APP_VERSION "2.0.0-git" // This is also being declared in "main.cc"

class xml;
class film;

Expand Down Expand Up @@ -62,7 +61,7 @@ show_help (char **argv)
"-m : generate the thumbnail image\n"
"-r : generate the images in native resolution\n"
"-c : print timecode on x-axis in graph\n",
APP_VERSION,
g_APP_VERSION,
argv[0],
DEFAULT_THRESHOLD
);
Expand Down
7 changes: 3 additions & 4 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
#include <wx/image.h>
#include <wx/cmdline.h>

#include "src/version.h"
#include "src/film.h"
#include "src/ui/dialog_shotdetect.h"
#include "src/xml.h"

#define APP_VERSION "2.0.0-git" // This is also being declared in "commandline.cc"
#include "src/ui/dialog_shotdetect.h"

class xml;
class film;
Expand Down Expand Up @@ -58,7 +57,7 @@ void show_help (char **argv) {
"-m : generate the thumbnail image\n"
"-r : generate the images in native resolution\n"
"-c : print timecode on x-axis in graph\n",
APP_VERSION,
g_APP_VERSION,
argv[0],
DEFAULT_THRESHOLD
);
Expand Down
15 changes: 15 additions & 0 deletions src/version.cc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This file is used for generating and setting shotdetect's
* version string. This is especially useful for embedding
* the repository revision information (e.g. git SHA1).
*/

#include "../src/version.h"

#define GIT_SHA1 "@GIT_SHA1@"
#define GIT_SHA1_SHORT "@GIT_SHA1_SHORT@"

const char g_GIT_SHA1[] = GIT_SHA1;
const char g_GIT_SHA1_SHORT[] = GIT_SHA1_SHORT;
const char g_APP_VERSION[] = "2.0.0-git@GIT_SHA1_SHORT@";

8 changes: 8 additions & 0 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __VERSION_H__
#define __VERSION_H__

extern const char g_GIT_SHA1[];
extern const char g_GIT_SHA1_SHORT[];
extern const char g_APP_VERSION[];

#endif /* !__VERSION_H__ */

0 comments on commit 054932e

Please sign in to comment.