diff options
author | Gerald Combs <gerald@wireshark.org> | 2020-10-18 17:41:02 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2020-10-19 08:46:32 -0700 |
commit | 1a244f9de5b770e072acfe07c4c3c38dd4260420 (patch) | |
tree | fe9dcd7e50165df9d1b6c4857fbee776f0f3ffe2 /cmake | |
parent | 0a219bf8b90c2414bb42e367c2df02fe26286f18 (diff) |
CMake: Configure our .y files for different Bison/YACC flavors.
Bison 3.4 and later generate deprecation warnings for the "%pure-parser"
directive. As https://git.savannah.gnu.org/cgit/bison.git/tree/NEWS says,
----
** Deprecated features
The %pure-parser directive is deprecated in favor of '%define api.pure'
since Bison 2.3b (2008-05-27), but no warning was issued; there is one
now. Note that since Bison 2.7 you are strongly encouraged to use
'%define api.pure full' instead of '%define api.pure'.
----
Rename our .y files to .y.in, and modify FindYACC.cmake to detect newer
versions of Bison and configure our .y files with "%pure-parser" or
"%define api.pure" as needed. Squelches warnings from Bison in #16924.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/modules/FindYACC.cmake | 17 |
1 files changed, 16 insertions, 1 deletions
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) |