Add custom targets to generate tarballs with stored versions
[oonf.git] / cmake / get_version.cmake
1 #!/bin/cmake
2 IF(EXISTS "${CMAKE_SOURCE_DIR}/version.cmake")
3   # preconfigured version data
4   FILE (COPY ${CMAKE_SOURCE_DIR}/version.cmake DESTINATION ${PROJECT_BINARY_DIR})
5 ELSEIF(NOT OONF_LIB_GIT AND NOT OONF_VERSION)
6   # look for git executable
7   SET(found_git false) 
8   find_program(found_git git)
9
10   SET(OONF_LIB_GIT "cannot read git repository")
11
12   IF(NOT ${found_git} STREQUAL "found_git-NOTFOUND")
13     # get git description WITH dirty flag
14     execute_process(COMMAND git describe --always --long --tags --dirty --match "v[0-9]*"
15       WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
16       OUTPUT_VARIABLE LIB_GIT OUTPUT_STRIP_TRAILING_WHITESPACE)
17
18     # get git description WITH dirty flag
19     execute_process(COMMAND git describe --abbrev=0 --match "v[0-9]*"
20       WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
21       OUTPUT_VARIABLE VERSION_TAG OUTPUT_STRIP_TRAILING_WHITESPACE)
22     
23     # strip "v" from tag
24     string(SUBSTRING ${VERSION_TAG} 1 -1 VERSION)
25   ENDIF()
26   
27   message ("Git commit: ${LIB_GIT}, Git version: ${VERSION}")
28   configure_file (${CMAKE_SOURCE_DIR}/cmake/version.cmake.in ${PROJECT_BINARY_DIR}/version.cmake)
29 ENDIF()