尝试向已有自定义规则的输出添加自定义规则
Attempt to add a custom rule to output which already has a custom rule
我正在使用 cmake 编译一个使用 flex 和 bison 的库,但我遇到了这个错误:
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.
这是我用来编译它的 CMakeLists 的内容。
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)
我相信,我遵循了文档,但我不明白为什么它会失败。 谁能帮我解决这个问题?
您需要为 flex 和 bison 目标指定不同的输出文件。
flex_target(lexer automaton_lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lexer.c)
bison_target(parser automaton_parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.c)