Thanks, James.<br><br><div><span class="gmail_quote">On 5/16/07, <b class="gmail_sendername">James Bigler</b> &lt;<a href="mailto:bigler@cs.utah.edu">bigler@cs.utah.edu</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Clark J. Wang wrote:<br>&gt; I read through the CMake&#39;s man page and found no support for lex/flex and<br>&gt; yacc/bison. Need I define my own rules to handle with lex/yacc source<br>&gt; files?<br><br>Yup, I haven&#39;t seen one either.&nbsp;&nbsp;I&#39;ve attached the one that I&#39;ve wrote and have
<br>been using.&nbsp;&nbsp;It does some fiddling with the output file names, but you can see<br>that in the code.<br><br>Here&#39;s some code that uses it:<br><br>&nbsp;&nbsp; INCLUDE(${CMAKE_SOURCE_DIR}/CMake/FindParsers.cmake)<br><br>&nbsp;&nbsp; IF(PARSERS_FOUND)
<br><br>&nbsp;&nbsp;&nbsp;&nbsp; GENERATE_BISON_FLEX_SOURCES(${CMAKE_CURRENT_SOURCE_DIR}/parse.y &quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ${CMAKE_CURRENT_SOURCE_DIR}/lex.l&nbsp;&nbsp; &quot;&quot;)<br><br>&nbsp;&nbsp;&nbsp;&nbsp; INCLUDE_DIRECTORIES(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ${CMAKE_CURRENT_BINARY_DIR}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br><br>&nbsp;&nbsp;&nbsp;&nbsp; ADD_LIBRARY(mylib mycode.cc ${BF_SOURCES})<br>&nbsp;&nbsp;&nbsp;&nbsp; TARGET_LINK_LIBRARIES(scene_galileo ${OTHER_LIBRARIES})<br><br>&nbsp;&nbsp; ELSE(PARSERS_FOUND)<br>&nbsp;&nbsp;&nbsp;&nbsp; # Opps, didn&#39;t find the parsers<br>&nbsp;&nbsp;&nbsp;&nbsp; MESSAGE(SEND_ERROR &quot;The parsing tools can&#39;t be found.&quot;)
<br>&nbsp;&nbsp; ENDIF(PARSERS_FOUND)<br><br><br>James<br><br># /*<br>#&nbsp;&nbsp; For more information, please see: <a href="http://software.sci.utah.edu">http://software.sci.utah.edu</a><br><br>#&nbsp;&nbsp; The MIT License<br><br>#&nbsp;&nbsp; Copyright (c) 2005-2006
<br>#&nbsp;&nbsp; Scientific Computing and Imaging Institute, University of Utah<br><br>#&nbsp;&nbsp; License for the specific language governing rights and limitations under<br>#&nbsp;&nbsp; Permission is hereby granted, free of charge, to any person obtaining a
<br>#&nbsp;&nbsp; copy of this software and associated documentation files (the &quot;Software&quot;),<br>#&nbsp;&nbsp; to deal in the Software without restriction, including without limitation<br>#&nbsp;&nbsp; the rights to use, copy, modify, merge, publish, distribute, sublicense,
<br>#&nbsp;&nbsp; and/or sell copies of the Software, and to permit persons to whom the<br>#&nbsp;&nbsp; Software is furnished to do so, subject to the following conditions:<br><br>#&nbsp;&nbsp; The above copyright notice and this permission notice shall be included
<br>#&nbsp;&nbsp; in all copies or substantial portions of the Software.<br><br>#&nbsp;&nbsp; THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>#&nbsp;&nbsp; OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
<br>#&nbsp;&nbsp; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>#&nbsp;&nbsp; THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>#&nbsp;&nbsp; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
<br>#&nbsp;&nbsp; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>#&nbsp;&nbsp; DEALINGS IN THE SOFTWARE.<br># */<br><br>SET(PARSERS_FOUND FOOBAR)<br><br># These variables need to be specified in order to get CMake not to
<br># barf on the IF(EXISTS ${BISON_EXECUTABLE} ..) expression even though<br># the code shouldn&#39;t get called.&nbsp;&nbsp;By setting them to BISON_EXECUTABLE<br><br>SET(BISON_EXECUTABLE &quot;BISON_EXECUTABLE-NOTFOUND&quot; CACHE FILEPATH &quot;bison executable&quot;)
<br>SET(FLEX_EXECUTABLE &quot;FLEX_EXECUTABLE-NOTFOUND&quot; CACHE FILEPATH &quot;flex executable&quot;)<br># Mark these variables as advanced options<br>MARK_AS_ADVANCED(FORCE BISON_EXECUTABLE)<br>MARK_AS_ADVANCED(FORCE FLEX_EXECUTABLE)
<br><br># You need at least version 2.4 for this to work.<br>IF(&quot;${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}&quot; LESS 2.4)<br>&nbsp;&nbsp;MESSAGE(&quot;You need at least version 2.4 for generating flex and bison parsers.&nbsp;&nbsp;Go get it from 
<a href="http://www.cmake.org/HTML/Download.html">http://www.cmake.org/HTML/Download.html</a>&quot;)<br>&nbsp;&nbsp;SET(PARSERS_FOUND 0)<br><br>ELSE(&quot;${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}&quot; LESS 2.4)<br><br>&nbsp;&nbsp;FIND_PROGRAM(BISON_EXECUTABLE
<br>&nbsp;&nbsp;&nbsp;&nbsp;NAMES bison<br>&nbsp;&nbsp;&nbsp;&nbsp;PATHS ${BISON_DIR} )<br><br>&nbsp;&nbsp;FIND_PROGRAM(FLEX_EXECUTABLE<br>&nbsp;&nbsp;&nbsp;&nbsp;NAMES flex<br>&nbsp;&nbsp;&nbsp;&nbsp;PATHS ${FLEX_DIR} )<br><br>&nbsp;&nbsp;IF(EXISTS ${BISON_EXECUTABLE} AND EXISTS ${FLEX_EXECUTABLE})<br>&nbsp;&nbsp;&nbsp;&nbsp;SET(PARSERS_FOUND 1)
<br><br>&nbsp;&nbsp;ELSE(EXISTS ${BISON_EXECUTABLE} AND EXISTS ${FLEX_EXECUTABLE})<br>&nbsp;&nbsp;&nbsp;&nbsp;SET(PARSERS_FOUND 0)<br>&nbsp;&nbsp;&nbsp;&nbsp;# Print some error messages to the user<br>&nbsp;&nbsp;&nbsp;&nbsp;IF (NOT EXISTS ${BISON_EXECUTABLE})<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MESSAGE(&quot;Couldn&#39;t find bison executable.&nbsp;&nbsp;Please check value in BISON_EXECUTABLE in advanced settings.&quot;)
<br>&nbsp;&nbsp;&nbsp;&nbsp;ENDIF (NOT EXISTS ${BISON_EXECUTABLE})<br>&nbsp;&nbsp;&nbsp;&nbsp;IF (NOT EXISTS ${FLEX_EXECUTABLE})<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MESSAGE(&quot;Couldn&#39;t find flex executable.&nbsp;&nbsp;Please check value in FLEX_EXECUTABLE in advanced settings.&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;ENDIF (NOT EXISTS ${FLEX_EXECUTABLE})
<br><br>&nbsp;&nbsp;ENDIF(EXISTS ${BISON_EXECUTABLE} AND EXISTS ${FLEX_EXECUTABLE})<br><br>ENDIF(&quot;${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}&quot; LESS 2.4)<br><br># These are helper functions for parsers.<br><br># parser is the parser file name like 
parser.y<br># lexer is like lexer.l<br><br># The names of the output files will be based on the input names.<br># BF_SOURCES will be parser.cc, parser.h and lexer.cc.<br><br>MACRO(GENERATE_BISON_FLEX_SOURCES parser parser_args
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lexer&nbsp;&nbsp;lexer_args)<br>&nbsp;&nbsp;GET_FILENAME_COMPONENT(parser_base &quot;${parser}&quot; NAME_WE)<br><br>&nbsp;&nbsp;SET(BISON_TAB_C &quot;${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.tab.c&quot;)<br>&nbsp;&nbsp;SET(BISON_TAB_H &quot;${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.tab.h&quot;)
<br>&nbsp;&nbsp;SET(BISON_CC&nbsp;&nbsp;&nbsp;&nbsp;&quot;${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.cc&quot;)<br>&nbsp;&nbsp;SET(BISON_H&nbsp;&nbsp;&nbsp;&nbsp; &quot;${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.h&quot;)<br><br>&nbsp;&nbsp;ADD_CUSTOM_COMMAND(<br>&nbsp;&nbsp;&nbsp;&nbsp;OUTPUT ${BISON_TAB_C} ${BISON_TAB_H}
<br>&nbsp;&nbsp;&nbsp;&nbsp;COMMAND ${BISON_EXECUTABLE}<br>&nbsp;&nbsp;&nbsp;&nbsp;ARGS &quot;${parser}&quot; ${parser_args} &quot;--defines&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;DEPENDS &quot;${parser}&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;COMMENT &quot;Generating ${BISON_TAB_C} ${BISON_TAB_H} from ${parser}&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;)<br><br>&nbsp;&nbsp;ADD_CUSTOM_COMMAND(<br>&nbsp;&nbsp;&nbsp;&nbsp;OUTPUT ${BISON_CC}<br>&nbsp;&nbsp;&nbsp;&nbsp;COMMAND&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${CMAKE_COMMAND}<br>&nbsp;&nbsp;&nbsp;&nbsp;ARGS -E copy ${BISON_TAB_C} ${BISON_CC}<br>&nbsp;&nbsp;&nbsp;&nbsp;DEPENDS ${BISON_TAB_C}<br>&nbsp;&nbsp;&nbsp;&nbsp;COMMENT &quot;Copying ${BISON_TAB_C} to ${BISON_CC}&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;)<br><br>&nbsp;&nbsp;ADD_CUSTOM_COMMAND(<br>&nbsp;&nbsp;&nbsp;&nbsp;OUTPUT ${BISON_H}<br>&nbsp;&nbsp;&nbsp;&nbsp;COMMAND&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${CMAKE_COMMAND}<br>&nbsp;&nbsp;&nbsp;&nbsp;ARGS -E copy ${BISON_TAB_H} ${BISON_H}<br>&nbsp;&nbsp;&nbsp;&nbsp;DEPENDS ${BISON_TAB_H}<br>&nbsp;&nbsp;&nbsp;&nbsp;COMMENT &quot;Copying ${BISON_TAB_H} to ${BISON_H}&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;)<br><br>&nbsp;&nbsp;GET_FILENAME_COMPONENT(lexer_base &quot;${lexer}&quot; NAME_WE)<br>&nbsp;&nbsp;SET(FLEX_C &quot;${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c&quot;)<br>&nbsp;&nbsp;SET(FLEX_CC &quot;${CMAKE_CURRENT_BINARY_DIR}/${lexer_base}.cc&quot;)
<br><br>&nbsp;&nbsp;ADD_CUSTOM_COMMAND(<br>&nbsp;&nbsp;&nbsp;&nbsp;OUTPUT ${FLEX_C}<br>&nbsp;&nbsp;&nbsp;&nbsp;COMMAND ${FLEX_EXECUTABLE}<br>&nbsp;&nbsp;&nbsp;&nbsp;ARGS &quot;${lexer}&quot; ${lexer_args}<br>&nbsp;&nbsp;&nbsp;&nbsp;DEPENDS &quot;${lexer}&quot; ${BISON_H}<br>&nbsp;&nbsp;&nbsp;&nbsp;COMMENT &quot;Generating ${FLEX_C} from ${lexer}&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;)<br><br>&nbsp;&nbsp;ADD_CUSTOM_COMMAND(<br>&nbsp;&nbsp;&nbsp;&nbsp;OUTPUT ${FLEX_CC}<br>&nbsp;&nbsp;&nbsp;&nbsp;COMMAND&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${CMAKE_COMMAND}<br>&nbsp;&nbsp;&nbsp;&nbsp;ARGS -E copy ${FLEX_C} ${FLEX_CC}<br>&nbsp;&nbsp;&nbsp;&nbsp;DEPENDS ${FLEX_C}<br>&nbsp;&nbsp;&nbsp;&nbsp;COMMENT &quot;Copying ${FLEX_C} to ${FLEX_CC}&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;)<br><br>&nbsp;&nbsp;SET(BF_SOURCES ${BISON_CC} ${BISON_H} ${FLEX_CC})<br><br>ENDMACRO(GENERATE_BISON_FLEX_SOURCES)</blockquote></div>