Skip to content

Commit 34b68d6

Browse files
authored
Change git command working directory to this project (#796)
If this project is used as subproject of another CMake project, then git commands will fail because git will be executed from wrong location.
1 parent f8143d5 commit 34b68d6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

cmake/modules/Versioning.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set(_VERSIONING_MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "Versionin
1414
# Get tag (expected: v1.2.3 or 1.2.3 or 1.2.3-12-gHASH)
1515
execute_process(
1616
COMMAND git describe --tags --dirty
17-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
17+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
1818
OUTPUT_VARIABLE GIT_DESC_RAW
1919
OUTPUT_STRIP_TRAILING_WHITESPACE
2020
)
@@ -35,12 +35,14 @@ set(PROJECT_VERSION_STRING
3535
# Commit hash (full + short)
3636
execute_process(
3737
COMMAND git rev-parse HEAD
38+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
3839
OUTPUT_VARIABLE PROJECT_GIT_HASH
3940
OUTPUT_STRIP_TRAILING_WHITESPACE
4041
)
4142

4243
execute_process(
4344
COMMAND git rev-parse --short HEAD
45+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
4446
OUTPUT_VARIABLE PROJECT_GIT_HASH_SHORT
4547
OUTPUT_STRIP_TRAILING_WHITESPACE
4648
)

0 commit comments

Comments
 (0)