我的项目中有一个带有两个cmake文件的子目录结构。其中一个应该是编译器,使用flex和bison,但是cmake给了我一个我不太明白的错误:
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
那我做错了什么?
答案 0 :(得分:4)
看来你刚刚把ADD_FLEX_BISON_DEPENDENCY
的论据搞砸了。尝试:
ADD_FLEX_BISON_DEPENDENCY(LeafScanner LeafParser)
此外,您的FLEX_TARGET
电话中存在拼写错误(CMAKE_CURRENT_ BIANRY _DIR)。