Skip to content

Commit

Permalink
Check and write version.h only if we have a version
Browse files Browse the repository at this point in the history
  • Loading branch information
alef committed Feb 6, 2024
1 parent 1f2b9f5 commit 253168d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ execute_process(COMMAND ${CMAKE_COMMAND}
-DGIT_BINARY=${GIT_BINARY}
-P ${CMAKE_SOURCE_DIR}/src/version.cmake
ERROR_VARIABLE GIT_VERSION
ERROR_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

Expand Down
17 changes: 9 additions & 8 deletions src/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ if("${GIT_VERSION}" MATCHES "GIT-NOTFOUND")
return()
endif()

string(REPLACE "-NOTFOUND" "" GIT_VERSION ${GIT_VERSION})

file(READ ${CMAKE_SOURCE_DIR}/src/version.h VERSION_H)
string(REGEX MATCH "#define VERSION \"(.+)\"" VERSION_H "${VERSION_H}")

if(NOT GIT_VERSION STREQUAL VERSION_H)
file(WRITE ${CMAKE_SOURCE_DIR}/src/version.h
"// NOLINT(cata-header-guard)\n\#define VERSION \"${GIT_VERSION}\"\n")
if(GIT_VERSION)
string(REPLACE "-NOTFOUND" "" GIT_VERSION ${GIT_VERSION})
file(READ ${CMAKE_SOURCE_DIR}/src/version.h VERSION_H)
string(REGEX MATCH "#define VERSION \"(.+)\"" VERSION_H "${VERSION_H}")

if(NOT GIT_VERSION STREQUAL VERSION_H)
file(WRITE ${CMAKE_SOURCE_DIR}/src/version.h
"// NOLINT(cata-header-guard)\n\#define VERSION \"${GIT_VERSION}\"\n")
endif()
endif()

# get_git_head_revision() does not work with worktrees in Windows
Expand Down

0 comments on commit 253168d

Please sign in to comment.