@@ -13,26 +13,31 @@ project(amd_comgr VERSION "${ver_major}.${ver_minor}.0" LANGUAGES C CXX)
13
13
set (amd_comgr_NAME "${PROJECT_NAME} " )
14
14
15
15
# Get git branch and commit hash to add to log for easier debugging.
16
- # Modeled after https://github.com/pmirshad/cmake-with-git-metadata.
17
- # Current working branch
18
- if (EXISTS "${CMAKE_SOURCE_DIR} /../../.git" )
19
- execute_process (
20
- COMMAND git rev-parse --abbrev-ref HEAD
21
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
22
- OUTPUT_VARIABLE AMD_COMGR_GIT_BRANCH
23
- OUTPUT_STRIP_TRAILING_WHITESPACE
24
- )
25
- # Shortened commit hash
26
16
execute_process (
27
17
COMMAND git log -1 --format=%h
28
- WORKING_DIRECTORY ${CMAKE_SOURCE_DIR }
18
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR }
29
19
OUTPUT_VARIABLE AMD_COMGR_GIT_COMMIT
30
20
OUTPUT_STRIP_TRAILING_WHITESPACE
21
+ RESULT_VARIABLE GIT_REV_PARSE_EXITCODE
31
22
)
32
- else (EXISTS "${CMAKE_SOURCE_DIR} /../../.git" )
23
+
24
+ if (${GIT_REV_PARSE_EXITCODE} EQUAL 0)
25
+ execute_process (
26
+ COMMAND git log -1 --format=%h
27
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
28
+ OUTPUT_VARIABLE AMD_COMGR_GIT_COMMIT
29
+ OUTPUT_STRIP_TRAILING_WHITESPACE
30
+ )
31
+ execute_process (
32
+ COMMAND git name -rev --name -only HEAD
33
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
34
+ OUTPUT_VARIABLE AMD_COMGR_GIT_BRANCH
35
+ OUTPUT_STRIP_TRAILING_WHITESPACE
36
+ )
37
+ else ()
33
38
set (AMD_COMGR_GIT_BRANCH "not-available" )
34
39
set (AMD_COMGR_GIT_COMMIT "not-available" )
35
- endif (EXISTS " ${CMAKE_SOURCE_DIR} /../../.git" )
40
+ endif ()
36
41
37
42
include (GNUInstallDirs)
38
43
include (CMakePackageConfigHelpers)
0 commit comments