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