From fd4540d5736b0f498dd84838ad98ba100c499513 Mon Sep 17 00:00:00 2001 From: Nicolas Hake Date: Sun, 5 Feb 2012 02:08:45 +0100 Subject: [PATCH] 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. --- Version.txt | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Version.txt b/Version.txt index f43838141..e1bce26bd 100644 --- a/Version.txt +++ b/Version.txt @@ -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