Barth
Barth

Reputation: 15725

CMake: how to get subversion revision but not to fail if we made an export?

I retrieve the subversion revision this way :

include(FindSubversion)
IF(Subversion_FOUND) 
    Subversion_WC_INFO(${CMAKE_SOURCE_DIR} MY)
    SET(SVN_REVISION "${MY_WC_REVISION}")
ELSE(Subversion_FOUND)
    SET(SVN_REVISION "-1")
ENDIF(Subversion_FOUND) 

The problem is that when someone does "svn export" he can't compile :

-- Found Subversion: /usr/bin/svn (found version "1.6.11") 
CMake Error at /opt/cmake-2.8.9-Linux-i386/share/cmake-2.8/Modules/FindSubversion.cmake:84 (MESSAGE):
  Command "/usr/bin/svn info /tmp/amore" failed with output:

  svn: '/tmp/amore' is not a working copy

Call Stack (most recent call first):
  CMakeLists.txt:32 (Subversion_WC_INFO)

How to solve this problem in an elegant way ?

Upvotes: 1

Views: 1536

Answers (1)

Barth
Barth

Reputation: 15725

I decided to simply test for the existence of the directory .svn in the sources :

# SVN revision 
include(FindSubversion)
IF(Subversion_FOUND) 
    if(EXISTS "${CMAKE_SOURCE_DIR}/.svn")
        Subversion_WC_INFO(${CMAKE_SOURCE_DIR} MY)
        SET(SVN_REVISION "${MY_WC_REVISION}")
    else ()
        SET(SVN_REVISION "-1")
    endif()
ELSE(Subversion_FOUND)
    SET(SVN_REVISION "-1")
ENDIF(Subversion_FOUND) 

Upvotes: 4

Related Questions