diff --git a/cmake/modules/FindYACC.cmake b/cmake/modules/FindYACC.cmake index c96f87b389..c4e889f4ac 100644 --- a/cmake/modules/FindYACC.cmake +++ b/cmake/modules/FindYACC.cmake @@ -22,9 +22,24 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(YACC DEFAULT_MSG YACC_EXECUTABLE) MARK_AS_ADVANCED(YACC_EXECUTABLE) +# Specifying "%pure-parser" will fail with a deprecation warning in +# Bison 3.4 and later. Specifying "%define api.pure" doesn't work with +# Berkeley YACC and older versions of Bison (such as 2.3, which ships +# with macOS). If we're using Bison and it's new, configure our .y.in +# files with "%define api.pure", otherwise use "%pure-parser". +set(YACC_PURE_PARSER_DIRECTIVE "%pure-parser") +if(YACC_EXECUTABLE) + execute_process(COMMAND ${YACC_EXECUTABLE} -V OUTPUT_VARIABLE _yacc_full_version) + string(REGEX MATCH "[1-9]+\.[0-9]+" _yacc_major_minor ${_yacc_full_version}) + if (_yacc_full_version MATCHES "GNU Bison" AND _yacc_major_minor VERSION_GREATER "2.6") + set(YACC_PURE_PARSER_DIRECTIVE "%define api.pure") + endif() +endif() + MACRO(ADD_YACC_FILES _source _generated) FOREACH (_current_FILE ${ARGN}) - GET_FILENAME_COMPONENT(_in ${_current_FILE} ABSOLUTE) + configure_file(${_current_FILE}.in ${_current_FILE}) + GET_FILENAME_COMPONENT(_in ${CMAKE_CURRENT_BINARY_DIR}/${_current_FILE} ABSOLUTE) GET_FILENAME_COMPONENT(_basename ${_current_FILE} NAME_WE) SET(_out ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.c) diff --git a/epan/protobuf_lang.y b/epan/protobuf_lang.y.in similarity index 98% rename from epan/protobuf_lang.y rename to epan/protobuf_lang.y.in index 1e3fab939a..b031bfb6c5 100644 --- a/epan/protobuf_lang.y +++ b/epan/protobuf_lang.y.in @@ -1,11 +1,11 @@ /* * We want a reentrant parser. - * For now ignore the wdeprecated warning recommending - * %define api.pure - * https://code.wireshark.org/review/#/c/33771/ - * "This doesn't work with Berkeley YACC, and I'd *really* prefer not to require Bison." + * Berkeley YACC and older versions of Bison use "%pure-parser" and newer + * versions of Bison use "%define api.pure". + * As https://code.wireshark.org/review/#/c/33771/ + * says, "This doesn't work with Berkeley YACC, and I'd *really* prefer not to require Bison." */ -%pure-parser +${YACC_PURE_PARSER_DIRECTIVE} /* * We also want a reentrant scanner, so we have to pass the diff --git a/wiretap/ascend.y b/wiretap/ascend.y.in similarity index 98% rename from wiretap/ascend.y rename to wiretap/ascend.y.in index b19a0464b0..cbc9f91a7b 100644 --- a/wiretap/ascend.y +++ b/wiretap/ascend.y.in @@ -1,11 +1,11 @@ /* * We want a reentrant parser. - * For now ignore the wdeprecated warning recommending - * %define api.pure - * https://code.wireshark.org/review/#/c/33771/ - * "This doesn't work with Berkeley YACC, and I'd *really* prefer not to require Bison." + * Berkeley YACC and older versions of Bison use "%pure-parser" and newer + * versions of Bison use "%define api.pure". + * As https://code.wireshark.org/review/#/c/33771/ + * says, "This doesn't work with Berkeley YACC, and I'd *really* prefer not to require Bison." */ -%pure-parser +${YACC_PURE_PARSER_DIRECTIVE} /* * We also want a reentrant scanner, so we have to pass the