Merge topic 'FindFLEX-DEFINES_FILE'
4565a2e1
Help: Add notes for topic 'FindFLEX-DEFINES_FILE'db3d8505
FindFLEX: Add a DEFINES_FILE option to specify flex-generated header (#15781)c26ff8a9
FindFLEX: Fix typo in ADD_FLEX_BISON_DEPENDENCY errors30710b8d
FindFLEX: Use CMAKE_PARSE_ARGUMENTS to parse arguments
This commit is contained in:
commit
5ec8064b76
|
@ -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.
|
|
@ -27,13 +27,17 @@
|
||||||
#
|
#
|
||||||
# ::
|
# ::
|
||||||
#
|
#
|
||||||
# FLEX_TARGET(Name FlexInput FlexOutput [COMPILE_FLAGS <string>])
|
# FLEX_TARGET(Name FlexInput FlexOutput
|
||||||
|
# [COMPILE_FLAGS <string>]
|
||||||
|
# [DEFINES_FILE <string>]
|
||||||
|
# )
|
||||||
#
|
#
|
||||||
# which creates a custom command to generate the <FlexOutput> file from
|
# which creates a custom command to generate the <FlexOutput> file from
|
||||||
# the <FlexInput> file. If COMPILE_FLAGS option is specified, the next
|
# the <FlexInput> file. If COMPILE_FLAGS option is specified, the next
|
||||||
# parameter is added to the flex command line. Name is an alias used to
|
# parameter is added to the flex command line. If flex is configured to
|
||||||
# get details of this custom command. Indeed the macro defines the
|
# output a header file, the DEFINES_FILE option may be used to specify its
|
||||||
# following variables:
|
# 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
|
# FLEX_${Name}_OUTPUTS - the source file generated by the custom rule, an
|
||||||
# alias for FlexOutput
|
# alias for FlexOutput
|
||||||
# FLEX_${Name}_INPUT - the flex source file, an alias for ${FlexInput}
|
# 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)
|
mark_as_advanced(FL_LIBRARY FLEX_INCLUDE_DIR)
|
||||||
|
|
||||||
|
include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
|
||||||
|
|
||||||
set(FLEX_INCLUDE_DIRS ${FLEX_INCLUDE_DIR})
|
set(FLEX_INCLUDE_DIRS ${FLEX_INCLUDE_DIR})
|
||||||
set(FLEX_LIBRARIES ${FL_LIBRARY})
|
set(FLEX_LIBRARIES ${FL_LIBRARY})
|
||||||
|
|
||||||
|
@ -145,31 +152,55 @@ if(FLEX_EXECUTABLE)
|
||||||
#============================================================
|
#============================================================
|
||||||
#
|
#
|
||||||
macro(FLEX_TARGET Name Input Output)
|
macro(FLEX_TARGET Name Input Output)
|
||||||
set(FLEX_TARGET_usage "FLEX_TARGET(<Name> <Input> <Output> [COMPILE_FLAGS <string>]")
|
set(FLEX_TARGET_outputs "${Output}")
|
||||||
if(${ARGC} GREATER 3)
|
set(FLEX_EXECUTABLE_opts "")
|
||||||
if(${ARGC} EQUAL 5)
|
|
||||||
if("${ARGV3}" STREQUAL "COMPILE_FLAGS")
|
set(FLEX_TARGET_PARAM_OPTIONS)
|
||||||
set(FLEX_EXECUTABLE_opts "${ARGV4}")
|
set(FLEX_TARGET_PARAM_ONE_VALUE_KEYWORDS
|
||||||
separate_arguments(FLEX_EXECUTABLE_opts)
|
COMPILE_FLAGS
|
||||||
else()
|
DEFINES_FILE
|
||||||
message(SEND_ERROR ${FLEX_TARGET_usage})
|
)
|
||||||
endif()
|
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(<Name> <Input> <Output> [COMPILE_FLAGS <string>] [DEFINES_FILE <string>]")
|
||||||
|
|
||||||
|
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()
|
else()
|
||||||
message(SEND_ERROR ${FLEX_TARGET_usage})
|
set(FLEX_${Name}_OUTPUT_HEADER ${FLEX_TARGET_ARG_DEFINES_FILE})
|
||||||
endif()
|
endif()
|
||||||
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()
|
endmacro()
|
||||||
#============================================================
|
#============================================================
|
||||||
|
|
||||||
|
@ -181,11 +212,11 @@ if(FLEX_EXECUTABLE)
|
||||||
macro(ADD_FLEX_BISON_DEPENDENCY FlexTarget BisonTarget)
|
macro(ADD_FLEX_BISON_DEPENDENCY FlexTarget BisonTarget)
|
||||||
|
|
||||||
if(NOT FLEX_${FlexTarget}_OUTPUTS)
|
if(NOT FLEX_${FlexTarget}_OUTPUTS)
|
||||||
message(SEND_ERROR "Flex target `${FlexTarget}' does not exists.")
|
message(SEND_ERROR "Flex target `${FlexTarget}' does not exist.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT BISON_${BisonTarget}_OUTPUT_HEADER)
|
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()
|
endif()
|
||||||
|
|
||||||
set_source_files_properties(${FLEX_${FlexTarget}_OUTPUTS}
|
set_source_files_properties(${FLEX_${FlexTarget}_OUTPUTS}
|
||||||
|
|
Loading…
Reference in New Issue