diff --git a/CMakeLists.txt b/CMakeLists.txt index f3d2576..82585c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ set(CPACK_DEBIAN_PACKAGE_DEPENDS "ruby | ruby-interpreter") INCLUDE(CPack) execute_process( - COMMAND git rev-parse HEAD + COMMAND git rev-parse --short HEAD OUTPUT_VARIABLE GIT_REV OUTPUT_STRIP_TRAILING_WHITESPACE ) @@ -48,7 +48,11 @@ message(STATUS "GIT_DATE = '${GIT_DATE}'") execute_process( WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND ./replace_strings.pl "GIT_REV_STRING=${GIT_REV}" "GIT_DATE_STRING=${GIT_DATE}" bin/cmdtest.rb bin/cmdtest.rb.generated + COMMAND ./replace_strings.pl + "GIT_REV_STRING=${GIT_REV}" + "GIT_DATE_STRING=${GIT_DATE}" + "VERSION=${CPACK_PACKAGE_VERSION}" + bin/cmdtest.rb bin/cmdtest.rb.generated ) diff --git a/bin/cmdtest.rb b/bin/cmdtest.rb index 90e2bf2..46299f7 100755 --- a/bin/cmdtest.rb +++ b/bin/cmdtest.rb @@ -49,10 +49,11 @@ module Cmdtest ORIG_CWD = Dir.pwd - GIT_REV = 'GIT_REV_STRING' - GIT_DATE = 'GIT_DATE_STRING' + GIT_REV = '$GIT_REV_STRING$' + GIT_DATE = '$GIT_DATE_STRING$' + VERSION = '$VERSION$' - VERSION = '1.4' + SHORT_VERSION = '1.4' #---------------------------------------------------------------------- @@ -605,10 +606,10 @@ module Cmdtest opts = _parse_options if opts.shortversion - puts VERSION + puts SHORT_VERSION exit(0) elsif opts.version - puts "Version: " + VERSION + puts "Version: " + (VERSION =~ /^\$/ ? SHORT_VERSION : VERSION) if File.directory?(File.join(TOP_DIR, ".git")) Dir.chdir(TOP_DIR) do git_rev = `git rev-parse HEAD` diff --git a/replace_strings.pl b/replace_strings.pl index 15c6c9f..9027c17 100755 --- a/replace_strings.pl +++ b/replace_strings.pl @@ -21,7 +21,7 @@ open(my $g, '>', $outfile) || die "open($outfile)"; while (my $line = <$f>) { for my $entry (@replace) { my ($old, $new) = @$entry; - $line =~ s/$old/$new/g; + $line =~ s/\$$old\$/$new/g; } print {$g} $line; }