Initial commit - from Precise source
[freerdp-ubuntu-pcb-backport.git] / cmake / AutoVersioning.cmake
1 # - AutoVersioning
2 # Gather version from tarball or SCM
3 #
4 #  This module defines the following variables:
5 #     PRODUCT_VERSION    - Version of product
6 #
7
8 #=============================================================================
9 # Copyright 2011 O.S. Systems Software Ltda.
10 # Copyright 2011 Otavio Salvador <otavio@ossystems.com.br>
11 #
12 # Licensed under the Apache License, Version 2.0 (the "License");
13 # you may not use this file except in compliance with the License.
14 # You may obtain a copy of the License at
15 #
16 #     http://www.apache.org/licenses/LICENSE-2.0
17 #
18 # Unless required by applicable law or agreed to in writing, software
19 # distributed under the License is distributed on an "AS IS" BASIS,
20 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 # See the License for the specific language governing permissions and
22 # limitations under the License.
23 #=============================================================================
24
25 if(EXISTS "${CMAKE_SOURCE_DIR}/.version" )
26   file(READ ${CMAKE_SOURCE_DIR}/.version PRODUCT_VERSION)
27
28   string(STRIP ${PRODUCT_VERSION} PRODUCT_VERSION)
29 else()
30   execute_process(COMMAND git describe --match "v[0-9]*" --abbrev=4
31                   OUTPUT_VARIABLE PRODUCT_VERSION
32                   OUTPUT_STRIP_TRAILING_WHITESPACE
33                   ERROR_QUIET)
34
35   if(PRODUCT_VERSION)
36         string(REGEX REPLACE "^v(.*)" "\\1" PRODUCT_VERSION ${PRODUCT_VERSION})
37   else()
38     # GIT is the default version
39     set(PRODUCT_VERSION GIT)
40   endif()
41
42   # Check if has not commited changes
43   execute_process(COMMAND git update-index -q --refresh)
44   execute_process(COMMAND git diff-index --name-only HEAD --
45                   OUTPUT_VARIABLE CHANGED_SOURCE
46                   OUTPUT_STRIP_TRAILING_WHITESPACE
47                   ERROR_QUIET)
48
49   if(CHANGED_SOURCE)
50     set(PRODUCT_VERSION ${PRODUCT_VERSION}-dirty)
51   endif()
52 endif()
53
54 message(STATUS "${CMAKE_PROJECT_NAME} ${PRODUCT_VERSION}")