FindBISON

Find bison executable and provide a macro to generate custom build rules.

The module defines the following variables:

BISON_EXECUTABLE
path to the bison program
BISON_VERSION
version of bison
BISON_FOUND
true if the program was found

The minimum required version of bison can be specified using the standard CMake syntax, e.g. find_package(BISON 2.1.3).

If bison is found, the module defines the macro:

BISON_TARGET(<Name> <YaccInput> <CodeOutput>
             [COMPILE_FLAGS <flags>]
             [DEFINES_FILE <file>]
             [VERBOSE <file>]
             )

which will create a custom rule to generate a parser. <YaccInput> is the path to a yacc file. <CodeOutput> is the name of the source file generated by bison. A header file is also be generated, and contains the token list.

The options are:

COMPILE_FLAGS <flags>
Specify flags to be added to the bison command line.
DEFINES_FILE <file>
Specify a non-default header <file> to be generated by bison.
VERBOSE <file>
Tell bison to write verbose descriptions of the grammar and parser to the given <file>.

The macro defines the following variables:

BISON_<Name>_DEFINED
true is the macro ran successfully
BISON_<Name>_INPUT
The input source file, an alias for <YaccInput>
BISON_<Name>_OUTPUT_SOURCE
The source file generated by bison
BISON_<Name>_OUTPUT_HEADER
The header file generated by bison
BISON_<Name>_OUTPUTS
The sources files generated by bison
BISON_<Name>_COMPILE_FLAGS
Options used in the bison command line

Example usage:

find_package(BISON)
BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
             DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.h)
add_executable(Foo main.cpp ${BISON_MyParser_OUTPUTS})

© 2000–2019 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.
https://cmake.org/cmake/help/v3.5/module/FindBISON.html