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.

80 lines
3.0 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@gmail.com>
  5. # Copyright (C) 2015-2018 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
  25. # not defined during the build configuration. If CreateGitVersionHeader
  26. # cannot determine the current repo version, a version.h file is still
  27. # created with KICAD_VERSION set in KiCadVersion.cmake.
  28. include( ${CMAKE_MODULE_PATH}/KiCadVersion.cmake )
  29. # Always use git if it's available to determine the version string.
  30. message( STATUS "Using Git to determine build version string." )
  31. include( ${CMAKE_MODULE_PATH}/CreateGitVersionHeader.cmake )
  32. create_git_version_header( ${SRC_PATH} )
  33. # $KICAD_VERSION will always be set to something. Even if it is the default
  34. # value set in KiCadVersion.cmake
  35. set( KICAD_VERSION_FULL "${KICAD_VERSION}" )
  36. # Optional user version information defined at configuration.
  37. if( KICAD_VERSION_EXTRA )
  38. set( KICAD_VERSION_FULL "${KICAD_VERSION_FULL}-${KICAD_VERSION_EXTRA}" )
  39. endif()
  40. set( _wvh_new_version_text
  41. "/* Do not modify this file, it was automatically generated by CMake. */
  42. /*
  43. * Define the KiCad build version string.
  44. */
  45. #ifndef __KICAD_VERSION_H__
  46. #define __KICAD_VERSION_H__
  47. #define KICAD_VERSION_FULL \"${KICAD_VERSION_FULL}\"
  48. #endif /* __KICAD_VERSION_H__ */
  49. " )
  50. set( _wvh_write_version_file ON )
  51. # Only write the header if it has changed, to avoid rebuilds
  52. if( EXISTS ${OUTPUT_FILE} )
  53. file( READ ${OUTPUT_FILE} _wvh_old_version_text )
  54. if( _wvh_old_version_text STREQUAL _wvh_new_version_text )
  55. message( STATUS "Not updating ${OUTPUT_FILE}" )
  56. set( _wvh_write_version_file OFF )
  57. endif()
  58. endif()
  59. if( _wvh_write_version_file )
  60. message( STATUS "Writing ${OUTPUT_FILE} file with version: ${KICAD_VERSION_FULL}" )
  61. file( WRITE ${OUTPUT_FILE} ${_wvh_new_version_text} )
  62. endif()
  63. # There should always be a valid version.h file. Otherwise, the build will fail.
  64. if( NOT EXISTS ${OUTPUT_FILE} )
  65. message( FATAL_ERROR "Configuration failed to write file ${OUTPUT_FILE}." )
  66. endif()