Skip to content

Commit

Permalink
modified to generate a unique version release string
Browse files Browse the repository at this point in the history
cmake now uses git to generate a unique version release string, which
will consist of the latest tag, and if beyond this tag, will also
contain the number of commits beyond that tag plus the SHA1 commit id;
if git is not available (building from a .zip of .tar.gz download),
then it will use the major, minor and patch numbers set in
CMakeLists.txt; the version numbering also allows for negative patch
numbers, which represents what was prevsiously called preliminary or
developmental releases

modified the program to print this release string instead of the major,
minor and patch numbers directly; and will not output the GPL header
when outputting the version number to be consistent with other programs
  • Loading branch information
thunder422 committed Oct 23, 2012
1 parent ffc74a8 commit 1bba2c3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
35 changes: 29 additions & 6 deletions CMakeLists.txt
Expand Up @@ -32,6 +32,12 @@
# replaced add_definitions, which are for compiler options, with
# set_target_properties where link flags are set for added the
# static linking options
#
# 2012-10-23 streamlined not found check for PROGRAM_AWK
# renamed variables from VERSION to RELEASE
# allow negative patch numbers indicating developmental releases
# added code to get a unique release string using git, and if git
# is not available use the three RELEASE variables

cmake_minimum_required(VERSION 2.8)

Expand All @@ -47,17 +53,34 @@ if (GCC_VERSION VERSION_LESS 4.5)
)
endif (GCC_VERSION VERSION_LESS 4.5)

set(ibcp_VERSION_MAJOR 0)
set(ibcp_VERSION_MINOR 1)
set(ibcp_VERSION_PATCH 16)
set(ibcp_RELEASE_MAJOR 0)
set(ibcp_RELEASE_MINOR 2)
set(ibcp_RELEASE_PATCH -1)

set(ibcp_COPYRIGHT_YEAR 2012)

find_program (PROGRAM_GIT git)
if (PROGRAM_GIT)
execute_process(COMMAND ${PROGRAM_GIT} describe
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE ibcp_RELEASE_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else (PROGRAM_GIT)
set(ibcp_RELEASE_STRING release${ibcp_RELEASE_MAJOR}.${ibcp_RELEASE_MINOR})
if (ibcp_RELEASE_PATCH LESS 0)
set(ibcp_RELEASE_STRING ${ibcp_RELEASE_STRING}${ibcp_RELEASE_PATCH})
else (ibcp_RELEASE_PATCH LESS 0)
set(ibcp_RELEASE_STRING ${ibcp_RELEASE_STRING}.${ibcp_RELEASE_PATCH})
endif (ibcp_RELEASE_PATCH LESS 0)
endif (PROGRAM_GIT)
message(STATUS "Building version: ${ibcp_RELEASE_STRING}")

# find awk executable
find_program (PROGRAM_AWK awk)
if (PROGRAM_AWK STREQUAL "PROGRAM_AWK-NOTFOUND")
message(FATAL_ERROR "required awk program was not found")
endif (PROGRAM_AWK STREQUAL "PROGRAM_AWK-NOTFOUND")
if (NOT PROGRAM_AWK)
message(FATAL_ERROR "required 'awk' program was not found")
endif (NOT PROGRAM_AWK)

# configure a header file to pass some of the CMake settings to the source code
configure_file(
Expand Down
22 changes: 17 additions & 5 deletions ibcp.cpp
Expand Up @@ -96,6 +96,13 @@
// does not include extension (.exe) if present to make
// consistent between windows and linux; also fixed bug for
// linux name (was incorrectly defining new variable within if)
//
// 2012-10-23 get full release string from cmake (ibcp_config.h) instead of
// individual major, minor and patch numbers so that during
// development and git release number is used (to produce a
// unique release number at each commit)
// moved output of version number before gpl header eliminating
// gpl header to match other programs

#include <stdio.h>
#include <stdarg.h> // 2010-06-25: for generic print function
Expand Down Expand Up @@ -279,9 +286,8 @@ bool ibcp_version(char *name, int argc, char *argv[])
return false; // not our options
}
// 2010-03-13: changed to output actual program name
// 2010-04-02: added + 1 so that '\' is no output
printf("%s version %d.%d.%d\n", name, ibcp_VERSION_MAJOR,
ibcp_VERSION_MINOR, ibcp_VERSION_PATCH);
// 2012-10-23: changed to get release string from cmake without 'release'
printf("%s version %s\n", name, ibcp_RELEASE_STRING + 7);
return true;
}

Expand Down Expand Up @@ -316,6 +322,12 @@ int main(int argc, char *argv[])
program_name = program_name == NULL ? argv[0] : program_name + 1;
char *ext = strrchr(program_name, '.');
program_name_len = ext == NULL ? strlen(program_name) : ext - program_name;

// 2012-10-23: moved version output before gpl output
if (ibcp_version(program_name, argc, argv))
{
return 0;
}
print_gpl_header(program_name, program_name_len);

// 2010-06-25: added try block for token initialization
Expand Down Expand Up @@ -359,8 +371,8 @@ int main(int argc, char *argv[])
// 2010-04-25: added "-t" to usage string
// 2011-06-11: added check for version option
// 2012-10-10: replaced test_parser and test_translator with test_ibcp
if (!ibcp_version(program_name, argc, argv)
&& !test_ibcp(translator, parser, table, argc, argv))
// 2012-10-23: moved version output before gpl output
if (!test_ibcp(translator, parser, table, argc, argv))
{
// 2010-05-28: replaced strrchr(argv[1],...) call with 'program_name'
// 2011-06-11: added "-v" to usage string
Expand Down
13 changes: 9 additions & 4 deletions ibcp_config.h.in
Expand Up @@ -2,7 +2,7 @@
//
// Interactive BASIC Compiler Project
// File: ibcp_config.h.in - cmake input file for generating ibcp_config.h
// Copyright (C) 2010-2011 Thunder422
// Copyright (C) 2010-2012 Thunder422
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -21,11 +21,16 @@
// Change History:
//
// 2011-06-11 initial version
//
// 2012-10-23 renamed variables from VERSION to RELEASE
// added new ibcp_RELEASE_STRING

// the configured options and settings for ibcp
// (for passing values from cmake to ibcp source files)
#define ibcp_VERSION_MAJOR @ibcp_VERSION_MAJOR@
#define ibcp_VERSION_MINOR @ibcp_VERSION_MINOR@
#define ibcp_VERSION_PATCH @ibcp_VERSION_PATCH@
#define ibcp_RELEASE_MAJOR @ibcp_RELEASE_MAJOR@
#define ibcp_RELEASE_MINOR @ibcp_RELEASE_MINOR@
#define ibcp_RELEASE_PATCH @ibcp_RELEASE_PATCH@

#define ibcp_COPYRIGHT_YEAR @ibcp_COPYRIGHT_YEAR@

#define ibcp_RELEASE_STRING "@ibcp_RELEASE_STRING@"

0 comments on commit 1bba2c3

Please sign in to comment.