source: icGREP/icgrep-devel/icgrep/cmake/VersionFromVCS.cmake @ 6036

Last change on this file since 6036 was 5373, checked in by cameron, 2 years ago

Parabix version info, unique names for IDISA builders

File size: 3.0 KB
Line 
1# Adds version control information to the variable VERS. For
2# determining the Version Control System used (if any) it inspects the
3# existence of certain subdirectories under CMAKE_CURRENT_SOURCE_DIR.
4
5function(add_version_info_from_vcs VERS)
6  string(REPLACE "svn" "" result "${${VERS}}")
7  if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn" OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../.svn" )
8    set(result "${result}svn")
9    # FindSubversion does not work with symlinks. See PR 8437
10    if( NOT IS_SYMLINK "${CMAKE_CURRENT_SOURCE_DIR}" )
11      find_package(Subversion)
12    endif()
13    if( Subversion_FOUND )
14      subversion_wc_info( ${CMAKE_CURRENT_SOURCE_DIR} Project )
15      if( Project_WC_REVISION )
16        set(SVN_REVISION ${Project_WC_REVISION} PARENT_SCOPE)
17        set(result "${result}_r${Project_WC_REVISION}")
18      endif()
19    endif()
20  elseif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git )
21    set(result "${result}git")
22    # Try to get a ref-id
23    if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git/svn OR EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git/svn )
24      find_program(git_executable NAMES git git.exe git.cmd)
25      if( git_executable )
26        set(is_git_svn_rev_exact false)
27        execute_process(COMMAND ${git_executable} svn log --limit=1 --oneline
28          WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
29          TIMEOUT 5
30          RESULT_VARIABLE git_result
31          OUTPUT_VARIABLE git_output)
32        if( git_result EQUAL 0 )
33          string(REGEX MATCH r[0-9]+ git_svn_rev ${git_output})
34          string(LENGTH "${git_svn_rev}" rev_length)
35          math(EXPR rev_length "${rev_length}-1")
36          string(SUBSTRING "${git_svn_rev}" 1 ${rev_length} git_svn_rev_number)
37          set(SVN_REVISION ${git_svn_rev_number} PARENT_SCOPE)
38          set(git_svn_rev "_svn_${git_svn_rev}")
39
40          # Determine if the HEAD points directly at a subversion revision.
41          execute_process(COMMAND ${git_executable} svn find-rev HEAD
42            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
43            TIMEOUT 5
44            RESULT_VARIABLE git_result
45            OUTPUT_VARIABLE git_output)
46          if( git_result EQUAL 0 )
47            string(STRIP "${git_output}" git_head_svn_rev_number)
48            if( git_head_svn_rev_number EQUAL git_svn_rev_number )
49              set(is_git_svn_rev_exact true)
50            endif()
51          endif()
52        else()
53          set(git_svn_rev "")
54        endif()
55        execute_process(COMMAND
56          ${git_executable} rev-parse --short HEAD
57          WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
58          TIMEOUT 5
59          RESULT_VARIABLE git_result
60          OUTPUT_VARIABLE git_output)
61        if( git_result EQUAL 0 AND NOT is_git_svn_rev_exact )
62          string(STRIP "${git_output}" git_ref_id)
63          set(GIT_COMMIT ${git_ref_id} PARENT_SCOPE)
64          set(result "${result}${git_svn_rev}_${git_ref_id}")
65        else()
66          set(result "${result}${git_svn_rev}")
67        endif()
68      endif()
69    endif()
70  endif()
71  set(${VERS} ${result} PARENT_SCOPE)
72endfunction(add_version_info_from_vcs)
Note: See TracBrowser for help on using the repository browser.