0
votes

I have Makefile file which manage building of my bison&flex&c++ project:

CFLAGS = -g
all:      cppcalc
cppcalc:    cppcalc.lex.o cppcalc.tab.o
    c++ -g -o $@ cppcalc.tab.o cppcalc.lex.o -lm
cppcalc.lex.o: cppcalc.lex.c cppcalc.tab.hh cppcalc-ctx.hh
    c++ -c $<
cppcalc.tab.o: cppcalc.tab.cc cppcalc-ctx.hh klasa.hh
cppcalc.lex.c: cppcalc.l
    flex -ocppcalc.lex.c cppcalc.l
cppcalc.tab.cc cppcalc.tab.hh: cppcalc.yy
    bison -vd cppcalc.yy

This works all right. I would like to convert this think to cmake. Right now I wrote something like this below, but I am getting errors after I typed make and I have no idea what is wrong:

cmake_minimum_required(VERSION 2.8)

find_package(BISON)
find_package(FLEX)

BISON_TARGET(MyParser cppcalc.yy ${CMAKE_CURRENT_BINARY_DIR}/cppcalc.tab.cc COMPILE_FLAGS -vd)
FLEX_TARGET(MyScanner cppcalc.l  ${CMAKE_CURRENT_BINARY_DIR}/cppcalc.lex.c)
ADD_FLEX_BISON_DEPENDENCY(MyScanner MyParser)

 include_directories(${CMAKE_CURRENT_BINARY_DIR})
 add_executable(Foo
    ${BISON_MyParser_OUTPUTS}
    ${FLEX_MyScanner_OUTPUTS}
    cppcalc-ctx.hh
    klasa.hh
 )

output

1
Check that file cppcalc-ctx.hh exists. As for klasa.hh, it probably is in your source directory, so you should issue appropriate include_directories() command. - Tsyvarev
Turn on verbose build output (can cmake do that?) and see what compilation command is actually being run (to see what flags are, or aren't, being passed). - Etan Reisner
@EtanReisner For make it would be make VERBOSE=1 - usr1234567
@usr1234567 For cmake having output to Makefiles you mean? (Because make itself doesn't have that sort of concept.) - Etan Reisner
@EtanReisner That's a shell variable evaluated by the Makefile generated from CMake. - usr1234567

1 Answers

0
votes
cmake_minimum_required(VERSION 2.8)

find_package(BISON 2.4.1)
find_package(FLEX 2.5.35)

BISON_TARGET(MyParser cppcalc.yy ${CMAKE_CURRENT_BINARY_DIR}/cppcalc.tab.cpp)
FLEX_TARGET(MyScanner cppcalc.l  ${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp)
ADD_FLEX_BISON_DEPENDENCY(MyScanner MyParser)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(Calc
  ${BISON_MyParser_OUTPUTS}
  ${FLEX_MyScanner_OUTPUTS}
)