1*c33452fbSAndroid Build Coastguard Worker# Copyright (c) 2016, Intel Corporation 2*c33452fbSAndroid Build Coastguard Worker# All rights reserved. 3*c33452fbSAndroid Build Coastguard Worker# 4*c33452fbSAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without modification, 5*c33452fbSAndroid Build Coastguard Worker# are permitted provided that the following conditions are met: 6*c33452fbSAndroid Build Coastguard Worker# 7*c33452fbSAndroid Build Coastguard Worker# 1. Redistributions of source code must retain the above copyright notice, this 8*c33452fbSAndroid Build Coastguard Worker# list of conditions and the following disclaimer. 9*c33452fbSAndroid Build Coastguard Worker# 10*c33452fbSAndroid Build Coastguard Worker# 2. Redistributions in binary form must reproduce the above copyright notice, 11*c33452fbSAndroid Build Coastguard Worker# this list of conditions and the following disclaimer in the documentation and/or 12*c33452fbSAndroid Build Coastguard Worker# other materials provided with the distribution. 13*c33452fbSAndroid Build Coastguard Worker# 14*c33452fbSAndroid Build Coastguard Worker# 3. Neither the name of the copyright holder nor the names of its contributors 15*c33452fbSAndroid Build Coastguard Worker# may be used to endorse or promote products derived from this software without 16*c33452fbSAndroid Build Coastguard Worker# specific prior written permission. 17*c33452fbSAndroid Build Coastguard Worker# 18*c33452fbSAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19*c33452fbSAndroid Build Coastguard Worker# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20*c33452fbSAndroid Build Coastguard Worker# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21*c33452fbSAndroid Build Coastguard Worker# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22*c33452fbSAndroid Build Coastguard Worker# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23*c33452fbSAndroid Build Coastguard Worker# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24*c33452fbSAndroid Build Coastguard Worker# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25*c33452fbSAndroid Build Coastguard Worker# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26*c33452fbSAndroid Build Coastguard Worker# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27*c33452fbSAndroid Build Coastguard Worker# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*c33452fbSAndroid Build Coastguard Worker 29*c33452fbSAndroid Build Coastguard Worker# Fallback values: 30*c33452fbSAndroid Build Coastguard Workerset(PF_VERSION_MAJOR 0) 31*c33452fbSAndroid Build Coastguard Workerset(PF_VERSION_MINOR 0) 32*c33452fbSAndroid Build Coastguard Workerset(PF_VERSION_PATCH 0) 33*c33452fbSAndroid Build Coastguard Workerset(PF_VERSION_TWEAK 0) 34*c33452fbSAndroid Build Coastguard Workerset(PF_VERSION_SHA1 "g0000000000") 35*c33452fbSAndroid Build Coastguard Workerset(PF_VERSION_DIRTY "") 36*c33452fbSAndroid Build Coastguard Worker 37*c33452fbSAndroid Build Coastguard Worker# Find and set the Parameter Framework's version 38*c33452fbSAndroid Build Coastguard Worker# First, let's see if the user forced a version (i.e. "vX.Y.Z-N") 39*c33452fbSAndroid Build Coastguard Workerif(NOT DEFINED PF_VERSION) 40*c33452fbSAndroid Build Coastguard Worker 41*c33452fbSAndroid Build Coastguard Worker # Else, try to get it from .version (this will happen when 42*c33452fbSAndroid Build Coastguard Worker # building from an archive) 43*c33452fbSAndroid Build Coastguard Worker file(READ "${PROJECT_SOURCE_DIR}/.version" PF_VERSION_FILE_CONTENT) 44*c33452fbSAndroid Build Coastguard Worker 45*c33452fbSAndroid Build Coastguard Worker set(REGEX "tag: (v[0-9.]+)") 46*c33452fbSAndroid Build Coastguard Worker if(PF_VERSION_FILE_CONTENT MATCHES ${REGEX}) 47*c33452fbSAndroid Build Coastguard Worker set(PF_VERSION "${CMAKE_MATCH_1}-0") 48*c33452fbSAndroid Build Coastguard Worker 49*c33452fbSAndroid Build Coastguard Worker else() 50*c33452fbSAndroid Build Coastguard Worker # Or fall back from git 51*c33452fbSAndroid Build Coastguard Worker execute_process(COMMAND git describe --tags --long --dirty --abbrev=12 52*c33452fbSAndroid Build Coastguard Worker WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 53*c33452fbSAndroid Build Coastguard Worker OUTPUT_VARIABLE PF_VERSION 54*c33452fbSAndroid Build Coastguard Worker RESULT_VARIABLE GIT_DESCRIBE_RESULT 55*c33452fbSAndroid Build Coastguard Worker OUTPUT_STRIP_TRAILING_WHITESPACE 56*c33452fbSAndroid Build Coastguard Worker ERROR_QUIET) 57*c33452fbSAndroid Build Coastguard Worker endif() 58*c33452fbSAndroid Build Coastguard Worker 59*c33452fbSAndroid Build Coastguard Workerelse() 60*c33452fbSAndroid Build Coastguard Worker # Set the "nice version string" to the one forced by the user 61*c33452fbSAndroid Build Coastguard Worker set(NICE_PF_VERSION "${PF_VERSION}") 62*c33452fbSAndroid Build Coastguard Workerendif() 63*c33452fbSAndroid Build Coastguard Worker 64*c33452fbSAndroid Build Coastguard Worker# Parse the version number to extract the various fields 65*c33452fbSAndroid Build Coastguard Workerset(REGEX "([0-9]+).([0-9]+).([0-9]+).([0-9]+)(-(g[0-9a-f]+)?)?(-(dirty)?)?") 66*c33452fbSAndroid Build Coastguard Workerif(PF_VERSION MATCHES ${REGEX}) 67*c33452fbSAndroid Build Coastguard Worker set(PF_VERSION_MAJOR ${CMAKE_MATCH_1}) 68*c33452fbSAndroid Build Coastguard Worker set(PF_VERSION_MINOR ${CMAKE_MATCH_2}) 69*c33452fbSAndroid Build Coastguard Worker set(PF_VERSION_PATCH ${CMAKE_MATCH_3}) 70*c33452fbSAndroid Build Coastguard Worker set(PF_VERSION_TWEAK ${CMAKE_MATCH_4}) 71*c33452fbSAndroid Build Coastguard Worker set(PF_VERSION_SHA1 ${CMAKE_MATCH_6}) # Skip the 5th: it is a superset of the 6th 72*c33452fbSAndroid Build Coastguard Worker set(PF_VERSION_DIRTY ${CMAKE_MATCH_8}) # Skip the 7th: it is a superset of the 8th 73*c33452fbSAndroid Build Coastguard Workerendif() 74*c33452fbSAndroid Build Coastguard Worker 75*c33452fbSAndroid Build Coastguard Worker# If we are precisely on a tag, make a nicer version string (unless otherwise 76*c33452fbSAndroid Build Coastguard Worker# forced by the user - see above) 77*c33452fbSAndroid Build Coastguard Workerif((NOT DEFINED NICE_PF_VERSION)) 78*c33452fbSAndroid Build Coastguard Worker if((PF_VERSION_TWEAK EQUAL 0) AND (NOT PF_VERSION_DIRTY)) 79*c33452fbSAndroid Build Coastguard Worker set(NICE_PF_VERSION "v${PF_VERSION_MAJOR}.${PF_VERSION_MINOR}.${PF_VERSION_PATCH}") 80*c33452fbSAndroid Build Coastguard Worker else() 81*c33452fbSAndroid Build Coastguard Worker # Fallback 82*c33452fbSAndroid Build Coastguard Worker set(NICE_PF_VERSION "${PF_VERSION}") 83*c33452fbSAndroid Build Coastguard Worker endif() 84*c33452fbSAndroid Build Coastguard Workerendif() 85