cmake: Read Mercurial revision from .hg_archival.txt if available

This way cmake will generate a correct C4Version.h from source tarballs
generated by hg archive.
scancodes-fix
Nicolas Hake 2012-02-05 02:08:45 +01:00
parent 32028fd903
commit fd4540d573
1 changed files with 14 additions and 6 deletions

View File

@ -35,12 +35,20 @@ SET(C4VERSIONEXTRA " Alpha")
############################################################################
# Get revision from Mercurial
############################################################################
# Note: This will not work for source distributions!
execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND "hg" "id" "--id"
OUTPUT_VARIABLE C4REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.hg_archival.txt")
# Archives generated by hg archive
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/.hg_archival.txt" C4REVISION
LIMIT_COUNT 1
REGEX "node: [0-9a-f]+"
)
string(SUBSTRING "${C4REVISION}" 6 12 C4REVISION)
else()
# Working copies
execute_process(WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND "hg" "id" "--id"
OUTPUT_VARIABLE C4REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
############################################################################
# Build version strings