Jelajahi Sumber

Merge topic 'FindBISON-OPTIONS-keyword'

211cec0f20 FindBISON: Add new keyword OPTIONS

Acked-by: Kitware Robot <[email protected]>
Tested-by: buildbot <[email protected]>
Merge-request: !10129
Brad King 11 bulan lalu
induk
melakukan
d949e7980c
2 mengubah file dengan 55 tambahan dan 1 penghapusan
  1. 6 0
      Help/release/dev/FindBISON.rst
  2. 49 1
      Modules/FindBISON.cmake

+ 6 - 0
Help/release/dev/FindBISON.rst

@@ -0,0 +1,6 @@
+FindBISON
+---------
+
+* The :module:`FindBISON` module :command:`bison_target` command has a new
+  ``OPTIONS`` option to add Bison command-line options as a
+  :ref:`semicolon-separated list <CMake Language Lists>`.

+ 49 - 1
Modules/FindBISON.cmake

@@ -28,6 +28,7 @@ If ``bison`` is found, the module defines the macro:
   .. code-block:: cmake
   .. code-block:: cmake
 
 
     bison_target(<Name> <YaccInput> <CodeOutput>
     bison_target(<Name> <YaccInput> <CodeOutput>
+                 [OPTIONS <options>...]
                  [COMPILE_FLAGS <string>]
                  [COMPILE_FLAGS <string>]
                  [DEFINES_FILE <file>]
                  [DEFINES_FILE <file>]
                  [VERBOSE [<file>]]
                  [VERBOSE [<file>]]
@@ -45,9 +46,18 @@ the token list.
 
 
 The options are:
 The options are:
 
 
+``OPTIONS <options>...``
+  .. versionadded:: 3.32
+
+  A :ref:`semicolon-separated list <CMake Language Lists>` of options added to
+  the ``bison`` command line.
+
 ``COMPILE_FLAGS <string>``
 ``COMPILE_FLAGS <string>``
+  .. deprecated:: 3.32
+
   Space-separated bison options added to the ``bison`` command line.
   Space-separated bison options added to the ``bison`` command line.
   A :ref:`;-list <CMake Language Lists>` will not work.
   A :ref:`;-list <CMake Language Lists>` will not work.
+  This option is deprecated in favor of ``OPTIONS <options>...``.
 
 
 ``DEFINES_FILE <file>``
 ``DEFINES_FILE <file>``
   .. versionadded:: 3.4
   .. versionadded:: 3.4
@@ -85,9 +95,17 @@ The macro defines the following variables:
   All files generated by ``bison`` including the source, the header and the
   All files generated by ``bison`` including the source, the header and the
   report.
   report.
 
 
-``BISON_<Name>_COMPILE_FLAGS``
+``BISON_<Name>_OPTIONS``
+  .. versionadded:: 3.32
+
   Options used in the ``bison`` command line.
   Options used in the ``bison`` command line.
 
 
+``BISON_<Name>_COMPILE_FLAGS``
+  .. deprecated:: 3.32
+
+  Options used in the ``bison`` command line. This variable is deprecated in
+  favor of ``BISON_<Name>_OPTIONS`` variable.
+
 Examples
 Examples
 ^^^^^^^^
 ^^^^^^^^
 
 
@@ -97,6 +115,29 @@ Examples
   bison_target(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
   bison_target(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
                DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.h)
                DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.h)
   add_executable(Foo main.cpp ${BISON_MyParser_OUTPUTS})
   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.
+
+.. code-block:: cmake
+
+  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:
+
+.. code-block:: cmake
+
+  find_package(BISON)
+
+  if(BISON_FOUND)
+    bison_target(MyParser parser.y parser.cpp OPTIONS $<$<CONFIG:Debug>:-t>)
+  endif()
 #]=======================================================================]
 #]=======================================================================]
 
 
 find_program(BISON_EXECUTABLE NAMES bison win-bison win_bison DOC "path to the bison executable")
 find_program(BISON_EXECUTABLE NAMES bison win-bison win_bison DOC "path to the bison executable")
@@ -236,6 +277,7 @@ if(BISON_EXECUTABLE)
       REPORT_FILE
       REPORT_FILE
       )
       )
     set(BISON_TARGET_PARAM_MULTI_VALUE_KEYWORDS
     set(BISON_TARGET_PARAM_MULTI_VALUE_KEYWORDS
+      OPTIONS
       VERBOSE
       VERBOSE
       )
       )
     cmake_parse_arguments(
     cmake_parse_arguments(
@@ -254,6 +296,11 @@ if(BISON_EXECUTABLE)
     else()
     else()
 
 
       BISON_TARGET_option_extraopts("${BISON_TARGET_ARG_COMPILE_FLAGS}")
       BISON_TARGET_option_extraopts("${BISON_TARGET_ARG_COMPILE_FLAGS}")
+
+      if(BISON_TARGET_ARG_OPTIONS)
+        list(APPEND BISON_TARGET_cmdopt ${BISON_TARGET_ARG_OPTIONS})
+      endif()
+
       BISON_TARGET_option_defines("${BisonOutput}" "${BISON_TARGET_ARG_DEFINES_FILE}")
       BISON_TARGET_option_defines("${BisonOutput}" "${BISON_TARGET_ARG_DEFINES_FILE}")
       BISON_TARGET_option_report_file("${BisonOutput}" "${BISON_TARGET_ARG_REPORT_FILE}")
       BISON_TARGET_option_report_file("${BisonOutput}" "${BISON_TARGET_ARG_REPORT_FILE}")
       if(NOT "${BISON_TARGET_ARG_VERBOSE}" STREQUAL "")
       if(NOT "${BISON_TARGET_ARG_VERBOSE}" STREQUAL "")
@@ -297,6 +344,7 @@ if(BISON_EXECUTABLE)
       set(BISON_${Name}_DEFINED TRUE)
       set(BISON_${Name}_DEFINED TRUE)
       set(BISON_${Name}_INPUT ${_BisonInput})
       set(BISON_${Name}_INPUT ${_BisonInput})
       set(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs} ${BISON_TARGET_extraoutputs})
       set(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs} ${BISON_TARGET_extraoutputs})
+      set(BISON_${Name}_OPTIONS ${BISON_TARGET_cmdopt})
       set(BISON_${Name}_COMPILE_FLAGS ${BISON_TARGET_cmdopt})
       set(BISON_${Name}_COMPILE_FLAGS ${BISON_TARGET_cmdopt})
       set(BISON_${Name}_OUTPUT_SOURCE "${BisonOutput}")
       set(BISON_${Name}_OUTPUT_SOURCE "${BisonOutput}")
       set(BISON_${Name}_OUTPUT_HEADER "${BISON_TARGET_output_header}")
       set(BISON_${Name}_OUTPUT_HEADER "${BISON_TARGET_output_header}")