0

I have this code in my CMake file to get SVN version info and push it into a define that my project can use:

   find_package(Subversion)
   if(SUBVERSION_FOUND)
     Subversion_WC_INFO(${CMAKE_CURRENT_SOURCE_DIR} MyProj)
     target_compile_definitions(MyProj PUBLIC "-DSVN_RC=${MyProj_WC_REVISION}" )
   endif(SUBVERSION_FOUND)

This uses a macro found in the default CMake distribution. This is effectively what the macro does:

  macro(Subversion_WC_INFO dir prefix)

    execute_process(COMMAND ${Subversion_SVN_EXECUTABLE} info ${dir}
      OUTPUT_VARIABLE ${prefix}_WC_INFO
      ERROR_VARIABLE Subversion_svn_info_error
      RESULT_VARIABLE Subversion_svn_info_result
      OUTPUT_STRIP_TRAILING_WHITESPACE)

    if(NOT ${Subversion_svn_info_result} EQUAL 0)
      message(SEND_ERROR "Command \"${Subversion_SVN_EXECUTABLE} info ${dir}\" failed with output:\n${Subversion_svn_info_error}")
    endif()

  endmacro()

My problem is that this code fails. The output of my configuration looks like this:

CMake Error at C:/msys64/mingw32/share/cmake-3.8/Modules/FindSubversion.cmake:99 (message):
  Command "C:/msys64/usr/bin/svn.exe info
  C:/msys64/home/stew/proj"
  failed with output:

  svn: warning: W155010: The node '/home/stew/proj/build/C:/msys64/home/stew/proj/' was not found.

  svn: E200009: Could not display info for all targets because some targets don't exist

I think the problem is my msys environment which is kind of a fake-root environment. svn info /home/stew/proj works while svn info c:/msys64/home/stew/proj doesn't work. ${CMAKE_CURRENT_SOURCE_DIR} gives me the windows path which is a problem for svn. Is there a way to translate the `${CMAKE_CURRENT_SOURCE_DIR} output in Windows format into the fakeroot format? If not, is there a way to force SVN to accept the other path?

1 Answer 1

1

I had this same problem. My solution was:

execute_process(COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR} svnversion -n OUTPUT_VARIABLE SVN_COMMIT)

The ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_SOURCE_DIR} bit runs what follows as a command in ${CMAKE_CURRENT_SOURCE_DIR}.

Sign up to request clarification or add additional context in comments.

1 Comment

Make sure your path is set up correctly. find_package(Subversion) failed for me (running through QtCreator) so I had to set the path manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.