Commit 944cf7ff authored by Tom Finegan's avatar Tom Finegan
Browse files

cmake: Add aom_version.h generation.

BUG=https://bugs.chromium.org/p/aomedia/issues/detail?id=76

Change-Id: I9778eaa1dd67d36bae7953cbd8cbcd893f0aefac
parent c1c6f6a2
......@@ -117,26 +117,28 @@ set(CONFIG_BITSTREAM_DEBUG 0)
set(CONFIG_TILE_GROUPS 0)
set(CONFIG_EC_ADAPT 0)
# TODO(tomfinegan): consume trailing whitespace after configure_file().
# TODO(tomfinegan): consume trailing whitespace after configure_file() when
# target platform check produces empty INLINE and RESTRICT values (aka empty
# values require special casing).
configure_file("${AOM_ROOT}/build/cmake/aom_config.h.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/aom_config.h")
# Read the current git hash.
find_package(Git)
set(AOM_GIT_DESCRIPTION)
set(AOM_GIT_HASH)
if (GIT_FOUND)
# TODO(tomfinegan): Make this smart enough to write a proper version string
# when in a repo that is on a label and clean.
# TODO(tomfinegan): In addition to the one above, also make this a custom
# build rule so users don't have to re-run cmake to create accurately
# versioned cmake builds.
# TODO(tomfinegan): Add build rule so users don't have to re-run cmake to
# create accurately versioned cmake builds.
execute_process(COMMAND ${GIT_EXECUTABLE}
--git-dir=${AOM_ROOT}/.git rev-parse HEAD
OUTPUT_VARIABLE AOM_GIT_HASH)
execute_process(COMMAND ${GIT_EXECUTABLE} --git-dir=${AOM_ROOT}/.git describe
OUTPUT_VARIABLE AOM_GIT_DESCRIPTION ERROR_QUIET)
# Consume the newline at the end of the git output.
string(STRIP ${AOM_GIT_HASH} AOM_GIT_HASH)
else ()
set(AOM_GIT_HASH)
endIf ()
string(STRIP "${AOM_GIT_HASH}" AOM_GIT_HASH)
string(STRIP "${AOM_GIT_DESCRIPTION}" AOM_GIT_DESCRIPTION)
endif ()
# TODO(tomfinegan): An alternative to dumping the configure command line to
# aom_config.c is needed in cmake. Normal cmake generation runs do not make the
......@@ -149,4 +151,19 @@ endIf ()
# information available.
set(AOM_CMAKE_CONFIG "cmake")
configure_file("${AOM_ROOT}/build/cmake/aom_config.c.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/aom_config.c")
"${AOM_CONFIG_DIR}/aom_config.c")
# Find Perl.
find_package(Perl)
if (NOT PERL_FOUND)
message(FATAL_ERROR "Perl is required to build libaom.")
endif ()
# Generate aom_version.h.
if ("${AOM_GIT_DESCRIPTION}" STREQUAL "")
set(AOM_GIT_DESCRIPTION "${AOM_ROOT}/CHANGELOG")
endif ()
execute_process(
COMMAND ${PERL_EXECUTABLE} "${AOM_ROOT}/build/cmake/aom_version.pl"
--version_data=${AOM_GIT_DESCRIPTION}
--version_filename=${AOM_CONFIG_DIR}/aom_version.h)
#!/usr/bin/env perl
##
## Copyright (c) 2016, Alliance for Open Media. All rights reserved
##
## This source code is subject to the terms of the BSD 2 Clause License and
## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
## was not distributed with this source code in the LICENSE file, you can
## obtain it at www.aomedia.org/license/software. If the Alliance for Open
## Media Patent License 1.0 was not distributed with this source code in the
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
##
use strict;
use warnings;
use 5.010;
use Getopt::Long;
my $version_data;
my $version_filename;
GetOptions('version_data=s' => \$version_data,
'version_filename=s' => \$version_filename) or
die("Invalid arg(s): $!");
if (!defined $version_data || length($version_data) == 0 ||
!defined $version_filename || length($version_filename) == 0) {
die("--version_data and --version_filename are required.");
}
# Determine if $version_data is a filename or a git tag/description.
my $version_string;
if (-r $version_data) {
# $version_data is the path to the CHANGELOG. Parse the most recent version.
my $changelog_filename = $version_data;
open(my $changelog_file, '<', $changelog_filename) or
die("Unable to open CHANGELOG @ $changelog_filename: $!.");
while (my $line = <$changelog_file>) {
my @split_line = split(" ", $line, 3);
next if @split_line < 2;
$version_string = $split_line[1];
last if substr($version_string, 0, 1) eq "v";
}
close($changelog_file);
} else {
# $version_data is either a tag name or a full git description, one of:
# tagName OR tagName-commitsSinceTag-shortCommitHash
# In either case we want the first element of the array returned by split.
$version_string = (split("-", $version_data))[0];
}
if (substr($version_string, 0, 1) eq "v") {
$version_string = substr($version_string, 1);
}
my @version_components = split('\.', $version_string, 4);
my $version_major = $version_components[0];
my $version_minor = $version_components[1];
my $version_patch = $version_components[2];
my $version_extra = "";
if (@version_components > 3) {
$version_extra = $version_components[3];
}
open(my $version_file, '>', $version_filename) or
die("Cannot open $version_filename: $!");
my $version_packed = "((VERSION_MAJOR<<16)|(VERSION_MINOR<<8)|(VERSION_PATCH))";
my $year = (localtime)[5] + 1900;
my $lic_block = << "EOF";
/*
* Copyright (c) $year, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
EOF
select $version_file;
print << "EOF";
$lic_block
#define VERSION_MAJOR $version_major
#define VERSION_MINOR $version_minor
#define VERSION_PATCH $version_patch
#define VERSION_EXTRA \"$version_extra\"
#define VERSION_PACKED $version_packed
#define VERSION_STRING_NOSP \"v$version_string\"
#define VERSION_STRING \" v$version_string\"
EOF
close($version_file);
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