FindBISON¶
Find bison
executable and provide a macro to generate custom build rules.
The module defines the following variables:
BISON_FOUND
True if the program was found.
BISON_EXECUTABLE
The path to the
bison
program.BISON_VERSION
The version of
bison
.
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¶
bison_target(<Name> <YaccInput> <CodeOutput> [OPTIONS <options>...] [COMPILE_FLAGS <string>] [DEFINES_FILE <file>] [VERBOSE [<file>]] [REPORT_FILE <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 can also be generated, and contains
the token list.
Changed in version 3.14: When CMP0088
is set to NEW
, bison
runs in the
CMAKE_CURRENT_BINARY_DIR
directory.
The options are:
OPTIONS <options>...
Added in version 4.0.
A semicolon-separated list of options added to the
bison
command line.COMPILE_FLAGS <string>
Deprecated since version 4.0.
Space-separated bison options added to the
bison
command line. A ;-list will not work. This option is deprecated in favor ofOPTIONS <options>...
.DEFINES_FILE <file>
Added in version 3.4.
Specify a non-default header
<file>
to be generated bybison
.VERBOSE [<file>]
Tell
bison
to write a report file of the grammar and parser.Deprecated since version 3.7: If
<file>
is given, it specifies path the report file is copied to.[<file>]
is left for backward compatibility of this module. UseVERBOSE REPORT_FILE <file>
.REPORT_FILE <file>
Added in version 3.7.
Specify a non-default report
<file>
, if generated.
The macro defines the following variables:
BISON_<Name>_DEFINED
True if 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
All files generated by
bison
including the source, the header and the report.BISON_<Name>_OPTIONS
Added in version 4.0.
Options used in the
bison
command line.BISON_<Name>_COMPILE_FLAGS
Deprecated since version 4.0.
Options used in the
bison
command line. This variable is deprecated in favor ofBISON_<Name>_OPTIONS
variable.
Examples¶
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})
Adding additional command-line options to the bison
executable can be passed
as a list. For example, adding the -Wall
option to report all warnings, and
--no-lines
(-l
) to not generate #line
directives.
find_package(BISON)
if(BISON_FOUND)
bison_target(MyParser parser.y parser.cpp OPTIONS -Wall --no-lines)
endif()
Generator expressions can be used in OPTIONS <options...
. For example, to
add the --debug
(-t
) option only for the Debug
build type:
find_package(BISON)
if(BISON_FOUND)
bison_target(MyParser parser.y parser.cpp OPTIONS $<$<CONFIG:Debug>:-t>)
endif()