From db3d85059c2e48b1a4da99230098f63d04dd4e93 Mon Sep 17 00:00:00 2001 From: Chris Davies Date: Sat, 17 Oct 2015 17:51:51 +0100 Subject: [PATCH] FindFLEX: Add a DEFINES_FILE option to specify flex-generated header (#15781) --- Modules/FindFLEX.cmake | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Modules/FindFLEX.cmake b/Modules/FindFLEX.cmake index 55a9537f5..ca6649359 100644 --- a/Modules/FindFLEX.cmake +++ b/Modules/FindFLEX.cmake @@ -27,13 +27,17 @@ # # :: # -# FLEX_TARGET(Name FlexInput FlexOutput [COMPILE_FLAGS ]) +# FLEX_TARGET(Name FlexInput FlexOutput +# [COMPILE_FLAGS ] +# [DEFINES_FILE ] +# ) # # which creates a custom command to generate the file from # the file. If COMPILE_FLAGS option is specified, the next -# parameter is added to the flex command line. Name is an alias used to -# get details of this custom command. Indeed the macro defines the -# following variables: +# parameter is added to the flex command line. If flex is configured to +# output a header file, the DEFINES_FILE option may be used to specify its +# name. Name is an alias used to get details of this custom command. +# Indeed the macro defines the following variables: # # :: # @@ -41,6 +45,7 @@ # FLEX_${Name}_OUTPUTS - the source file generated by the custom rule, an # alias for FlexOutput # FLEX_${Name}_INPUT - the flex source file, an alias for ${FlexInput} +# FLEX_${Name}_OUTPUT_HEADER - the header flex output, if any. # # # @@ -147,11 +152,13 @@ if(FLEX_EXECUTABLE) #============================================================ # macro(FLEX_TARGET Name Input Output) + set(FLEX_TARGET_outputs "${Output}") set(FLEX_EXECUTABLE_opts "") set(FLEX_TARGET_PARAM_OPTIONS) set(FLEX_TARGET_PARAM_ONE_VALUE_KEYWORDS COMPILE_FLAGS + DEFINES_FILE ) set(FLEX_TARGET_PARAM_MULTI_VALUE_KEYWORDS) @@ -163,7 +170,7 @@ if(FLEX_EXECUTABLE) ${ARGN} ) - set(FLEX_TARGET_usage "FLEX_TARGET( [COMPILE_FLAGS ]") + set(FLEX_TARGET_usage "FLEX_TARGET( [COMPILE_FLAGS ] [DEFINES_FILE ]") if(NOT "${FLEX_TARGET_ARG_UNPARSED_ARGUMENTS}" STREQUAL "") message(SEND_ERROR ${FLEX_TARGET_usage}) @@ -172,8 +179,12 @@ if(FLEX_EXECUTABLE) set(FLEX_EXECUTABLE_opts "${FLEX_TARGET_ARG_COMPILE_FLAGS}") separate_arguments(FLEX_EXECUTABLE_opts) endif() + if(NOT "${FLEX_TARGET_ARG_DEFINES_FILE}" STREQUAL "") + list(APPEND FLEX_TARGET_outputs "${FLEX_TARGET_ARG_DEFINES_FILE}") + list(APPEND FLEX_EXECUTABLE_opts --header-file=${FLEX_TARGET_ARG_DEFINES_FILE}) + endif() - add_custom_command(OUTPUT ${Output} + add_custom_command(OUTPUT ${FLEX_TARGET_outputs} COMMAND ${FLEX_EXECUTABLE} ARGS ${FLEX_EXECUTABLE_opts} -o${Output} ${Input} DEPENDS ${Input} @@ -184,6 +195,11 @@ if(FLEX_EXECUTABLE) set(FLEX_${Name}_OUTPUTS ${Output}) set(FLEX_${Name}_INPUT ${Input}) set(FLEX_${Name}_COMPILE_FLAGS ${FLEX_EXECUTABLE_opts}) + if("${FLEX_TARGET_ARG_DEFINES_FILE}" STREQUAL "") + set(FLEX_${Name}_OUTPUT_HEADER "") + else() + set(FLEX_${Name}_OUTPUT_HEADER ${FLEX_TARGET_ARG_DEFINES_FILE}) + endif() endif() endmacro() #============================================================