[CMake] No support for lex/flex and yacc/bison?

James Bigler bigler at cs.utah.edu
Wed May 16 12:35:18 EDT 2007


Mielcarek, Donn wrote:
> Thanks for posting the flex/bison code.
> 
> Two things:
> 
> I had to change:
>  SET(BISON_TAB_C "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.tab.cc")
> to
>  SET(BISON_TAB_C "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.tab.bison_cc")

This code was designed to copy whatever bison generated which is a .c 
file to a .cc file.  If you are passing in other args to change the 
output file name, you will have to adjust these file names.  The bison 
I'm using spits out ${parser_base}.tab.c.

So, I'm guessing you modified something else.  This is what I have:

   SET(BISON_TAB_C "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.tab.c")
   SET(BISON_CC    "${CMAKE_CURRENT_BINARY_DIR}/${parser_base}.cc")

The rules I made will create a command to generate BISON_TAB_C with 
bison.  It will then make another rule to copy BISON_TAB_C to BISON_CC. 
  It is probably getting confused somewhere, but I can tell for sure 
without seeing your modified .cmake file.

> (and likewise for the other constructs)
> 
> Otherwise I would get the message:
> CMake Error: Attempt to add a custom rule to output "[...]/parser.cc.rule"
>  which already has a custom rule.
> 
> 
> The other issue is the creation of the library, which is
> a problem I've been struggling with.
> 
> ADD_LIBRARY(mylib ${BF_SOURCES})
> causes the error message:
> 
> You have called ADD_LIBRARY for library mylib without any source files. This
> typically indicates a problem with your CMakeLists.txt file
> 
> I added:
> SET_SOURCE_FILES_PROPERTIES(${BF_SOURCES} GENERATED)
> 
> but it doesn't help.

In the example I gave you it had a source file, mycode.cc.  Typically 
you need some kind of driving code for the parser.  Stick that in mycode.cc.

     ADD_LIBRARY(mylib mycode.cc ${BF_SOURCES})


James


More information about the CMake mailing list