2012-06-06 80 views
0

我有一個automake構建系統的項目,那裏有flex/bison文件。現在我無法理解如何將它們包含到cmake構建系統中。我正在嘗試手動執行此操作。下面是該項目的樹:爲cmake生成文件

+ROOT 
|---CMakeLists.txt 
|---Sources/ 
| |---Flex 
| |---Main 
| |---CMakeLists.txt 
|---Includes/ 

Flex文件夾下有2個文件:player_command_parser.ypp; player_command_tok.lpp。這些文件是從RoboCup soccer server

我真的不知道如何將它們與新的構建系統中使用,所以我決定用手手動生成的所有文件:

flex --c++ player_command_tok.lpp 

此命令生成lex.RCSSPCom.cc與下面的代碼開始:

#line 3 "lex.RCSSPCom.cc" 

#define YY_INT_ALIGNED short int 

/* A lexical scanner generated by flex */ 

#define FLEX_SCANNER 
#define YY_FLEX_MAJOR_VERSION 2 
#define YY_FLEX_MINOR_VERSION 5 
#define YY_FLEX_SUBMINOR_VERSION 35 
#if YY_FLEX_SUBMINOR_VERSION > 0 
#define FLEX_BETA 
#endif 

    /* The c++ scanner is a mess. The FlexLexer.h header file relies on the 
    * following macro. This is required in order to pass the c++-multiple-scanners 
    * test in the regression suite. We get reports that it breaks inheritance. 
    * We will address this in a future release of flex, or omit the C++ scanner 
    * altogether. 
    */ 
    #define yyFlexLexer RCSSPComFlexLexer 

下一步是:bison -d player_command_parser.ypp

我:player_command_parser.tab.cpp; player_command_parser.tab.hpp

現在我想所有生成的文件複製到相關的文件夾:* .tab.hpp - >包括,和新增的CC & cpp文件到Sources/CMakeLists.txt

set (FlexSources 
    Server/Flex/lex.RCSSPCom.cc 
    Server/Flex/player_command_parser.tab.cpp 
) 

並編譯輸出:

[ 1%] Building CXX object Sources/Flex/lex.RCSSPCom.cc.o 
In file included from /Includes/player_command_tok.h:31:0, 
       from player_command_tok.lpp:28: 
/usr/include/FlexLexer.h:112:7: error: redefinition of ‘class RCSSPComFlexLexer’ 
/usr/include/FlexLexer.h:112:7: error: previous definition of ‘class RCSSPComFlexLexer’ 

什麼可能是錯的?

+0

愚蠢的事情來檢查:標題衛兵。 –

回答

2

您的編譯錯誤似乎是由於某些頭文件包含兩次。您可能需要做出額外的文件,是不是包括後衛更小:

player_command_tok_guarded.hpp:

#ifndef PLAYER_COMMAND_TOK_GUARDED 
#define PLAYER_COMMAND_TOK_GUARDED 
#include "player_command_tok.hpp" 
#endif 

,使您的文件#include這個新文件代替。至於集成flex和野牛到你的CMake系統,嘗試這樣的事情:

# Find flex and bison. 
find_program(FLEX flex DOC "Path to the flex lexical analyser generator.") 
if(NOT ${FLEX}) 
    message(SEND_ERROR "Flex not found.") 
endif 
find_program(BISON bison DOC "Path to the bison parser generator.") 
if(NOT ${BISON}) 
    message(SEND_ERROR "Bison not found.") 
endif 

# Custom commands to invoke flex and bison. 
add_custom_command(OUTPUT lex.RCSSPCom.cc 
        COMMAND ${FLEX} --c++ player_command_tok.lpp 
        MAIN_DEPENDENCY player_command_tok.lpp 
        COMMENT "Generating lexer" 
        VERBATIM) 
add_custom_command(OUTPUT player_command_parser.tab.cpp player_command_parser.tab.hpp 
        COMMAND ${BISON} -d player_command_parser.ypp 
        MAIN_DEPENDENCY player_command_parser.ypp 
        COMMENT "Generating parser" 
        VERBATIM) 

並像往常一樣將文件添加到您的文件列表。