|
|
|
|
@@ -5,120 +5,198 @@
|
|
|
|
|
FindBISON
|
|
|
|
|
---------
|
|
|
|
|
|
|
|
|
|
Find ``bison`` executable and provide a macro to generate custom build rules.
|
|
|
|
|
Finds the Bison command-line parser generator and provides a CMake command to
|
|
|
|
|
generate custom build rules for using Bison:
|
|
|
|
|
|
|
|
|
|
The module defines the following variables:
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
find_package(BISON [<version>] ...)
|
|
|
|
|
|
|
|
|
|
Bison is a parser generator that replaced earlier Yacc (Yet Another
|
|
|
|
|
Compiler-Compiler). On Unix-like systems, most common implementation is
|
|
|
|
|
GNU Bison. On Windows, this module looks for Windows-compatible Bison, if
|
|
|
|
|
installed.
|
|
|
|
|
|
|
|
|
|
Result Variables
|
|
|
|
|
^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
This module defines the following variables:
|
|
|
|
|
|
|
|
|
|
``BISON_FOUND``
|
|
|
|
|
True if the program was found.
|
|
|
|
|
|
|
|
|
|
``BISON_EXECUTABLE``
|
|
|
|
|
The path to the ``bison`` program.
|
|
|
|
|
Boolean indicating whether (the requested version of) Bison is found.
|
|
|
|
|
|
|
|
|
|
``BISON_VERSION``
|
|
|
|
|
The version of ``bison``.
|
|
|
|
|
The version of Bison found.
|
|
|
|
|
|
|
|
|
|
The minimum required version of ``bison`` can be specified using the
|
|
|
|
|
standard CMake syntax, e.g. :command:`find_package(BISON 2.1.3)`.
|
|
|
|
|
Cache Variables
|
|
|
|
|
^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
If ``bison`` is found, the module defines the macro:
|
|
|
|
|
The following cache variables may also be set:
|
|
|
|
|
|
|
|
|
|
``BISON_EXECUTABLE``
|
|
|
|
|
The path to the ``bison`` command-line program.
|
|
|
|
|
|
|
|
|
|
Commands
|
|
|
|
|
^^^^^^^^
|
|
|
|
|
|
|
|
|
|
This module provides the following command if ``bison`` is found:
|
|
|
|
|
|
|
|
|
|
.. command:: bison_target
|
|
|
|
|
|
|
|
|
|
Creates a custom build rule to generate a parser file from a Yacc file using
|
|
|
|
|
Bison:
|
|
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
bison_target(<Name> <YaccInput> <CodeOutput>
|
|
|
|
|
[OPTIONS <options>...]
|
|
|
|
|
[COMPILE_FLAGS <string>]
|
|
|
|
|
[DEFINES_FILE <file>]
|
|
|
|
|
[VERBOSE [<file>]]
|
|
|
|
|
[REPORT_FILE <file>]
|
|
|
|
|
)
|
|
|
|
|
bison_target(
|
|
|
|
|
<name>
|
|
|
|
|
<input-yacc-file>
|
|
|
|
|
<output-parser-file>
|
|
|
|
|
[DEFINES_FILE <header>]
|
|
|
|
|
[VERBOSE [<file>]] # The [<file>] argument is deprecated
|
|
|
|
|
[REPORT_FILE <file>]
|
|
|
|
|
[OPTIONS <options>...]
|
|
|
|
|
[COMPILE_FLAGS <string>] # Deprecated
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
.. versionchanged:: 3.14
|
|
|
|
|
When policy :policy:`CMP0088` is set to ``NEW``, ``bison`` runs in the
|
|
|
|
|
:variable:`CMAKE_CURRENT_BINARY_DIR` directory.
|
|
|
|
|
|
|
|
|
|
.. versionchanged:: 3.14
|
|
|
|
|
When :policy:`CMP0088` is set to ``NEW``, ``bison`` runs in the
|
|
|
|
|
:variable:`CMAKE_CURRENT_BINARY_DIR` directory.
|
|
|
|
|
``<name>``
|
|
|
|
|
String used as an identifier for this command invocation.
|
|
|
|
|
|
|
|
|
|
The options are:
|
|
|
|
|
``<input-yacc-file>``
|
|
|
|
|
The path to an input Yacc source file (``.y``). If given as a relative
|
|
|
|
|
path, it will be interpreted relative to the current source directory
|
|
|
|
|
(:variable:`CMAKE_CURRENT_SOURCE_DIR`).
|
|
|
|
|
|
|
|
|
|
``OPTIONS <options>...``
|
|
|
|
|
.. versionadded:: 4.0
|
|
|
|
|
``<output-parser-file>``
|
|
|
|
|
The path of the output parser file to be generated by Bison. If given as a
|
|
|
|
|
relative path, it will be interpreted relative to the current Bison working
|
|
|
|
|
directory.
|
|
|
|
|
|
|
|
|
|
A :ref:`semicolon-separated list <CMake Language Lists>` of options added to
|
|
|
|
|
the ``bison`` command line.
|
|
|
|
|
``DEFINES_FILE <header>``
|
|
|
|
|
.. versionadded:: 3.4
|
|
|
|
|
|
|
|
|
|
``COMPILE_FLAGS <string>``
|
|
|
|
|
.. deprecated:: 4.0
|
|
|
|
|
By default, Bison can generate a header file containing the list of tokens.
|
|
|
|
|
This option allows specifying a custom ``<header>`` file to be generated by
|
|
|
|
|
Bison. If given as a relative path, it will be interpreted relative to the
|
|
|
|
|
current Bison working directory.
|
|
|
|
|
|
|
|
|
|
Space-separated bison options added to the ``bison`` command line.
|
|
|
|
|
A :ref:`;-list <CMake Language Lists>` will not work.
|
|
|
|
|
This option is deprecated in favor of ``OPTIONS <options>...``.
|
|
|
|
|
``VERBOSE [<file>]``
|
|
|
|
|
Enables generation of a verbose grammar and parser report. By default, the
|
|
|
|
|
report file is created in the current Bison working directory and named
|
|
|
|
|
``<output-parser-filename>.output``.
|
|
|
|
|
|
|
|
|
|
``DEFINES_FILE <file>``
|
|
|
|
|
.. versionadded:: 3.4
|
|
|
|
|
``<file>``
|
|
|
|
|
.. deprecated:: 3.7
|
|
|
|
|
Use ``VERBOSE REPORT_FILE <file>``.
|
|
|
|
|
|
|
|
|
|
Specify a non-default header ``<file>`` to be generated by ``bison``.
|
|
|
|
|
Specifies the path to which the report file should be copied. This
|
|
|
|
|
argument is retained for backward compatibility and only works when the
|
|
|
|
|
``<output-parser-file>`` is specified as an absolute path.
|
|
|
|
|
|
|
|
|
|
``VERBOSE [<file>]``
|
|
|
|
|
Tell ``bison`` to write a report file of the grammar and parser.
|
|
|
|
|
``REPORT_FILE <file>``
|
|
|
|
|
.. versionadded:: 3.7
|
|
|
|
|
|
|
|
|
|
.. deprecated:: 3.7
|
|
|
|
|
If ``<file>`` is given, it specifies path the report file is copied to.
|
|
|
|
|
``[<file>]`` is left for backward compatibility of this module.
|
|
|
|
|
Use ``VERBOSE REPORT_FILE <file>``.
|
|
|
|
|
Used in combination with ``VERBOSE`` to specify a custom path for the report
|
|
|
|
|
output ``<file>``, overriding the default location. If given as a relative
|
|
|
|
|
path, it will be interpreted relative to the current Bison working
|
|
|
|
|
directory.
|
|
|
|
|
|
|
|
|
|
``REPORT_FILE <file>``
|
|
|
|
|
.. versionadded:: 3.7
|
|
|
|
|
``OPTIONS <options>...``
|
|
|
|
|
.. versionadded:: 4.0
|
|
|
|
|
|
|
|
|
|
Specify a non-default report ``<file>``, if generated.
|
|
|
|
|
A :ref:`semicolon-separated list <CMake Language Lists>` of extra options
|
|
|
|
|
added to the ``bison`` command line.
|
|
|
|
|
|
|
|
|
|
The macro defines the following variables:
|
|
|
|
|
``COMPILE_FLAGS <string>``
|
|
|
|
|
.. deprecated:: 4.0
|
|
|
|
|
Superseded by ``OPTIONS <options>...``.
|
|
|
|
|
|
|
|
|
|
``BISON_<Name>_DEFINED``
|
|
|
|
|
True if the macro ran successfully.
|
|
|
|
|
A string of space-separated extra options added to the ``bison`` command
|
|
|
|
|
line. A :ref:`semicolon-separated list <CMake Language Lists>` will not
|
|
|
|
|
work.
|
|
|
|
|
|
|
|
|
|
``BISON_<Name>_INPUT``
|
|
|
|
|
The input source file, an alias for ``<YaccInput>``.
|
|
|
|
|
---------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
``BISON_<Name>_OUTPUT_SOURCE``
|
|
|
|
|
The source file generated by ``bison``.
|
|
|
|
|
This command also defines the following variables:
|
|
|
|
|
|
|
|
|
|
``BISON_<Name>_OUTPUT_HEADER``
|
|
|
|
|
The header file generated by ``bison``.
|
|
|
|
|
``BISON_<name>_DEFINED``
|
|
|
|
|
Boolean indicating whether this command was successfully invoked.
|
|
|
|
|
|
|
|
|
|
``BISON_<Name>_OUTPUTS``
|
|
|
|
|
All files generated by ``bison`` including the source, the header and the
|
|
|
|
|
report.
|
|
|
|
|
``BISON_<name>_INPUT``
|
|
|
|
|
The input source file, an alias for ``<input-yacc-file>``.
|
|
|
|
|
|
|
|
|
|
``BISON_<Name>_OPTIONS``
|
|
|
|
|
.. versionadded:: 4.0
|
|
|
|
|
``BISON_<name>_OUTPUT_SOURCE``
|
|
|
|
|
The output parser file generated by ``bison``.
|
|
|
|
|
|
|
|
|
|
Options used in the ``bison`` command line.
|
|
|
|
|
``BISON_<name>_OUTPUT_HEADER``
|
|
|
|
|
The header file generated by ``bison``, if any.
|
|
|
|
|
|
|
|
|
|
``BISON_<Name>_COMPILE_FLAGS``
|
|
|
|
|
.. deprecated:: 4.0
|
|
|
|
|
``BISON_<name>_OUTPUTS``
|
|
|
|
|
A list of files generated by ``bison``, including the output parser file,
|
|
|
|
|
header file, and report file.
|
|
|
|
|
|
|
|
|
|
Options used in the ``bison`` command line. This variable is deprecated in
|
|
|
|
|
favor of ``BISON_<Name>_OPTIONS`` variable.
|
|
|
|
|
``BISON_<name>_OPTIONS``
|
|
|
|
|
.. versionadded:: 4.0
|
|
|
|
|
|
|
|
|
|
A list of command-line options used for the ``bison`` command.
|
|
|
|
|
|
|
|
|
|
``BISON_<name>_COMPILE_FLAGS``
|
|
|
|
|
.. deprecated:: 4.0
|
|
|
|
|
Superseded by ``BISON_<name>_OPTIONS`` variable with the same value.
|
|
|
|
|
|
|
|
|
|
A list of command-line options used for the ``bison`` command.
|
|
|
|
|
|
|
|
|
|
Examples
|
|
|
|
|
^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Examples: Finding Bison
|
|
|
|
|
"""""""""""""""""""""""
|
|
|
|
|
|
|
|
|
|
Finding Bison:
|
|
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
find_package(BISON)
|
|
|
|
|
bison_target(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
|
|
|
|
|
DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.h)
|
|
|
|
|
|
|
|
|
|
Finding Bison with a minimum required version:
|
|
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
find_package(BISON 2.1.3)
|
|
|
|
|
|
|
|
|
|
Finding Bison and making it required (if Bison is not found, processing stops
|
|
|
|
|
with an error message):
|
|
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
find_package(BISON 2.1.3 REQUIRED)
|
|
|
|
|
|
|
|
|
|
Example: Generating Parser
|
|
|
|
|
""""""""""""""""""""""""""
|
|
|
|
|
|
|
|
|
|
Finding Bison and adding input Yacc source file ``parser.y`` to be processed by
|
|
|
|
|
Bison into ``parser.cpp`` source file with header ``parser.h`` at build phase:
|
|
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
find_package(BISON)
|
|
|
|
|
|
|
|
|
|
if(BISON_FOUND)
|
|
|
|
|
bison_target(MyParser parser.y parser.cpp DEFINES_FILE parser.h)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
add_executable(Foo main.cpp ${BISON_MyParser_OUTPUTS})
|
|
|
|
|
|
|
|
|
|
Examples: Command-line Options
|
|
|
|
|
""""""""""""""""""""""""""""""
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
as a list. For example, adding the ``-Wall`` option to report all warnings, and
|
|
|
|
|
``--no-lines`` (``-l``) to not generate ``#line`` directives:
|
|
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
@@ -128,8 +206,9 @@ as a list. For example, adding the ``-Wall`` option to report all warnings, and
|
|
|
|
|
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:
|
|
|
|
|
:manual:`Generator expressions <cmake-generator-expressions(7)>` can be used in
|
|
|
|
|
the ``OPTIONS <options>...`` argument. For example, to add the ``--debug``
|
|
|
|
|
(``-t``) option only for the ``Debug`` build type:
|
|
|
|
|
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
@@ -138,6 +217,11 @@ add the ``--debug`` (``-t``) option only for the ``Debug`` build type:
|
|
|
|
|
if(BISON_FOUND)
|
|
|
|
|
bison_target(MyParser parser.y parser.cpp OPTIONS $<$<CONFIG:Debug>:-t>)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
See Also
|
|
|
|
|
^^^^^^^^
|
|
|
|
|
|
|
|
|
|
* The :module:`FindFLEX` module to find Flex scanner generator.
|
|
|
|
|
#]=======================================================================]
|
|
|
|
|
|
|
|
|
|
find_program(BISON_EXECUTABLE NAMES bison win-bison win_bison DOC "path to the bison executable")
|
|
|
|
|
@@ -261,7 +345,7 @@ if(BISON_EXECUTABLE)
|
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
|
|
#============================================================
|
|
|
|
|
# BISON_TARGET (public macro)
|
|
|
|
|
# bison_target() public macro
|
|
|
|
|
#============================================================
|
|
|
|
|
#
|
|
|
|
|
macro(BISON_TARGET Name BisonInput BisonOutput)
|
|
|
|
|
|