Rename EvalHHIRAllocXMMRegs to EvalHHIRAllocSIMDRegs
[hiphop-php.git] / CMake / FindBISON.cmake
blobbe18333494fc4a1e1ec09af0ceff2889f7f49bb8
1 # - Find bison executable and provides macros to generate custom build rules\r
2 # The module defined the following variables:\r
3 #  BISON_EXECUTABLE - path to the bison program\r
4 #  BISON_VERSION - version of bison\r
5 #  BISON_FOUND - true if the program was found\r
6 # If bison is found, the module defines the macros:\r
7 #  BISON_TARGET(<Name> <YaccInput> <CodeOutput> [VERBOSE <file>]\r
8 #              [COMPILE_FLAGS <string>])\r
9 # which will create  a custom rule to generate  a parser. <YaccInput> is\r
10 # the path to  a yacc file. <CodeOutput> is the name  of the source file\r
11 # generated by bison.  A header file is also  be generated, and contains\r
12 # the  token  list.  If  COMPILE_FLAGS  option is  specified,  the  next\r
13 # parameter is  added in the bison  command line.  if  VERBOSE option is\r
14 # specified, <file> is created  and contains verbose descriptions of the\r
15 # grammar and parser. The macro defines a set of variables:\r
16 #  BISON_${Name}_DEFINED - true is the macro ran successfully\r
17 #  BISON_${Name}_INPUT - The input source file, an alias for <YaccInput>\r
18 #  BISON_${Name}_OUTPUT_SOURCE - The source file generated by bison\r
19 #  BISON_${Name}_OUTPUT_HEADER - The header file generated by bison\r
20 #  BISON_${Name}_OUTPUTS - The sources files generated by bison\r
21 #  BISON_${Name}_COMPILE_FLAGS - Options used in the bison command line\r
22 #\r
23 # Example:\r
24 # FIND_PACKAGE(BISON)\r
25 # BISON_TARGET(MyParser parser.y ${PROJECT_BINARY_DIR}/parser.cpp)\r
26 # ADD_EXECUTABLE(Foo main.cpp ${BISON_MyParser_OUTPUTS})\r
27 #\r
29 # Copyright (c) 2006, Tristan Carel\r
30 # All rights reserved.\r
31 # Redistribution and use in source and binary forms, with or without\r
32 # modification, are permitted provided that the following conditions are met:\r
33 #\r
34 #     * Redistributions of source code must retain the above copyright\r
35 #       notice, this list of conditions and the following disclaimer.\r
36 #     * Redistributions in binary form must reproduce the above copyright\r
37 #       notice, this list of conditions and the following disclaimer in the\r
38 #       documentation and/or other materials provided with the distribution.\r
39 #     * Neither the name of the University of California, Berkeley nor the\r
40 #       names of its contributors may be used to endorse or promote products\r
41 #       derived from this software without specific prior written permission.\r
42 #\r
43 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY\r
44 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
45 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
46 # DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY\r
47 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
48 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
49 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
50 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
51 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
52 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
54 # $Id:: FindBISON.cmake 3 2006-11-03 02:42:02Z ken                            $\r
56 SET(BISON_FOUND FALSE)\r
58 FIND_PROGRAM(BISON_EXECUTABLE bison DOC "path to the bison executable")\r
59 MARK_AS_ADVANCED(BISON_EXECUTABLE)\r
61 IF(BISON_EXECUTABLE)\r
62   SET(BISON_FOUND TRUE)\r
64   EXECUTE_PROCESS(COMMAND ${BISON_EXECUTABLE} --version\r
65     OUTPUT_VARIABLE BISON_version_output\r
66     ERROR_VARIABLE BISON_version_error\r
67     RESULT_VARIABLE BISON_version_result\r
68     OUTPUT_STRIP_TRAILING_WHITESPACE)\r
69   IF(NOT ${BISON_version_result} EQUAL 0)\r
70     MESSAGE(SEND_ERROR "Command \"${BISON_EXECUTABLE} --version\" failed with output:\n${BISON_version_error}")\r
71   ELSE(NOT ${BISON_version_result} EQUAL 0)\r
72     STRING(REGEX REPLACE "^bison \\(GNU Bison\\) ([^\n]+)\n.*" "\\1"\r
73       BISON_VERSION "${BISON_version_output}")\r
74   ENDIF(NOT ${BISON_version_result} EQUAL 0)\r
76   # internal macro\r
77   MACRO(BISON_TARGET_option_verbose Name BisonOutput filename)\r
78     LIST(APPEND BISON_TARGET_cmdopt "--verbose")\r
79     GET_FILENAME_COMPONENT(BISON_TARGET_output_path "${BisonOutput}" PATH)\r
80     GET_FILENAME_COMPONENT(BISON_TARGET_output_name "${BisonOutput}" NAME_WE)\r
81     ADD_CUSTOM_COMMAND(OUTPUT ${filename}\r
82       COMMAND ${CMAKE_COMMAND} -E copy\r
83       "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output"\r
84       "${filename}"\r
85       DEPENDS\r
86       "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output"\r
87       COMMENT "[BISON][${Name}] Copying bison verbose table to ${filename}"\r
88       WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})\r
89     SET(BISON_${Name}_VERBOSE_FILE ${filename})\r
90     LIST(APPEND BISON_TARGET_extraoutputs\r
91       "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output")\r
92   ENDMACRO(BISON_TARGET_option_verbose)\r
94   # internal macro\r
95   MACRO(BISON_TARGET_option_extraopts Options)\r
96     SET(BISON_TARGET_extraopts "${Options}")\r
97     SEPARATE_ARGUMENTS(BISON_TARGET_extraopts)\r
98     LIST(APPEND BISON_TARGET_cmdopt ${BISON_TARGET_extraopts})\r
99   ENDMACRO(BISON_TARGET_option_extraopts)\r
101   MACRO(BISON_TARGET Name BisonInput BisonOutput)\r
102     SET(BISON_TARGET_output_header "")\r
103     SET(BISON_TARGET_cmdopt "")\r
104     SET(BISON_TARGET_outputs "${BisonOutput}")\r
106     IF(NOT ${ARGC} EQUAL 3 AND NOT ${ARGC} EQUAL 5 AND NOT ${ARGC} EQUAL 7)\r
107       MESSAGE(SEND_ERROR "Usage")\r
108     ELSE(NOT ${ARGC} EQUAL 3 AND NOT ${ARGC} EQUAL 5 AND NOT ${ARGC} EQUAL 7)\r
109       # Parsing parameters\r
110       IF(${ARGC} GREATER 5 OR ${ARGC} EQUAL 5)\r
111         IF("${ARGV3}" STREQUAL "VERBOSE")\r
112           BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${ARGV4}")\r
113         ENDIF("${ARGV3}" STREQUAL "VERBOSE")\r
114         IF("${ARGV3}" STREQUAL "COMPILE_FLAGS")\r
115           BISON_TARGET_option_extraopts("${ARGV4}")\r
116         ENDIF("${ARGV3}" STREQUAL "COMPILE_FLAGS")\r
117       ENDIF(${ARGC} GREATER 5 OR ${ARGC} EQUAL 5)\r
118       IF(${ARGC} EQUAL 7)\r
119         IF("${ARGV5}" STREQUAL "VERBOSE")\r
120           BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${ARGV6}")\r
121         ENDIF("${ARGV5}" STREQUAL "VERBOSE")\r
122         IF("${ARGV5}" STREQUAL "COMPILE_FLAGS")\r
123           BISON_TARGET_option_extraopts("${ARGV6}")\r
124         ENDIF("${ARGV5}" STREQUAL "COMPILE_FLAGS")\r
125       ENDIF(${ARGC} EQUAL 7)\r
127       # Header's name generated by bison (see option -d)\r
128       LIST(APPEND BISON_TARGET_cmdopt "-d")\r
129       STRING(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\2" _fileext "${ARGV2}")\r
130       STRING(REPLACE "c" "h" _fileext ${_fileext})\r
131       STRING(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\1${_fileext}"\r
132         BISON_${Name}_OUTPUT_HEADER "${ARGV2}")\r
133       LIST(APPEND BISON_TARGET_outputs "${BISON_${Name}_OUTPUT_HEADER}")\r
135       ADD_CUSTOM_COMMAND(OUTPUT ${BISON_TARGET_outputs}\r
136         ${BISON_TARGET_extraoutputs}\r
137         COMMAND ${BISON_EXECUTABLE} ${BISON_TARGET_cmdopt} -o ${ARGV2} ${ARGV1}\r
138         DEPENDS ${ARGV1}\r
139         COMMENT "[BISON][${Name}] Building parser with bison ${BISON_VERSION}"\r
140         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})\r
142       # define target variables\r
143       SET(BISON_${Name}_DEFINED TRUE)\r
144       SET(BISON_${Name}_INPUT ${ARGV1})\r
145       SET(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs})\r
146       SET(BISON_${Name}_COMPILE_FLAGS ${BISON_TARGET_cmdopt})\r
147       SET(BISON_${Name}_OUTPUT_SOURCE "${BisonOutput}")\r
149     ENDIF(NOT ${ARGC} EQUAL 3 AND NOT ${ARGC} EQUAL 5 AND NOT ${ARGC} EQUAL 7)\r
150   ENDMACRO(BISON_TARGET)\r
152 ENDIF(BISON_EXECUTABLE)\r
155 IF(NOT BISON_FOUND)\r
156   IF(NOT BISON_FIND_QUIETLY)\r
157     MESSAGE(STATUS "BISON was not found.")\r
158   ELSE(NOT BISON_FIND_QUIETLY)\r
159     IF(BISON_FIND_REQUIRED)\r
160       MESSAGE(FATAL_ERROR "BISON was not found.")\r
161     ENDIF(BISON_FIND_REQUIRED)\r
162   ENDIF(NOT BISON_FIND_QUIETLY)\r
163 ENDIF(NOT BISON_FOUND)\r
165 # FindBISON.cmake ends here\r