I am using cmake to compile a library using flex & bison and I have this error:
CMake Error at /usr/share/cmake/Modules/FindBISON.cmake:279 (add_custom_command):
Attempt to add a custom rule to output
PATH/automaton.c.rule
which already has a custom rule.
Here is the content of my CMakeLists meant to compile it.
FIND_PACKAGE(BISON REQUIRED)
FIND_PACKAGE(FLEX REQUIRED)
flex_target(lexer automaton_lexer.l ${CMAKE_CURRENT_BINARY_DIR}/automaton.c)
bison_target(parser automaton_parser.y ${CMAKE_CURRENT_BINARY_DIR}/automaton.c)
add_flex_bison_dependency(lexer parser)
add_library(automaton automaton.c queue.c tikz_handler.c ${FLEX_lexer_OUTPUTS} ${BISON_parser_OUTPUTS})
target_link_libraries(automaton ${FLEX_LIBRARIES})
target_include_directories(automaton PUBLIC headers)
I believe, I followed the documentation, yet I can't figure why it fails. Could anyone help me on this?
You need to specify different output files for flex and bison targets.
flex_target(lexer automaton_lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.c)
bison_target(parser automaton_parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.c)