Oscar Fuentes | 052c23c | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 1 | # Adds version control information to the variable VERS. For |
| 2 | # determining the Version Control System used (if any) it inspects the |
Mehdi Amini | 1d30fca | 2016-04-16 07:33:14 +0000 | [diff] [blame] | 3 | # existence of certain subdirectories under SOURCE_DIR (if provided as an |
| 4 | # extra argument, otherwise uses CMAKE_CURRENT_SOURCE_DIR). |
Oscar Fuentes | 052c23c | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 5 | |
Tom Stellard | caad217 | 2019-10-31 13:39:48 -0700 | [diff] [blame] | 6 | function(get_source_info path revision repository) |
Petr Hosek | 23fdd5a | 2019-02-06 03:51:00 +0000 | [diff] [blame] | 7 | find_package(Git) |
| 8 | if(GIT_FOUND) |
| 9 | execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir |
| 10 | WORKING_DIRECTORY ${path} |
| 11 | RESULT_VARIABLE git_result |
| 12 | OUTPUT_VARIABLE git_output |
| 13 | ERROR_QUIET) |
| 14 | if(git_result EQUAL 0) |
| 15 | string(STRIP "${git_output}" git_output) |
| 16 | get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path}) |
Tom Stellard | caad217 | 2019-10-31 13:39:48 -0700 | [diff] [blame] | 17 | execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD |
| 18 | WORKING_DIRECTORY ${path} |
| 19 | RESULT_VARIABLE git_result |
| 20 | OUTPUT_VARIABLE git_output) |
| 21 | if(git_result EQUAL 0) |
| 22 | string(STRIP "${git_output}" git_output) |
| 23 | set(${revision} ${git_output} PARENT_SCOPE) |
| 24 | endif() |
| 25 | execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref --symbolic-full-name @{upstream} |
| 26 | WORKING_DIRECTORY ${path} |
| 27 | RESULT_VARIABLE git_result |
| 28 | OUTPUT_VARIABLE git_output |
| 29 | ERROR_QUIET) |
| 30 | if(git_result EQUAL 0) |
| 31 | string(REPLACE "/" ";" branch ${git_output}) |
| 32 | list(GET branch 0 remote) |
Petr Hosek | 23fdd5a | 2019-02-06 03:51:00 +0000 | [diff] [blame] | 33 | else() |
Tom Stellard | caad217 | 2019-10-31 13:39:48 -0700 | [diff] [blame] | 34 | set(remote "origin") |
| 35 | endif() |
| 36 | execute_process(COMMAND ${GIT_EXECUTABLE} remote get-url ${remote} |
| 37 | WORKING_DIRECTORY ${path} |
| 38 | RESULT_VARIABLE git_result |
| 39 | OUTPUT_VARIABLE git_output |
| 40 | ERROR_QUIET) |
| 41 | if(git_result EQUAL 0) |
| 42 | string(STRIP "${git_output}" git_output) |
| 43 | set(${repository} ${git_output} PARENT_SCOPE) |
| 44 | else() |
| 45 | set(${repository} ${path} PARENT_SCOPE) |
Tom Stellard | 0e38d1f | 2017-03-02 22:05:13 +0000 | [diff] [blame] | 46 | endif() |
Oscar Fuentes | fc21c3a | 2010-08-05 02:22:51 +0000 | [diff] [blame] | 47 | endif() |
Oscar Fuentes | 052c23c | 2010-08-03 17:28:09 +0000 | [diff] [blame] | 48 | endif() |
Petr Hosek | 23fdd5a | 2019-02-06 03:51:00 +0000 | [diff] [blame] | 49 | endfunction() |