xref: /aosp_15_r20/external/libaom/build/cmake/version.cmake (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker#
2*77c1e3ccSAndroid Build Coastguard Worker# Copyright (c) 2017, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker#
4*77c1e3ccSAndroid Build Coastguard Worker# This source code is subject to the terms of the BSD 2 Clause License and the
5*77c1e3ccSAndroid Build Coastguard Worker# Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License was
6*77c1e3ccSAndroid Build Coastguard Worker# not distributed with this source code in the LICENSE file, you can obtain it
7*77c1e3ccSAndroid Build Coastguard Worker# at www.aomedia.org/license/software. If the Alliance for Open Media Patent
8*77c1e3ccSAndroid Build Coastguard Worker# License 1.0 was not distributed with this source code in the PATENTS file, you
9*77c1e3ccSAndroid Build Coastguard Worker# can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker#
11*77c1e3ccSAndroid Build Coastguard Workercmake_minimum_required(VERSION 3.5)
12*77c1e3ccSAndroid Build Coastguard Worker
13*77c1e3ccSAndroid Build Coastguard Workerset(REQUIRED_ARGS "AOM_ROOT" "AOM_CONFIG_DIR" "GIT_EXECUTABLE"
14*77c1e3ccSAndroid Build Coastguard Worker                  "PERL_EXECUTABLE")
15*77c1e3ccSAndroid Build Coastguard Worker
16*77c1e3ccSAndroid Build Coastguard Workerforeach(arg ${REQUIRED_ARGS})
17*77c1e3ccSAndroid Build Coastguard Worker  if("${${arg}}" STREQUAL "")
18*77c1e3ccSAndroid Build Coastguard Worker    message(FATAL_ERROR "${arg} must not be empty.")
19*77c1e3ccSAndroid Build Coastguard Worker  endif()
20*77c1e3ccSAndroid Build Coastguard Workerendforeach()
21*77c1e3ccSAndroid Build Coastguard Worker
22*77c1e3ccSAndroid Build Coastguard Workerinclude("${AOM_ROOT}/build/cmake/util.cmake")
23*77c1e3ccSAndroid Build Coastguard Worker
24*77c1e3ccSAndroid Build Coastguard Worker# Generate the version string for this run.
25*77c1e3ccSAndroid Build Coastguard Workerunset(aom_version)
26*77c1e3ccSAndroid Build Coastguard Workerif(EXISTS "${GIT_EXECUTABLE}")
27*77c1e3ccSAndroid Build Coastguard Worker  execute_process(COMMAND ${GIT_EXECUTABLE}
28*77c1e3ccSAndroid Build Coastguard Worker                          --git-dir=${AOM_ROOT}/.git describe
29*77c1e3ccSAndroid Build Coastguard Worker                          --match=v[0-9]*
30*77c1e3ccSAndroid Build Coastguard Worker                  OUTPUT_VARIABLE aom_version
31*77c1e3ccSAndroid Build Coastguard Worker                  ERROR_QUIET
32*77c1e3ccSAndroid Build Coastguard Worker                  RESULT_VARIABLE version_check_result)
33*77c1e3ccSAndroid Build Coastguard Worker
34*77c1e3ccSAndroid Build Coastguard Worker  if(${version_check_result} EQUAL 0)
35*77c1e3ccSAndroid Build Coastguard Worker    string(STRIP "${aom_version}" aom_version)
36*77c1e3ccSAndroid Build Coastguard Worker
37*77c1e3ccSAndroid Build Coastguard Worker    # Remove the leading 'v' from the version string.
38*77c1e3ccSAndroid Build Coastguard Worker    string(FIND "${aom_version}" "v" v_pos)
39*77c1e3ccSAndroid Build Coastguard Worker    if(${v_pos} EQUAL 0)
40*77c1e3ccSAndroid Build Coastguard Worker      string(SUBSTRING "${aom_version}" 1 -1 aom_version)
41*77c1e3ccSAndroid Build Coastguard Worker    endif()
42*77c1e3ccSAndroid Build Coastguard Worker  else()
43*77c1e3ccSAndroid Build Coastguard Worker    set(aom_version "")
44*77c1e3ccSAndroid Build Coastguard Worker  endif()
45*77c1e3ccSAndroid Build Coastguard Workerendif()
46*77c1e3ccSAndroid Build Coastguard Worker
47*77c1e3ccSAndroid Build Coastguard Workerif("${aom_version}" STREQUAL "")
48*77c1e3ccSAndroid Build Coastguard Worker  set(aom_version "${AOM_ROOT}/CHANGELOG")
49*77c1e3ccSAndroid Build Coastguard Workerendif()
50*77c1e3ccSAndroid Build Coastguard Worker
51*77c1e3ccSAndroid Build Coastguard Workerunset(last_aom_version)
52*77c1e3ccSAndroid Build Coastguard Workerset(version_file "${AOM_CONFIG_DIR}/config/aom_version.h")
53*77c1e3ccSAndroid Build Coastguard Workerif(EXISTS "${version_file}")
54*77c1e3ccSAndroid Build Coastguard Worker  extract_version_string("${version_file}" last_aom_version)
55*77c1e3ccSAndroid Build Coastguard Worker  if("${aom_version}" MATCHES "CHANGELOG$")
56*77c1e3ccSAndroid Build Coastguard Worker    set(aom_version "${last_aom_version}")
57*77c1e3ccSAndroid Build Coastguard Worker  endif()
58*77c1e3ccSAndroid Build Coastguard Workerendif()
59*77c1e3ccSAndroid Build Coastguard Worker
60*77c1e3ccSAndroid Build Coastguard Workerif(NOT "${aom_version}" STREQUAL "${last_aom_version}")
61*77c1e3ccSAndroid Build Coastguard Worker  # TODO(tomfinegan): Perl dependency is unnecessary. CMake can do everything
62*77c1e3ccSAndroid Build Coastguard Worker  # that is done by version.pl on its own (if a bit more verbosely...).
63*77c1e3ccSAndroid Build Coastguard Worker  execute_process(COMMAND ${PERL_EXECUTABLE}
64*77c1e3ccSAndroid Build Coastguard Worker                          "${AOM_ROOT}/build/cmake/version.pl"
65*77c1e3ccSAndroid Build Coastguard Worker                          --version_data=${aom_version}
66*77c1e3ccSAndroid Build Coastguard Worker                          --version_filename=${version_file} VERBATIM)
67*77c1e3ccSAndroid Build Coastguard Workerendif()
68