@@ -79,6 +79,17 @@ in various scenarios.
79
79
* `DEPENDS <depends>...` - Optional list of dependent files to regenerate the
80
80
output file .
81
81
82
+ * `VERBOSE` - This adds the `--verbose` (`-v` ) command -line option to
83
+ `bison` executable and will create extra output file
84
+ `<parser-output-filename>.output` containing verbose descriptions of the
85
+ grammar and parser. File will be created in the current binary directory .
86
+
87
+ * `REPORT_FILE <file>` - This adds the `--report-file=<file>` command -line
88
+ option to `bison` executable and will create verbose information report in the
89
+ specified `<file>`. This option must be used together with the `VERBOSE`
90
+ option . Relative file path is interpreted as being relative to the current
91
+ binary directory .
92
+
82
93
* `NO_DEFAULT_OPTIONS` - If specified, the `BISON_DEFAULT_OPTIONS` are not added
83
94
to the current `bison` invocation.
84
95
@@ -225,15 +236,113 @@ function(_bison_process_options options result)
225
236
return (PROPAGATE ${result} )
226
237
endfunction ()
227
238
239
+ # Process HEADER and HEADER_FILE options.
240
+ function (_bison_process_header_option )
241
+ if (NOT parsed_HEADER AND NOT parsed_HEADER_FILE )
242
+ return ()
243
+ endif ()
244
+
245
+ # Bison versions 3.8 and later introduced the --header=[FILE] (-H) option.
246
+ # For prior versions the --defines=[FILE] (-d) option can be used.
247
+ if (parsed_HEADER_FILE )
248
+ set (header ${parsed_HEADER_FILE} )
249
+ if (NOT IS_ABSOLUTE "${header} " )
250
+ set (header ${CMAKE_CURRENT_BINARY_DIR} /${header} )
251
+ endif ()
252
+
253
+ if (BISON_VERSION VERSION_LESS 3.8 )
254
+ list (APPEND options --defines=${header} )
255
+ else ()
256
+ list (APPEND options --header=${header} )
257
+ endif ()
258
+ else ()
259
+ if (BISON_VERSION VERSION_LESS 3.8 )
260
+ list (APPEND options -d )
261
+ else ()
262
+ list (APPEND options --header )
263
+ endif ()
264
+
265
+ # Produce default header path generated by bison (see option --header).
266
+ cmake_path (GET output EXTENSION LAST_ONLY extension )
267
+ string (REPLACE "c" "h" extension "${extension} " )
268
+ if (NOT extension )
269
+ set (extension ".h" )
270
+ endif ()
271
+ cmake_path (
272
+ REPLACE_EXTENSION
273
+ output
274
+ LAST_ONLY
275
+ "${extension} "
276
+ OUTPUT_VARIABLE header
277
+ )
278
+ # TODO: Add path if header is relative.
279
+ endif ()
280
+
281
+ list (APPEND outputs ${header} )
282
+
283
+ return (PROPAGATE outputs options )
284
+ endfunction ()
285
+
286
+ # Process the VERBOSE and REPORT_FILE options.
287
+ function (_bison_process_verbose_option )
288
+ if (NOT parsed_VERBOSE )
289
+ return ()
290
+ endif ()
291
+
292
+ list (APPEND options --verbose )
293
+
294
+ if (NOT parsed_REPORT_FILE )
295
+ cmake_path (GET output FILENAME reportFile )
296
+ cmake_path (GET output EXTENSION extension )
297
+
298
+ # Bison treats output files <parser-output-filename>.tab.<last-extension>
299
+ # differently. It removes the '.tab' part of the extension and creates
300
+ # <parser-output-filename>.output file. Elsewhere, it replaces only the
301
+ # last extension with '.output'.
302
+ if (extension MATCHES "\\ .tab\\ .([^.]+)$" )
303
+ string (
304
+ REGEX REPLACE
305
+ "\\ .tab\\ .${CMAKE_MATCH_1} $"
306
+ ".output"
307
+ reportFile
308
+ "${reportFile} "
309
+ )
310
+ else ()
311
+ cmake_path (REPLACE_EXTENSION reportFile LAST_ONLY "output" )
312
+ endif ()
313
+ else ()
314
+ set (reportFile ${parsed_REPORT_FILE} )
315
+ endif ()
316
+
317
+ if (NOT IS_ABSOLUTE "${reportFile} " )
318
+ set (reportFile ${CMAKE_CURRENT_BINARY_DIR} /${reportFile} )
319
+ endif ()
320
+
321
+ list (APPEND options --report-file=${reportFile} )
322
+
323
+ return (PROPAGATE options )
324
+ endfunction ()
325
+
228
326
macro (_bison_process )
229
327
if (parsed_UNPARSED_ARGUMENTS )
230
- message (FATAL_ERROR "Bad arguments: ${parsed_UNPARSED_ARGUMENTS} " )
328
+ message (FATAL_ERROR "Unrecognized arguments: ${parsed_UNPARSED_ARGUMENTS} " )
231
329
endif ()
232
330
233
331
if (parsed_KEYWORDS_MISSING_VALUES )
234
332
message (FATAL_ERROR "Missing values for: ${parsed_KEYWORDS_MISSING_VALUES} " )
235
333
endif ()
236
334
335
+ if (parsed_HEADER AND parsed_HEADER_FILE )
336
+ message (
337
+ FATAL_ERROR
338
+ "When 'HEADER_FILE' is specified, remove redundant 'HEADER' option."
339
+ )
340
+ endif ()
341
+
342
+ if (parsed_REPORT_FILE AND NOT parsed_VERBOSE )
343
+ message (FATAL_ERROR "'REPORT_FILE' option requires also 'VERBOSE' option." )
344
+ endif ()
345
+
237
346
set (input ${ARGV1} )
238
347
if (NOT IS_ABSOLUTE "${input} " )
239
348
set (input ${CMAKE_CURRENT_SOURCE_DIR} /${input} )
@@ -249,58 +358,8 @@ macro(_bison_process)
249
358
set (outputs ${output} )
250
359
251
360
_bison_process_options (parsed_OPTIONS options )
252
-
253
- if (parsed_HEADER OR parsed_HEADER_FILE )
254
- # Bison versions 3.8 and later introduced the --header=[FILE] (-H) option.
255
- # For prior versions the --defines=[FILE] (-d) option can be used.
256
- if (parsed_HEADER_FILE )
257
- set (header ${parsed_HEADER_FILE} )
258
- if (NOT IS_ABSOLUTE "${header} " )
259
- set (header ${CMAKE_CURRENT_BINARY_DIR} /${header} )
260
- endif ()
261
- if (BISON_VERSION VERSION_LESS 3.8 )
262
- list (APPEND options --defines=${header} )
263
- else ()
264
- list (APPEND options --header=${header} )
265
- endif ()
266
- else ()
267
- if (BISON_VERSION VERSION_LESS 3.8 )
268
- list (APPEND options -d )
269
- else ()
270
- list (APPEND options --header )
271
- endif ()
272
-
273
- # Produce default header path generated by bison (see option --header)
274
- cmake_path (GET output EXTENSION LAST_ONLY extension )
275
- string (REPLACE "c" "h" extension "${extension} " )
276
- if (NOT extension )
277
- set (extension "h" )
278
- endif ()
279
- cmake_path (
280
- REPLACE_EXTENSION
281
- output
282
- LAST_ONLY
283
- "${extension} "
284
- OUTPUT_VARIABLE header
285
- )
286
- # TODO: Add path if header is relative.
287
- endif ()
288
-
289
- list (APPEND outputs ${header} )
290
-
291
- if (parsed_VERBOSE )
292
- list (APPEND options --verbose )
293
- if (parsed_REPORT_FILE )
294
- if (NOT IS_ABSOLUTE "${parsed_REPORT_FILE} " )
295
- set (
296
- parsed_REPORT_FILE
297
- ${CMAKE_CURRENT_BINARY_DIR} /${parsed_REPORT_FILE}
298
- )
299
- endif ()
300
- list (APPEND options --report-file=${parsed_REPORT_FILE} )
301
- endif ()
302
- endif ()
303
- endif ()
361
+ _bison_process_header_option ()
362
+ _bison_process_verbose_option ()
304
363
305
364
# Assemble commands for add_custom_command() and execute_process().
306
365
set (commands "" )
@@ -356,7 +415,7 @@ function(bison)
356
415
PARSE_ARGV
357
416
3
358
417
parsed # prefix
359
- "NO_DEFAULT_OPTIONS;CODEGEN;VERBOSE; HEADER" # options
418
+ "NO_DEFAULT_OPTIONS;CODEGEN;HEADER;VERBOSE " # options
360
419
"HEADER_FILE;WORKING_DIRECTORY;REPORT_FILE" # one-value keywords
361
420
"OPTIONS;DEPENDS" # multi-value keywords
362
421
)
@@ -484,12 +543,12 @@ block(PROPAGATE BISON_VERSION _bisonVersionValid)
484
543
endif ()
485
544
endblock ()
486
545
487
- set (_bisonRequiredVars "" )
488
-
489
546
################################################################################
490
547
# Download and build the package.
491
548
################################################################################
492
549
550
+ set (_bisonRequiredVars "" )
551
+
493
552
if (
494
553
NOT CMAKE_SCRIPT_MODE_FILE
495
554
AND NOT BISON_DISABLE_DOWNLOAD
0 commit comments