diff --git a/Modules/FindBISON.cmake b/Modules/FindBISON.cmake index 30d7c4f19..7d81276c8 100644 --- a/Modules/FindBISON.cmake +++ b/Modules/FindBISON.cmake @@ -22,6 +22,7 @@ # # BISON_TARGET( # [COMPILE_FLAGS ] +# [DEFINES_FILE ] # [VERBOSE ] # ) # @@ -35,6 +36,9 @@ # ``COMPILE_FLAGS `` # Specify flags to be added to the ``bison`` command line. # +# ``DEFINES_FILE `` +# Specify a non-default header ```` to be generated by ``bison``. +# # ``VERBOSE `` # Tell ``bison`` to write verbose descriptions of the grammar and # parser to the given ````. @@ -64,7 +68,8 @@ # .. code-block:: cmake # # find_package(BISON) -# 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) # add_executable(Foo main.cpp ${BISON_MyParser_OUTPUTS}) #============================================================================= @@ -140,6 +145,12 @@ if(BISON_EXECUTABLE) list(APPEND BISON_TARGET_cmdopt ${BISON_TARGET_extraopts}) endmacro() + # internal macro + macro(BISON_TARGET_option_defines Header) + set(BISON_TARGET_output_header "${Header}") + list(APPEND BISON_TARGET_cmdopt --defines=${BISON_TARGET_output_header}) + endmacro() + #============================================================ # BISON_TARGET (public macro) #============================================================ @@ -154,6 +165,7 @@ if(BISON_EXECUTABLE) set(BISON_TARGET_PARAM_ONE_VALUE_KEYWORDS VERBOSE COMPILE_FLAGS + DEFINES_FILE ) set(BISON_TARGET_PARAM_MULTI_VALUE_KEYWORDS) cmake_parse_arguments( @@ -173,14 +185,19 @@ if(BISON_EXECUTABLE) if(NOT "${BISON_TARGET_ARG_COMPILE_FLAGS}" STREQUAL "") BISON_TARGET_option_extraopts("${BISON_TARGET_ARG_COMPILE_FLAGS}") endif() + if(NOT "${BISON_TARGET_ARG_DEFINES_FILE}" STREQUAL "") + BISON_TARGET_option_defines("${BISON_TARGET_ARG_DEFINES_FILE}") + endif() - # Header's name generated by bison (see option -d) - list(APPEND BISON_TARGET_cmdopt "-d") - string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\2" _fileext "${BisonOutput}") - string(REPLACE "c" "h" _fileext ${_fileext}) - string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\1${_fileext}" - BISON_${Name}_OUTPUT_HEADER "${BisonOutput}") - list(APPEND BISON_TARGET_outputs "${BISON_${Name}_OUTPUT_HEADER}") + if("${BISON_TARGET_output_header}" STREQUAL "") + # Header's name generated by bison (see option -d) + list(APPEND BISON_TARGET_cmdopt "-d") + string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\2" _fileext "${BisonOutput}") + string(REPLACE "c" "h" _fileext ${_fileext}) + string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\1${_fileext}" + BISON_TARGET_output_header "${BisonOutput}") + endif() + list(APPEND BISON_TARGET_outputs "${BISON_TARGET_output_header}") add_custom_command(OUTPUT ${BISON_TARGET_outputs} ${BISON_TARGET_extraoutputs} @@ -196,6 +213,7 @@ if(BISON_EXECUTABLE) set(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs}) set(BISON_${Name}_COMPILE_FLAGS ${BISON_TARGET_cmdopt}) set(BISON_${Name}_OUTPUT_SOURCE "${BisonOutput}") + set(BISON_${Name}_OUTPUT_HEADER "${BISON_TARGET_output_header}") endif() endmacro()