PageRenderTime 136ms CodeModel.GetById 81ms app.highlight 7ms RepoModel.GetById 43ms app.codeStats 1ms

/CMakeModules/CMakeVersionSource.cmake

http://github.com/tomahawk-player/tomahawk
CMake | 45 lines | 44 code | 0 blank | 1 comment | 5 complexity | efda017199a5769d2c2a6e0303573e5a MD5 | raw file
 1# Try to identify the current development source version.
 2set(CMAKE_VERSION_SOURCE "")
 3if(EXISTS ${CMAKE_SOURCE_DIR}/.git/HEAD)
 4  find_program(GIT_EXECUTABLE NAMES git git.cmd)
 5  mark_as_advanced(GIT_EXECUTABLE)
 6  if(GIT_EXECUTABLE)
 7    execute_process(
 8      COMMAND ${GIT_EXECUTABLE} rev-parse --verify -q --short=7 HEAD
 9      OUTPUT_VARIABLE head
10      OUTPUT_STRIP_TRAILING_WHITESPACE
11      WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
12      )
13    if(head)
14      set(branch "")
15      execute_process(
16        COMMAND ${GIT_EXECUTABLE} name-rev HEAD
17        OUTPUT_VARIABLE branch
18        OUTPUT_STRIP_TRAILING_WHITESPACE
19        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
20        )
21      string(REGEX REPLACE "HEAD " "" branch "${branch}")
22      set(CMAKE_VERSION_SOURCE "git-${branch}-${head}")
23      execute_process(
24        COMMAND ${GIT_EXECUTABLE} update-index -q --refresh
25        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
26        )
27      execute_process(
28        COMMAND ${GIT_EXECUTABLE} diff-index --name-only HEAD --
29        OUTPUT_VARIABLE dirty
30        OUTPUT_STRIP_TRAILING_WHITESPACE
31        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
32        )
33      if(dirty)
34        set(CMAKE_VERSION_SOURCE "${CMAKE_VERSION_SOURCE}-dirty")
35      endif()
36    endif()
37  endif()
38elseif(EXISTS ${CMAKE_SOURCE_DIR}/CVS/Repository)
39  file(READ ${CMAKE_SOURCE_DIR}/CVS/Repository repo)
40  set(branch "")
41  if("${repo}" MATCHES "\\.git/")
42    string(REGEX REPLACE ".*\\.git/([^\r\n]*).*" "-\\1" branch "${repo}")
43  endif()
44  set(CMAKE_VERSION_SOURCE "cvs${branch}")
45endif()