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. diff --git a/Modules/FindFLEX.cmake b/Modules/FindFLEX.cmake index c837c52c7..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. # # # @@ -113,6 +118,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 +152,55 @@ if(FLEX_EXECUTABLE) #============================================================ # macro(FLEX_TARGET Name Input Output) - 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() + 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) + + 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 ] [DEFINES_FILE ]") + + 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() + 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 ${FLEX_TARGET_outputs} + 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}) + if("${FLEX_TARGET_ARG_DEFINES_FILE}" STREQUAL "") + set(FLEX_${Name}_OUTPUT_HEADER "") else() - message(SEND_ERROR ${FLEX_TARGET_usage}) + set(FLEX_${Name}_OUTPUT_HEADER ${FLEX_TARGET_ARG_DEFINES_FILE}) endif() 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() #============================================================ @@ -181,11 +212,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}