From ad2497aa054e40afa88b5288a59f2e6ad3a765c0 Mon Sep 17 00:00:00 2001 From: Eon Jeong Date: Sat, 16 Jul 2016 00:54:56 +0900 Subject: [PATCH] FindBISON: Change usage of [VERBOSE ] to [VERBOSE []] --- Modules/FindBISON.cmake | 71 ++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/Modules/FindBISON.cmake b/Modules/FindBISON.cmake index 69293f5f3..f1df16db6 100644 --- a/Modules/FindBISON.cmake +++ b/Modules/FindBISON.cmake @@ -23,7 +23,7 @@ # BISON_TARGET( # [COMPILE_FLAGS ] # [DEFINES_FILE ] -# [VERBOSE ] +# [VERBOSE []] # ) # # which will create a custom rule to generate a parser. ```` is @@ -39,9 +39,9 @@ # ``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 ````. +# ``VERBOSE []`` +# Tell ``bison`` to write a report file of the grammar and parser. +# If given, the report file is copied to ````. # # The macro defines the following variables: # @@ -58,7 +58,7 @@ # The header file generated by bison # # ``BISON__OUTPUTS`` -# The sources files generated by bison +# All files generated by bison including the source, the header and the report # # ``BISON__COMPILE_FLAGS`` # Options used in the ``bison`` command line @@ -120,24 +120,34 @@ if(BISON_EXECUTABLE) endif() # internal macro - macro(BISON_TARGET_option_verbose Name BisonOutput filename) - list(APPEND BISON_TARGET_cmdopt "--verbose") + macro(BISON_TARGET_set_verbose_file BisonOutput) get_filename_component(BISON_TARGET_output_path "${BisonOutput}" PATH) get_filename_component(BISON_TARGET_output_name "${BisonOutput}" NAME_WE) - add_custom_command(OUTPUT ${filename} - COMMAND ${CMAKE_COMMAND} -E copy - "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output" - "${filename}" - VERBATIM - DEPENDS - "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output" - COMMENT "[BISON][${Name}] Copying bison verbose table to ${filename}" - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) - set(BISON_${Name}_VERBOSE_FILE ${filename}) - list(APPEND BISON_TARGET_extraoutputs + set(BISON_TARGET_verbose_file "${BISON_TARGET_output_path}/${BISON_TARGET_output_name}.output") endmacro() + # internal macro + macro(BISON_TARGET_option_verbose Name BisonOutput filename) + list(APPEND BISON_TARGET_cmdopt "--verbose") + list(APPEND BISON_TARGET_extraoutputs + "${BISON_TARGET_verbose_file}") + if (NOT "${filename}" STREQUAL "") + add_custom_command(OUTPUT ${filename} + COMMAND ${CMAKE_COMMAND} -E copy + "${BISON_TARGET_verbose_file}" + "${filename}" + VERBATIM + DEPENDS + "${BISON_TARGET_verbose_file}" + COMMENT "[BISON][${Name}] Copying bison verbose table to ${filename}" + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + set(BISON_${Name}_VERBOSE_FILE ${filename}) + list(APPEND BISON_TARGET_extraoutputs + "${filename}") + endif() + endmacro() + # internal macro macro(BISON_TARGET_option_extraopts Options) set(BISON_TARGET_extraopts "${Options}") @@ -159,15 +169,19 @@ if(BISON_EXECUTABLE) set(BISON_TARGET_output_header "") set(BISON_TARGET_cmdopt "") set(BISON_TARGET_outputs "${BisonOutput}") + set(BISON_TARGET_extraoutputs "") + BISON_TARGET_set_verbose_file("${BisonOutput}") # Parsing parameters - set(BISON_TARGET_PARAM_OPTIONS) + set(BISON_TARGET_PARAM_OPTIONS + ) set(BISON_TARGET_PARAM_ONE_VALUE_KEYWORDS - VERBOSE COMPILE_FLAGS DEFINES_FILE ) - set(BISON_TARGET_PARAM_MULTI_VALUE_KEYWORDS) + set(BISON_TARGET_PARAM_MULTI_VALUE_KEYWORDS + VERBOSE + ) cmake_parse_arguments( BISON_TARGET_ARG "${BISON_TARGET_PARAM_OPTIONS}" @@ -178,9 +192,20 @@ if(BISON_EXECUTABLE) if(NOT "${BISON_TARGET_ARG_UNPARSED_ARGUMENTS}" STREQUAL "") message(SEND_ERROR "Usage") + elseif("${BISON_TARGET_ARG_VERBOSE}" MATCHES ";") + # [VERBOSE [] hack: is non-multi value by usage + message(SEND_ERROR "Usage") else() if(NOT "${BISON_TARGET_ARG_VERBOSE}" STREQUAL "") BISON_TARGET_option_verbose(${Name} ${BisonOutput} "${BISON_TARGET_ARG_VERBOSE}") + else() + # [VERBOSE []] is used with no argument or is not used + set(BISON_TARGET_args "${ARGN}") + list(FIND BISON_TARGET_args "VERBOSE" BISON_TARGET_args_indexof_verbose) + if(${BISON_TARGET_args_indexof_verbose} GREATER -1) + # VERBOSE is used without + BISON_TARGET_option_verbose(${Name} ${BisonOutput} "") + endif() endif() if(NOT "${BISON_TARGET_ARG_COMPILE_FLAGS}" STREQUAL "") BISON_TARGET_option_extraopts("${BISON_TARGET_ARG_COMPILE_FLAGS}") @@ -200,7 +225,7 @@ if(BISON_EXECUTABLE) list(APPEND BISON_TARGET_outputs "${BISON_TARGET_output_header}") add_custom_command(OUTPUT ${BISON_TARGET_outputs} - ${BISON_TARGET_extraoutputs} + ${BISON_TARGET_verbose_file} COMMAND ${BISON_EXECUTABLE} ${BISON_TARGET_cmdopt} -o ${BisonOutput} ${BisonInput} VERBATIM DEPENDS ${BisonInput} @@ -210,7 +235,7 @@ if(BISON_EXECUTABLE) # define target variables set(BISON_${Name}_DEFINED TRUE) set(BISON_${Name}_INPUT ${BisonInput}) - set(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs}) + set(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs} ${BISON_TARGET_extraoutputs}) set(BISON_${Name}_COMPILE_FLAGS ${BISON_TARGET_cmdopt}) set(BISON_${Name}_OUTPUT_SOURCE "${BisonOutput}") set(BISON_${Name}_OUTPUT_HEADER "${BISON_TARGET_output_header}")