From 30710b8d32344a7a9acf944f97fc947fd491cd65 Mon Sep 17 00:00:00 2001 From: Chris Davies Date: Sat, 17 Oct 2015 17:50:00 +0100 Subject: [PATCH 1/4] FindFLEX: Use CMAKE_PARSE_ARGUMENTS to parse arguments --- Modules/FindFLEX.cmake | 59 ++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/Modules/FindFLEX.cmake b/Modules/FindFLEX.cmake index c837c52c7..8ede93b21 100644 --- a/Modules/FindFLEX.cmake +++ b/Modules/FindFLEX.cmake @@ -113,6 +113,8 @@ find_path(FLEX_INCLUDE_DIR FlexLexer.h mark_as_advanced(FL_LIBRARY FLEX_INCLUDE_DIR) +include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake) + set(FLEX_INCLUDE_DIRS ${FLEX_INCLUDE_DIR}) set(FLEX_LIBRARIES ${FL_LIBRARY}) @@ -145,31 +147,44 @@ if(FLEX_EXECUTABLE) #============================================================ # macro(FLEX_TARGET Name Input Output) + set(FLEX_EXECUTABLE_opts "") + + set(FLEX_TARGET_PARAM_OPTIONS) + set(FLEX_TARGET_PARAM_ONE_VALUE_KEYWORDS + COMPILE_FLAGS + ) + set(FLEX_TARGET_PARAM_MULTI_VALUE_KEYWORDS) + + cmake_parse_arguments( + FLEX_TARGET_ARG + "${FLEX_TARGET_PARAM_OPTIONS}" + "${FLEX_TARGET_PARAM_ONE_VALUE_KEYWORDS}" + "${FLEX_TARGET_MULTI_VALUE_KEYWORDS}" + ${ARGN} + ) + set(FLEX_TARGET_usage "FLEX_TARGET( [COMPILE_FLAGS ]") - if(${ARGC} GREATER 3) - if(${ARGC} EQUAL 5) - if("${ARGV3}" STREQUAL "COMPILE_FLAGS") - set(FLEX_EXECUTABLE_opts "${ARGV4}") - separate_arguments(FLEX_EXECUTABLE_opts) - else() - message(SEND_ERROR ${FLEX_TARGET_usage}) - endif() - else() - message(SEND_ERROR ${FLEX_TARGET_usage}) + + if(NOT "${FLEX_TARGET_ARG_UNPARSED_ARGUMENTS}" STREQUAL "") + message(SEND_ERROR ${FLEX_TARGET_usage}) + else() + if(NOT "${FLEX_TARGET_ARG_COMPILE_FLAGS}" STREQUAL "") + set(FLEX_EXECUTABLE_opts "${FLEX_TARGET_ARG_COMPILE_FLAGS}") + separate_arguments(FLEX_EXECUTABLE_opts) endif() + + add_custom_command(OUTPUT ${Output} + COMMAND ${FLEX_EXECUTABLE} + ARGS ${FLEX_EXECUTABLE_opts} -o${Output} ${Input} + DEPENDS ${Input} + COMMENT "[FLEX][${Name}] Building scanner with flex ${FLEX_VERSION}" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + + set(FLEX_${Name}_DEFINED TRUE) + set(FLEX_${Name}_OUTPUTS ${Output}) + set(FLEX_${Name}_INPUT ${Input}) + set(FLEX_${Name}_COMPILE_FLAGS ${FLEX_EXECUTABLE_opts}) endif() - - add_custom_command(OUTPUT ${Output} - COMMAND ${FLEX_EXECUTABLE} - ARGS ${FLEX_EXECUTABLE_opts} -o${Output} ${Input} - DEPENDS ${Input} - COMMENT "[FLEX][${Name}] Building scanner with flex ${FLEX_VERSION}" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - - set(FLEX_${Name}_DEFINED TRUE) - set(FLEX_${Name}_OUTPUTS ${Output}) - set(FLEX_${Name}_INPUT ${Input}) - set(FLEX_${Name}_COMPILE_FLAGS ${FLEX_EXECUTABLE_opts}) endmacro() #============================================================ From c26ff8a90b985f7189aa114b0bcac35b2f476b55 Mon Sep 17 00:00:00 2001 From: Chris Davies Date: Sat, 17 Oct 2015 17:50:00 +0100 Subject: [PATCH 2/4] FindFLEX: Fix typo in ADD_FLEX_BISON_DEPENDENCY errors --- Modules/FindFLEX.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/FindFLEX.cmake b/Modules/FindFLEX.cmake index 8ede93b21..55a9537f5 100644 --- a/Modules/FindFLEX.cmake +++ b/Modules/FindFLEX.cmake @@ -196,11 +196,11 @@ if(FLEX_EXECUTABLE) macro(ADD_FLEX_BISON_DEPENDENCY FlexTarget BisonTarget) if(NOT FLEX_${FlexTarget}_OUTPUTS) - message(SEND_ERROR "Flex target `${FlexTarget}' does not exists.") + message(SEND_ERROR "Flex target `${FlexTarget}' does not exist.") endif() if(NOT BISON_${BisonTarget}_OUTPUT_HEADER) - message(SEND_ERROR "Bison target `${BisonTarget}' does not exists.") + message(SEND_ERROR "Bison target `${BisonTarget}' does not exist.") endif() set_source_files_properties(${FLEX_${FlexTarget}_OUTPUTS} From db3d85059c2e48b1a4da99230098f63d04dd4e93 Mon Sep 17 00:00:00 2001 From: Chris Davies Date: Sat, 17 Oct 2015 17:51:51 +0100 Subject: [PATCH 3/4] 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() #============================================================ From 4565a2e1c2643fcd1b40f4a041564fc4ab60c17c Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 19 Oct 2015 13:19:11 -0400 Subject: [PATCH 4/4] Help: Add notes for topic 'FindFLEX-DEFINES_FILE' --- Help/release/dev/FindFLEX-DEFINES_FILE.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Help/release/dev/FindFLEX-DEFINES_FILE.rst diff --git a/Help/release/dev/FindFLEX-DEFINES_FILE.rst b/Help/release/dev/FindFLEX-DEFINES_FILE.rst new file mode 100644 index 000000000..95133aa4a --- /dev/null +++ b/Help/release/dev/FindFLEX-DEFINES_FILE.rst @@ -0,0 +1,6 @@ +FindFLEX-DEFINES_FILE +--------------------- + +* The :module:`FindFLEX` module ``FLEX_TARGET`` macro learned a + new ``DEFINES_FILE`` option to specify a custom output header + to be generated.