Skip to content

Commit

Permalink
Merge pull request #469 from neojaw/git-version
Browse files Browse the repository at this point in the history
Fixed version check in wrong directory
  • Loading branch information
BigBoot authored Oct 30, 2024
2 parents 6671dc7 + 1854135 commit 317d5e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions cmake/modules/GetVersionFromGitTag.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@
# Author: Nuno Fachada

# Check if git is found...
if (GIT_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/.git)
if (GIT_EXECUTABLE AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)

# Get last tag from git
execute_process(COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 --tags
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE ${PROJECT_NAME}_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE)

#How many commits since last tag
execute_process(COMMAND ${GIT_EXECUTABLE} rev-list ${${PROJECT_NAME}_VERSION_STRING}..HEAD --count
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE ${PROJECT_NAME}_VERSION_AHEAD
OUTPUT_STRIP_TRAILING_WHITESPACE)

# Get current commit SHA from git
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE ${PROJECT_NAME}_VERSION_GIT_SHA
OUTPUT_STRIP_TRAILING_WHITESPACE)

Expand Down Expand Up @@ -83,7 +83,7 @@ if (GIT_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/.git)

# Check wether working tree is clean
execute_process(COMMAND ${GIT_EXECUTABLE} status --porcelain
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE ${PROJECT_NAME}_WORKING_DIR_CLEAN)

if(NOT ${PROJECT_NAME}_WORKING_DIR_CLEAN STREQUAL "")
Expand All @@ -96,7 +96,7 @@ if (GIT_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/.git)

# Save version to file (which will be used when Git is not available
# or VERSION_UPDATE_FROM_GIT is disabled)
file(WRITE ${CMAKE_BINARY_DIR}/VERSION ${${PROJECT_NAME}_VERSION_STRING_FULL}
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/VERSION ${${PROJECT_NAME}_VERSION_STRING_FULL}
"*" ${${PROJECT_NAME}_VERSION_STRING}
"*" ${${PROJECT_NAME}_VERSION_MAJOR}
"*" ${${PROJECT_NAME}_VERSION_MINOR}
Expand All @@ -108,7 +108,7 @@ if (GIT_EXECUTABLE AND EXISTS ${CMAKE_SOURCE_DIR}/.git)
else()

# Git not available, get version from file
file(STRINGS ${CMAKE_SOURCE_DIR}/VERSION ${PROJECT_NAME}_VERSION_LIST)
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/VERSION ${PROJECT_NAME}_VERSION_LIST)
string(REPLACE "*" ";" ${PROJECT_NAME}_VERSION_LIST ${${PROJECT_NAME}_VERSION_LIST})

# Get Length of the version elements
Expand Down
8 changes: 4 additions & 4 deletions cmake/modules/MacroOutOfSourceBuild.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Ensures that we do an out of source build

MACRO(MACRO_ENSURE_OUT_OF_SOURCE_BUILD MSG)
STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}"
"${CMAKE_BINARY_DIR}" insource)
GET_FILENAME_COMPONENT(PARENTDIR ${CMAKE_SOURCE_DIR} PATH)
STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}"
STRING(COMPARE EQUAL "${PROJECT_SOURCE_DIR}"
"${PROJECT_BINARY_DIR}" insource)
GET_FILENAME_COMPONENT(PARENTDIR ${PROJECT_SOURCE_DIR} PATH)
STRING(COMPARE EQUAL "${PROJECT_SOURCE_DIR}"
"${PARENTDIR}" insourcesubdir)
IF(insource OR insourcesubdir)
MESSAGE(FATAL_ERROR "${MSG}")
Expand Down

0 comments on commit 317d5e3

Please sign in to comment.