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.

87 lines
3.4 KiB

  1. #
  2. # This program source code file is part of KICAD, a free EDA CAD application.
  3. #
  4. # Copyright (C) 2015 Wayne Stambaugh <stambaughw@verizon.net>
  5. # Copyright (C) 2015 KiCad Developers, see AUTHORS.txt for contributors.
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, you may find one here:
  19. # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. # or you may search the http://www.gnu.org website for the version 2 license,
  21. # or you may write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. #
  24. # Automagically create version header file if the version string was not defined during
  25. # the build configuration. If CreateBzrVersionHeader or CreateGitVersionHeader cannot
  26. # determine the current repo version, a version.h file is still created with
  27. # KICAD_BUILD_VERSION set to "no-vcs-found".
  28. if( NOT KICAD_BUILD_VERSION )
  29. set( _wvh_version_str "no-vcs-found" )
  30. # Detect the appropiate VCS and set the version string.
  31. if( EXISTS "${SRC_PATH}/.bzr" )
  32. message( STATUS "Using Bazaar to determine build version string." )
  33. include( ${CMAKE_MODULE_PATH}/CreateBzrVersionHeader.cmake )
  34. create_bzr_version_header( ${SRC_PATH} )
  35. set( _wvh_version_str ${KICAD_BUILD_VERSION} )
  36. elseif( EXISTS "${SRC_PATH}/.git" )
  37. message( STATUS "Using Git to determine build version string." )
  38. include( ${CMAKE_MODULE_PATH}/CreateGitVersionHeader.cmake )
  39. create_git_version_header( ${SRC_PATH} )
  40. set( _wvh_version_str ${KICAD_BUILD_VERSION} )
  41. endif()
  42. else()
  43. set( _wvh_version_str ${KICAD_BUILD_VERSION} )
  44. endif()
  45. set( _wvh_write_version_file ON )
  46. # Compare the version argument against the version in the existing header file for a mismatch.
  47. if( EXISTS ${OUTPUT_FILE} )
  48. file( STRINGS ${CMAKE_BINARY_DIR}/version.h _current_version_str
  49. REGEX "^#define[\t ]+KICAD_BUILD_VERSION[\t ]+.*" )
  50. string( REGEX REPLACE "^#define KICAD_BUILD_VERSION \"([()a-zA-Z0-9 -.]+)\".*"
  51. "\\1" _wvh_last_version "${_current_version_str}" )
  52. # No change, do not write version.h
  53. if( _wvh_version_str STREQUAL _wvh_last_version )
  54. message( STATUS "Not updating ${OUTPUT_FILE}" )
  55. set( _wvh_write_version_file OFF )
  56. endif()
  57. endif()
  58. if( _wvh_write_version_file )
  59. message( STATUS "Writing ${OUTPUT_FILE} file with version: ${_wvh_version_str}" )
  60. file( WRITE ${OUTPUT_FILE}
  61. "/* Do not modify this file, it was automatically generated by CMake. */
  62. /*
  63. * Define the KiCad build version string.
  64. */
  65. #ifndef __KICAD_VERSION_H__
  66. #define __KICAD_VERSION_H__
  67. #define KICAD_BUILD_VERSION \"${_wvh_version_str}\"
  68. #endif /* __KICAD_VERSION_H__ */
  69. "
  70. )
  71. endif()
  72. # There should always be a valid version.h file. Otherwise, the build will fail.
  73. if( NOT EXISTS ${CMAKE_BINARY_DIR}/version.h )
  74. message( FATAL_ERROR "Configuration failed to write file ${OUTPUT_FILE}." )
  75. endif()