[CMake] Fwd: Portable revision lookup?

John Drescher drescherjm at gmail.com
Thu Feb 2 16:36:30 EST 2012


---------- Forwarded message ----------
From: John Drescher <drescherjm at gmail.com>
Date: Thu, Feb 2, 2012 at 4:36 PM
Subject: Re: [CMake] Portable revision lookup?
To: Oliver kfsone Smith <osmith at playnet.com>


On Thu, Feb 2, 2012 at 4:10 PM, Oliver kfsone Smith <osmith at playnet.com> wrote:
> Right now I wrap my Linux-based build process with a script that features
> the line
>
> REVISION=`svn info ${SRC_PATH} | awk '/^Revision/ { print $2 }'`
>
> Which is neither OS or VCS portable.
>
> I'm trying to put together a CPack configuration to make the builds, and I'd
> like to name the resulting installer for the revision it was built from.
>
> Is there any kind of built-in mechanism I can use for this, or would I be
> best just using IFs and executing os-specific commands? (I'm not quite sure
> how I'm going to pluck the info out under Windows)
>
> I'm also wondering if there is a way to query other repository attributes -
> specifically the URL - I'd like to build installers named
>
>     <product>.<branch>.<revision>.<suffix>
>
> e.g.
>
>     my-client.baseline.57721.deb
> or
>     my-server.branches.1.35.57804.tbz2
>
> Any pointers?
>

Cmake has support for pulling the svn and I believe git revs using
cmake modules. Here is what I do for svn

#-----------------------------------------------------------------------------
# If subversion is found append the svn rev to the patch version.
#
FIND_PACKAGE(Subversion)
IF(Subversion_FOUND)
       OPTION(SVN_APPEND_REV "Append subversion rev to application version" ON)
       IF(SVN_APPEND_REV)
               Subversion_WC_INFO(${PROJECT_SOURCE_DIR} Project)
               MESSAGE("Current revision is ${Project_WC_REVISION}")

               OPTION(SVN_GET_LOG "Get the SVN LOG" OFF)
               if(SVN_GET_LOG)
                       Subversion_WC_LOG(${PROJECT_SOURCE_DIR} Project)
                       MESSAGE("Last changed log is
${Project_LAST_CHANGED_LOG}")
               endif(SVN_GET_LOG)

               set (${PROJECT_NAME}_VERSION_PATCH
${${PROJECT_NAME}_VERSION_PATCH}.${Project_WC_REVISION})
       ENDIF(SVN_APPEND_REV)

ENDIF(Subversion_FOUND)

John


-- 
John M. Drescher


More information about the CMake mailing list