【问题标题】:CMake with flex/bison in CLion在 CLion 中使用 flex/bison 进行 CMake
【发布时间】:2017-07-02 02:03:24
【问题描述】:

我正在尝试将 Makefile 转换为 CMakeLists.txt。

有效的Makefile

fb1-5:  fb1-5.l fb1-5.y
    bison -d fb1-5.y
    flex fb1-5.l
    cc -o $@ fb1-5.tab.c lex.yy.c -lfl

CMakeLists.txt 尝试

cmake_minimum_required(VERSION 3.7)
project(calc)

set(CMAKE_C_STANDARD 99)

FIND_PACKAGE(BISON REQUIRED)
SET(BisonOutput ${CMAKE_SOURCE_DIR}/parser.c)
IF(BISON_FOUND)
    ADD_CUSTOM_COMMAND(
            OUTPUT ${BisonOutput}
            COMMAND ${BISON_EXECUTABLE}
            -d
            ${CMAKE_SOURCE_DIR}/fb1-5.y
            COMMENT "Generating parser.c"
    )
ENDIF()

FIND_PACKAGE(FLEX REQUIRED)
SET(FlexOutput ${CMAKE_SOURCE_DIR}/scanner.c)
IF(FLEX_FOUND)
    ADD_CUSTOM_COMMAND(
            OUTPUT ${FlexOutput}
            COMMAND ${FLEX_EXECUTABLE}
            ${CMAKE_SOURCE_DIR}/fb1-5.l
            COMMENT "Generating fb1-5.l"
    )
ENDIF()

ADD_LIBRARY(calc ${BisonOutput} ${FlexOutput})

它说它在 中找到了 bison 和 flex

-- Found BISON: /usr/bin/bison (found version "3.0.4") 
-- Found FLEX: /usr/bin/flex (found version "2.6.0") 

但我的 CMake 脚本不会生成可执行文件。我应该如何定义“可执行”以及如何使 CMake 构建脚本在 CLion 中工作?

【问题讨论】:

  • But how should I define "executable" - add_executable(fb1-5.tab.c lex.yy.c) 有什么问题? how can I make the CMake build script work in CLion? - 当前脚本有什么问题? FindFLEX 的文档有一个很好的例子来说明使用这个模块提供的函数(以及 FindBISON 模块)。你检查过这个例子吗?

标签: clion c makefile cmake bison flex-lexer


【解决方案1】:

但我的 CMake 脚本不会生成可执行文件。我应该如何定义“可执行”以及如何使 CMake 构建脚本在 CLion 中工作?

我认为你至少应该这样做:

add_executable(fb1-5
  ${BisonOutput}
  ${FlexOutput}
)

add_executable

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-09
    • 2013-10-24
    • 2019-06-15
    • 1970-01-01
    • 2017-02-10
    • 1970-01-01
    • 1970-01-01
    • 2011-08-23
    相关资源
    最近更新 更多