2017-07-02 84 views
0

我想將Makefile翻譯成CMakeLists.txt。CMake與靈活/野牛在CLION

的Makefile其中工程

fb1-5: fb1-5.l fb1-5.y 
    bison -d fb1-5.y 
    flex fb1-5.l 
    cc -o [email protected] 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}) 

它說,它發現野牛和Flex在

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

但我的CMake的腳本不會產生可執行文件。我應該如何定義「可執行文件」以及如何使CMake構建腳本在CLion中工作?

+2

'但我應該如何定義「可執行文件」' - add_executable(fb1-5.tab.c lex.yy.c)有什麼問題? '我怎樣才能讓CMake構建腳本在CLion中工作?' - 當前腳本有什麼問題? [FindFLEX]的文檔(https://cmake.org/cmake/help/v3.7/module/FindFLEX.html)有一個很好的使用這個模塊提供的函數的示例([FindBISON](https:// cmake.org/cmake/help/v3.7/module/FindBISON.html)模塊)。你檢查過這個例子嗎? – Tsyvarev

回答

1

但我的CMake腳本不會生成可執行文件。我應該如何定義「可執行文件」以及如何使CMake構建腳本在CLion中工作?

我想你至少應該做這樣的事情:

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

add_executable