Skip to content

Commit fd881e4

Browse files
committed
fix cmake PACKAGE_VERSION to behave same way as in autotools
1 parent 394839c commit fd881e4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ file(STRINGS "VERSION" VERSION_PLAIN)
4545
string(REGEX REPLACE "^([^.]*)\\..*" "\\1" VERSION_MAJOR ${VERSION_PLAIN})
4646
string(REGEX REPLACE "^[^.]*\\.([^.]*)\\..*" "\\1" VERSION_MINOR ${VERSION_PLAIN})
4747
string(REGEX REPLACE "^[^.]*\\.[^.]*\\.([0-9]*).*" "\\1" VERSION_PATCH ${VERSION_PLAIN})
48+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
49+
execute_process(COMMAND git describe --abbrev=4
50+
OUTPUT_VARIABLE GIT_REV)
51+
string(REGEX REPLACE "\n$" "" PACKAGE_VERSION "${GIT_REV}")
52+
elseif()
53+
set(PACKAGE_VERSION ${VERSION_PLAIN})
54+
endif()
4855

4956
# Provide also same macro names as autoconf (see configure.ac).
5057
set(GENERIC_MAJOR_VERSION ${VERSION_MAJOR})

cmake/Configure.cmake

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,9 @@ set(types_list
119119
)
120120
check_types(types_list)
121121

122-
set(PACKAGE_VERSION "${VERSION_PLAIN}")
123122
file(APPEND ${AUTOCONFIG_SRC} "
124123
/* Version number */
125-
#cmakedefine PACKAGE_VERSION \"${VERSION_PLAIN}\"
124+
#cmakedefine PACKAGE_VERSION \"${PACKAGE_VERSION}\"
126125
")
127126

128127
test_big_endian(WORDS_BIGENDIAN)

0 commit comments

Comments
 (0)