Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1099909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:48:17+00:00 2026-05-17T00:48:17+00:00

With CMake I can get the Subversion revision using Subversion_WC_INFO . However, this only

  • 0

With CMake I can get the Subversion revision using Subversion_WC_INFO. However, this only happens at configure time — every subsequent make will use this cached revision.

I’d like to get the svn revision at build time (ie, every time Make is run). How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:48:18+00:00Added an answer on May 17, 2026 at 12:48 am

    This is more of a pain to do than it needs to be. You can run a program at build time to extract the version information from subversion. CMake itself can be used as this program using its scripting language. You can run any CMake script using the -P command line flag. The piece of code to do this would be (To be placed in file getsvn.cmake):

    # the FindSubversion.cmake module is part of the standard distribution
    include(FindSubversion)
    # extract working copy information for SOURCE_DIR into MY_XXX variables
    Subversion_WC_INFO(${SOURCE_DIR} MY)
    # write a file with the SVNVERSION define
    file(WRITE svnversion.h.txt "#define SVNVERSION ${MY_WC_REVISION}\n")
    # copy the file to the final header only if the version changes
    # reduces needless rebuilds
    execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
                            svnversion.h.txt svnversion.h)
    

    This extracts the subversion revision information and writes it to a header file. This header file is only updated when needed to avoid recompiling all the time. In your program, you would include that header file to get at the SVNVERSION define.

    The CMakeLists.txt file that you would need to run the script would be something like this:

    # boilerplate
    cmake_minimum_required(VERSION 2.8)
    project(testsvn)
    
    # the test executable
    add_executable(test main.c ${CMAKE_CURRENT_BINARY_DIR}/svnversion.h)
    
    # include the output directory, where the svnversion.h file is generated
    include_directories(${CMAKE_CURRENT_BINARY_DIR})
    
    # a custom target that is always built
    add_custom_target(svnheader ALL
        DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/svnheader.h)
    
    # creates svnheader.h using cmake script
    add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/svnheader.h
        COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
                             -P ${CMAKE_CURRENT_SOURCE_DIR}/getsvn.cmake)
    
    # svnversion.h is a generated file
    set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/svnversion.h
        PROPERTIES GENERATED TRUE
        HEADER_FILE_ONLY TRUE)
    
    # explicitly say that the executable depends on the svnheader
    add_dependencies(test svnheader)
    

    You need to use add_custom_target and add_custom_command since there are no inputs to the svnheader.h file, it “appears from nowhere” to cmake. I already dealt with the issue of needless rebuilds in the getsvn.cmake file though, so rebuilding the “svnheader” target is basically a no-op if the subversion revision has not changed.

    Finally, an example main.c file:

    #include "svnversion.h"
    
    int main(int argc, const char *argv[])
    {
        printf("%d\n", SVNVERSION);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing some software using VTK. I have compiled VTK succesfully using CMake.
I am currently trying to get CMake to run on my Windows 7 (64-bit)
I've used CakePHP a few times before but this is the first time I'm
I am a Cake PHP novice. I want to edit the table Issue. This
This probably very easy when you know how, but I don't :) I'm trying
I'm struggling to implement ACL in CakePHP. After reading the documentation in the cake
I've got to write few words about C#, generally piece of cake? No! I've
hi I'm really frustrated, First I have no idea how to code the very
I am having a strange linking error. I followed instructions presented here to avoid
I'm aware that Cake HABTM associations are tricky at the best of times, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.