views:

259

answers:

1

I require the syntax of a CMAKE macro that generates .cc and .h files from a tool like lex/yacc.

Could someone please show me the syntax for the following contrived example:

say I have a file y.cc that depends on x.cc and x.h, the two files mentioned are generated by tool z_tool from file x.z. What would the syntax for this be ?

For this example assume that y.cc will be turned into a static library, and as I am quite new to CMAKE the full CMakellist.txt for this contrived example would be very helpful.I'm looking for a portable solution as the tools I am using are available on windows as well as UNIX variants.

+2  A: 

Rather than give you the answer to a contrived example, here is the way you would generate an executable using flex and bison

find_package(BISON)
find_package(FLEX)

BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cc)
FLEX_TARGET(MyScanner lexer.l  ${CMAKE_CURRENT_BIANRY_DIR}/lexer.cc)
ADD_FLEX_BISON_DEPENDENCY(MyScanner MyParser)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(Foo
  Foo.cc
  ${BISON_MyParser_OUTPUTS}
  ${FLEX_MyScanner_OUTPUTS})

The CMake find packages for bison/flex are included in the default installation, so this is cross platform.

In general to create an output that will later be used as an input you can use the add_custom_command function. If you use an output from the custom command as an input to a library or executable, then CMake knows to run your custom command before compiling the sources for the library/executable target.

rq
Nicely explained. The gist was indeed how to wire up the outputs and inputs :D
Hassan Syed