You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.9 KiB

  1. macro(create_svn_version_header)
  2. # Include Subversion support to automagically create version header file.
  3. find_package(Subversion)
  4. if(Subversion_FOUND)
  5. # Copied from the CMake module FindSubversion.cmake. The default
  6. # version prevents generating the output files when the "svn info"
  7. # command fails. Just fall back to using "build_version.h" for
  8. # the version strings.
  9. set(_Subversion_SAVED_LC_ALL "$ENV{LC_ALL}")
  10. set(ENV{LC_ALL} C)
  11. execute_process(
  12. COMMAND ${Subversion_SVN_EXECUTABLE} info ${PROJECT_SOURCE_DIR}
  13. OUTPUT_VARIABLE Kicad_WC_INFO
  14. ERROR_VARIABLE _svn_error
  15. RESULT_VARIABLE _svn_result
  16. OUTPUT_STRIP_TRAILING_WHITESPACE)
  17. if(NOT ${_svn_result} EQUAL 0)
  18. message(STATUS
  19. "Using <build_version.h> for version string.")
  20. else(NOT ${_svn_result} EQUAL 0)
  21. string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
  22. "\\2" Kicad_WC_URL "${Kicad_WC_INFO}")
  23. string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
  24. "\\2" Kicad_WC_REVISION "${Kicad_WC_INFO}")
  25. string(REGEX REPLACE "^(.*\n)?Last Changed Author: ([^\n]+).*"
  26. "\\2" Kicad_WC_LAST_CHANGED_AUTHOR "${Kicad_WC_INFO}")
  27. string(REGEX REPLACE "^(.*\n)?Last Changed Rev: ([^\n]+).*"
  28. "\\2" Kicad_WC_LAST_CHANGED_REV "${Kicad_WC_INFO}")
  29. string(REGEX REPLACE "^(.*\n)?Last Changed Date: ([^\n]+).*"
  30. "\\2" Kicad_WC_LAST_CHANGED_DATE "${Kicad_WC_INFO}")
  31. endif(NOT ${_svn_result} EQUAL 0)
  32. set(ENV{LC_ALL} ${_Subversion_SAVED_LC_ALL})
  33. endif(Subversion_FOUND)
  34. # Check to make sure 'svn info' command did not fail. Otherwise fallback
  35. # to version strings defined in "<kicad-src-dir>/include/build_version.h".
  36. if(Kicad_WC_LAST_CHANGED_DATE)
  37. string(REGEX REPLACE "^([0-9]+)\\-([0-9]+)\\-([0-9]+).*" "\\1\\2\\3"
  38. _kicad_svn_date ${Kicad_WC_LAST_CHANGED_DATE})
  39. set(KICAD_BUILD_VERSION
  40. "(${_kicad_svn_date} SVN-R${Kicad_WC_LAST_CHANGED_REV})")
  41. # Definition to conditionally use date and revision returned from the
  42. # Subversion info command instead of hand coded date and revision in
  43. # "include/build_version.h". If subversion is not found then the date
  44. # and version information must be manually edited.
  45. # Directive means SVN build, program version and build version will
  46. # reflect this.
  47. add_definitions(-DHAVE_SVN_VERSION)
  48. # Generate version.h.
  49. configure_file(${CMAKE_SOURCE_DIR}/CMakeModules/version.h.cmake
  50. ${CMAKE_BINARY_DIR}/version.h)
  51. message(STATUS "Kicad SVN build version: ${KICAD_BUILD_VERSION}")
  52. endif(Kicad_WC_LAST_CHANGED_DATE)
  53. endmacro(create_svn_version_header)