AbaKus – a complex calculator
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.

138 lines
5.0KB

  1. # /*
  2. # For more information, please see: http://software.sci.utah.edu
  3. # The MIT License
  4. # Copyright (c) 2005-2006
  5. # Scientific Computing and Imaging Institute, University of Utah
  6. # License for the specific language governing rights and limitations under
  7. # Permission is hereby granted, free of charge, to any person obtaining a
  8. # copy of this software and associated documentation files (the "Software"),
  9. # to deal in the Software without restriction, including without limitation
  10. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. # and/or sell copies of the Software, and to permit persons to whom the
  12. # Software is furnished to do so, subject to the following conditions:
  13. # The above copyright notice and this permission notice shall be included
  14. # in all copies or substantial portions of the Software.
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  16. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. # DEALINGS IN THE SOFTWARE.
  22. # */
  23. SET(PARSERS_FOUND FOOBAR)
  24. # These variables need to be specified in order to get CMake not to
  25. # barf on the IF(EXISTS ${BISON_EXECUTABLE} ..) expression even though
  26. # the code shouldn't get called. By setting them to BISON_EXECUTABLE
  27. SET(BISON_EXECUTABLE "BISON_EXECUTABLE-NOTFOUND" CACHE FILEPATH "bison executable")
  28. SET(FLEX_EXECUTABLE "FLEX_EXECUTABLE-NOTFOUND" CACHE FILEPATH "flex executable")
  29. # Mark these variables as advanced options
  30. MARK_AS_ADVANCED(FORCE BISON_EXECUTABLE)
  31. MARK_AS_ADVANCED(FORCE FLEX_EXECUTABLE)
  32. # You need at least version 2.4 for this to work.
  33. IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.4)
  34. MESSAGE("You need at least version 2.4 for generating flex and bison parsers. Go get it from http://www.cmake.org/HTML/Download.html")
  35. SET(PARSERS_FOUND 0)
  36. ELSE("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.4)
  37. FIND_PROGRAM(BISON_EXECUTABLE
  38. NAMES bison
  39. PATHS ${BISON_DIR} )
  40. FIND_PROGRAM(FLEX_EXECUTABLE
  41. NAMES flex
  42. PATHS ${FLEX_DIR} )
  43. IF(EXISTS ${BISON_EXECUTABLE} AND EXISTS ${FLEX_EXECUTABLE})
  44. SET(PARSERS_FOUND 1)
  45. ELSE(EXISTS ${BISON_EXECUTABLE} AND EXISTS ${FLEX_EXECUTABLE})
  46. SET(PARSERS_FOUND 0)
  47. # Print some error messages to the user
  48. IF (NOT EXISTS ${BISON_EXECUTABLE})
  49. MESSAGE("Couldn't find bison executable. Please check value in BISON_EXECUTABLE in advanced settings.")
  50. ENDIF (NOT EXISTS ${BISON_EXECUTABLE})
  51. IF (NOT EXISTS ${FLEX_EXECUTABLE})
  52. MESSAGE("Couldn't find flex executable. Please check value in FLEX_EXECUTABLE in advanced settings.")
  53. ENDIF (NOT EXISTS ${FLEX_EXECUTABLE})
  54. ENDIF(EXISTS ${BISON_EXECUTABLE} AND EXISTS ${FLEX_EXECUTABLE})
  55. ENDIF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.4)
  56. # These are helper functions for parsers.
  57. # parser is the parser file name like parser.y
  58. # lexer is like lexer.l
  59. # The names of the output files will be based on the input names.
  60. # BF_SOURCES will be parser.cc, parser.h and lexer.cc.
  61. MACRO(GENERATE_BISON_FLEX_SOURCES parser parser_args
  62. lexer lexer_args)
  63. GET_FILENAME_COMPONENT(parser_base "${parser}" NAME_WE)
  64. SET(BISON_TAB_C "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.tab.cc")
  65. SET(BISON_TAB_H "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.tab.hh")
  66. SET(BISON_CC "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.cc")
  67. SET(BISON_H "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.h")
  68. ADD_CUSTOM_COMMAND(
  69. OUTPUT ${BISON_TAB_C} ${BISON_TAB_H}
  70. COMMAND ${BISON_EXECUTABLE}
  71. ARGS "${parser}" ${parser_args} "--defines"
  72. DEPENDS "${parser}"
  73. COMMENT "Generating ${BISON_TAB_C} ${BISON_TAB_H} from ${parser}"
  74. )
  75. ADD_CUSTOM_COMMAND(
  76. OUTPUT ${BISON_CC}
  77. COMMAND ${CMAKE_COMMAND}
  78. ARGS -E copy ${BISON_TAB_C} ${BISON_CC}
  79. DEPENDS ${BISON_TAB_C}
  80. COMMENT "Copying ${BISON_TAB_C} to ${BISON_CC}"
  81. )
  82. ADD_CUSTOM_COMMAND(
  83. OUTPUT ${BISON_H}
  84. COMMAND ${CMAKE_COMMAND}
  85. ARGS -E copy ${BISON_TAB_H} ${BISON_H}
  86. DEPENDS ${BISON_TAB_H}
  87. COMMENT "Copying ${BISON_TAB_H} to ${BISON_H}"
  88. )
  89. GET_FILENAME_COMPONENT(lexer_base "${lexer}" NAME_WE)
  90. SET(FLEX_C "${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c")
  91. SET(FLEX_CC "${CMAKE_CURRENT_BINARY_DIR}/${lexer_base}.cc")
  92. ADD_CUSTOM_COMMAND(
  93. OUTPUT ${FLEX_C}
  94. COMMAND ${FLEX_EXECUTABLE}
  95. ARGS "${lexer}" ${lexer_args}
  96. DEPENDS "${lexer}" ${BISON_H}
  97. COMMENT "Generating ${FLEX_C} from ${lexer}"
  98. )
  99. ADD_CUSTOM_COMMAND(
  100. OUTPUT ${FLEX_CC}
  101. COMMAND ${CMAKE_COMMAND}
  102. ARGS -E copy ${FLEX_C} ${FLEX_CC}
  103. DEPENDS ${FLEX_C}
  104. COMMENT "Copying ${FLEX_C} to ${FLEX_CC}"
  105. )
  106. SET(BF_SOURCES ${BISON_CC} ${BISON_H} ${FLEX_CC})
  107. ENDMACRO(GENERATE_BISON_FLEX_SOURCES)