Search code examples
c++cmakebisonflex-lexer

CMake not invoking FLEX/BISON


I have the following CMake file, which is part of a bigger project (and as such in its folder and imported by upper levels using add_subdirectory(...)

find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)

include_directories(${PROJECT_SOURCE_DIR}/include/Parser)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

bison_target(XPathParser
        XPath.yy
        ${CMAKE_CURRENT_BINARY_DIR}/XPathParser.cpp
        DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/XPathParser.h)

flex_target(XPathScanner
        XPath.flex
        ${CMAKE_CURRENT_BINARY_DIR}/XPathScanner.cpp
        COMPILE_FLAGS "-Cm -B -L --c++ --nounistd")

add_flex_bison_dependency(XPathScanner XPathParser)

set_source_files_properties(${BISON_XPathParser_OUTPUTS}
                            ${FLEX_XPathScanner_OUTPUTS}
                            PROPERTIES
                            COMPILE_FLAGS -Wno-sign-compare
                            COMPILE_FLAGS -Wno-effc++)

add_library(xpath OBJECT
        ${BISON_Parser_OUTPUTS}
        ${FLEX_Lexer_OUTPUTS}
        ${CMAKE_CURRENT_LIST_DIR}/XPathParserDriver.cpp)

In my knowledge, this CMake should execute FLEX and BISON, that in turn would generate the C++ files, before the actual C++ compiler invocation.

For some reason beyond my understanding, this is not true. I tried to clear CMake cache and rerun it from scratch; still, there is no sign of FLEX nor BISON within the CMake generated files.

Of course, CMake finds both FLEX and BISON and properly sets the bison_target and flex_target macros (I tested it by messing with them adding random values: CMake gets angry and throws me an error).

Any clue on what is going on and what am I missing?


Solution

  • In add_library, you add BISON_Parser_OUTPUTS and FLEX_Lexer_OUTPUTS dependencies. Instead, it should be BISON_XPathParser_OUTPUTS and FLEX_XPathScanner_OUTPUTS respectively (since you gave them such names).