2010-08-03 19:28:09 +02:00
|
|
|
# Adds version control information to the variable VERS. For
|
|
|
|
# determining the Version Control System used (if any) it inspects the
|
2016-04-16 09:33:14 +02:00
|
|
|
# existence of certain subdirectories under SOURCE_DIR (if provided as an
|
|
|
|
# extra argument, otherwise uses CMAKE_CURRENT_SOURCE_DIR).
|
2010-08-03 19:28:09 +02:00
|
|
|
|
2019-10-31 21:39:48 +01:00
|
|
|
function(get_source_info path revision repository)
|
2020-06-22 12:34:49 +02:00
|
|
|
find_package(Git QUIET)
|
2019-02-06 04:51:00 +01:00
|
|
|
if(GIT_FOUND)
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --git-dir
|
|
|
|
WORKING_DIRECTORY ${path}
|
|
|
|
RESULT_VARIABLE git_result
|
|
|
|
OUTPUT_VARIABLE git_output
|
|
|
|
ERROR_QUIET)
|
|
|
|
if(git_result EQUAL 0)
|
|
|
|
string(STRIP "${git_output}" git_output)
|
|
|
|
get_filename_component(git_dir ${git_output} ABSOLUTE BASE_DIR ${path})
|
2019-10-31 21:39:48 +01:00
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
|
|
|
|
WORKING_DIRECTORY ${path}
|
|
|
|
RESULT_VARIABLE git_result
|
|
|
|
OUTPUT_VARIABLE git_output)
|
|
|
|
if(git_result EQUAL 0)
|
|
|
|
string(STRIP "${git_output}" git_output)
|
|
|
|
set(${revision} ${git_output} PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref --symbolic-full-name @{upstream}
|
|
|
|
WORKING_DIRECTORY ${path}
|
|
|
|
RESULT_VARIABLE git_result
|
|
|
|
OUTPUT_VARIABLE git_output
|
|
|
|
ERROR_QUIET)
|
|
|
|
if(git_result EQUAL 0)
|
|
|
|
string(REPLACE "/" ";" branch ${git_output})
|
|
|
|
list(GET branch 0 remote)
|
|
|
|
else()
|
|
|
|
set(remote "origin")
|
|
|
|
endif()
|
|
|
|
execute_process(COMMAND ${GIT_EXECUTABLE} remote get-url ${remote}
|
|
|
|
WORKING_DIRECTORY ${path}
|
|
|
|
RESULT_VARIABLE git_result
|
|
|
|
OUTPUT_VARIABLE git_output
|
|
|
|
ERROR_QUIET)
|
|
|
|
if(git_result EQUAL 0)
|
|
|
|
string(STRIP "${git_output}" git_output)
|
|
|
|
set(${repository} ${git_output} PARENT_SCOPE)
|
2019-02-06 04:51:00 +01:00
|
|
|
else()
|
2019-10-31 21:39:48 +01:00
|
|
|
set(${repository} ${path} PARENT_SCOPE)
|
2017-03-02 23:05:13 +01:00
|
|
|
endif()
|
2010-08-05 04:22:51 +02:00
|
|
|
endif()
|
2020-06-22 12:34:49 +02:00
|
|
|
else()
|
|
|
|
message(WARNING "Git not found. Version cannot be determined.")
|
2010-08-03 19:28:09 +02:00
|
|
|
endif()
|
2019-02-06 04:51:00 +01:00
|
|
|
endfunction()
|