FindFLEX: Use CMAKE_PARSE_ARGUMENTS to parse arguments

This commit is contained in:
Chris Davies 2015-10-17 17:50:00 +01:00 committed by Brad King
parent bf7d21b0cd
commit 30710b8d32
1 changed files with 37 additions and 22 deletions

View File

@ -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,18 +147,30 @@ 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(<Name> <Input> <Output> [COMPILE_FLAGS <string>]")
if(${ARGC} GREATER 3)
if(${ARGC} EQUAL 5)
if("${ARGV3}" STREQUAL "COMPILE_FLAGS")
set(FLEX_EXECUTABLE_opts "${ARGV4}")
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)
else()
message(SEND_ERROR ${FLEX_TARGET_usage})
endif()
else()
message(SEND_ERROR ${FLEX_TARGET_usage})
endif()
endif()
add_custom_command(OUTPUT ${Output}
@ -170,6 +184,7 @@ if(FLEX_EXECUTABLE)
set(FLEX_${Name}_OUTPUTS ${Output})
set(FLEX_${Name}_INPUT ${Input})
set(FLEX_${Name}_COMPILE_FLAGS ${FLEX_EXECUTABLE_opts})
endif()
endmacro()
#============================================================