2011-12-02 93 views
4

我在我的項目中有兩個cmake文件的子目錄結構。其中之一應該是一個編譯器,使用Flex和野牛,但CMake的給我一個錯誤,我不很明白:Flex /野牛目標不存在

cmake_minimum_required(VERSION 2.8) 

project(leaf) 

add_subdirectory(leafc) 

,並在目錄leafc

find_package(BISON) 
find_package(FLEX) 

BISON_TARGET(LeafParser ${CMAKE_CURRENT_SOURCE_DIR}/parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp) 
FLEX_TARGET(LeafScanner ${CMAKE_CURRENT_SOURCE_DIR}/lexer.l ${CMAKE_CURRENT_BIANRY_DIR}/lexer.cpp) 
ADD_FLEX_BISON_DEPENDENCY(LeafParser LeafScanner) 

include_directories(${CMAKE_CURRENT_BINARY_DIR}) 
add_executable(leafc main.cpp ${BISON_LeafParser_OUTPUTS} ${FLEX_LeafScanner_OUTPUTS}) 

,但我得到這個試圖cmake .

CMake Error at /usr/share/cmake-2.8/Modules/FindFLEX.cmake:132 (MESSAGE): 
    Flex target `LeafParser' does not exists. 
Call Stack (most recent call first): 
    leafc/CMakeLists.txt:6 (ADD_FLEX_BISON_DEPENDENCY) 

CMake Error at /usr/share/cmake-2.8/Modules/FindFLEX.cmake:136 (MESSAGE): 
    Bison target `LeafScanner' does not exists. 
Call Stack (most recent call first): 
    leafc/CMakeLists.txt:6 (ADD_FLEX_BISON_DEPENDENCY) 

CMake Error at /usr/share/cmake-2.8/Modules/FindFLEX.cmake:139 (SET_SOURCE_FILES_PROPERTIES): 
    set_source_files_properties called with incorrect number of arguments. 
Call Stack (most recent call first): 
    leafc/CMakeLists.txt:6 (ADD_FLEX_BISON_DEPENDENCY) 

-- Configuring incomplete, errors occurred! 

當錯誤文件有:

├── CMakeLists.txt 
├── leafc 
│   ├── CMakeLists.txt 
│   ├── lexer.l 
│   ├── main.cpp 
│   └── parser.y 
└── README 

那麼我做錯了什麼?

回答

4

看來你剛剛把ADD_FLEX_BISON_DEPENDENCY的參數弄混了。嘗試:

ADD_FLEX_BISON_DEPENDENCY(LeafScanner LeafParser) 

此外,還有一個錯字在您的通話FLEX_TARGET(CMAKE_CURRENT_ BIANRY _DIR)。

+0

謝謝,雖然我現在從'make'中得到了錯誤:'make [2]:***沒有規則使目標'parser.hpp',由'leafc/CMakeFiles/leafc.dir/lexer.cpp的.o」。 Stop.'任何想法? – Lanbo

+0

可能是由錯字造成的。查看更新的答案。 – sakra