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.

50 lines
2.1 KiB

  1. # This program source code file is part of KICAD, a free EDA CAD application.
  2. #
  3. # Copyright (C) 2020 Kicad Developers, see AUTHORS.txt for contributors.
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, you may find one here:
  17. # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  18. # or you may search the http://www.gnu.org website for the version 2 license,
  19. # or you may write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  21. #
  22. # This file takes the following variables as arguments:
  23. # * LEMON_EXE - The absolute path to the lemon executable
  24. # * LEMON_TEMPLATE - The absolute path to the lemon template file
  25. # * GRAMMAR_FILE - The file of the grammar to use
  26. # * GRAMMAR_DIR - An absolute path to where the grammar should be generated
  27. # Get the name without extension
  28. get_filename_component( GRAMMAR_BASE ${GRAMMAR_FILE} NAME_WE )
  29. # Only regenerate the lemon code if the grammar is newer than the current code
  30. if( ${GRAMMAR_FILE} IS_NEWER_THAN ${GRAMMAR_DIR}/${GRAMMAR_BASE}.c )
  31. execute_process(
  32. COMMAND ${LEMON_EXE} -T${LEMON_TEMPLATE} -d${GRAMMAR_DIR} -q ${GRAMMAR_FILE}
  33. WORKING_DIRECTORY ${GRAMMAR_DIR}
  34. OUTPUT_VARIABLE _lemon_output
  35. ERROR_VARIABLE _lemon_error
  36. RESULT_VARIABLE _lemon_result
  37. OUTPUT_STRIP_TRAILING_WHITESPACE
  38. )
  39. if( NOT ${_lemon_result} EQUAL 0)
  40. message( FATAL_ERROR "Lemon generator for ${GRAMMAR_FILE} has failed\n"
  41. "Error: ${_lemon_error}" )
  42. endif()
  43. endif()