FindBISON: Add DEFINES_FILE option to pass --defines=FILE
This commit is contained in:
parent
eb859263ae
commit
12e534c2b8
|
@ -22,6 +22,7 @@
|
|||
#
|
||||
# BISON_TARGET(<Name> <YaccInput> <CodeOutput>
|
||||
# [COMPILE_FLAGS <flags>]
|
||||
# [DEFINES_FILE <file>]
|
||||
# [VERBOSE <file>]
|
||||
# )
|
||||
#
|
||||
|
@ -35,6 +36,9 @@
|
|||
# ``COMPILE_FLAGS <flags>``
|
||||
# Specify flags to be added to the ``bison`` command line.
|
||||
#
|
||||
# ``DEFINES_FILE <file>``
|
||||
# Specify a non-default header ``<file>`` to be generated by ``bison``.
|
||||
#
|
||||
# ``VERBOSE <file>``
|
||||
# Tell ``bison`` to write verbose descriptions of the grammar and
|
||||
# parser to the given ``<file>``.
|
||||
|
@ -64,7 +68,8 @@
|
|||
# .. code-block:: cmake
|
||||
#
|
||||
# find_package(BISON)
|
||||
# BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp)
|
||||
# BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
|
||||
# DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.h)
|
||||
# add_executable(Foo main.cpp ${BISON_MyParser_OUTPUTS})
|
||||
|
||||
#=============================================================================
|
||||
|
@ -140,6 +145,12 @@ if(BISON_EXECUTABLE)
|
|||
list(APPEND BISON_TARGET_cmdopt ${BISON_TARGET_extraopts})
|
||||
endmacro()
|
||||
|
||||
# internal macro
|
||||
macro(BISON_TARGET_option_defines Header)
|
||||
set(BISON_TARGET_output_header "${Header}")
|
||||
list(APPEND BISON_TARGET_cmdopt --defines=${BISON_TARGET_output_header})
|
||||
endmacro()
|
||||
|
||||
#============================================================
|
||||
# BISON_TARGET (public macro)
|
||||
#============================================================
|
||||
|
@ -154,6 +165,7 @@ if(BISON_EXECUTABLE)
|
|||
set(BISON_TARGET_PARAM_ONE_VALUE_KEYWORDS
|
||||
VERBOSE
|
||||
COMPILE_FLAGS
|
||||
DEFINES_FILE
|
||||
)
|
||||
set(BISON_TARGET_PARAM_MULTI_VALUE_KEYWORDS)
|
||||
cmake_parse_arguments(
|
||||
|
@ -173,14 +185,19 @@ if(BISON_EXECUTABLE)
|
|||
if(NOT "${BISON_TARGET_ARG_COMPILE_FLAGS}" STREQUAL "")
|
||||
BISON_TARGET_option_extraopts("${BISON_TARGET_ARG_COMPILE_FLAGS}")
|
||||
endif()
|
||||
if(NOT "${BISON_TARGET_ARG_DEFINES_FILE}" STREQUAL "")
|
||||
BISON_TARGET_option_defines("${BISON_TARGET_ARG_DEFINES_FILE}")
|
||||
endif()
|
||||
|
||||
# Header's name generated by bison (see option -d)
|
||||
list(APPEND BISON_TARGET_cmdopt "-d")
|
||||
string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\2" _fileext "${BisonOutput}")
|
||||
string(REPLACE "c" "h" _fileext ${_fileext})
|
||||
string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\1${_fileext}"
|
||||
BISON_${Name}_OUTPUT_HEADER "${BisonOutput}")
|
||||
list(APPEND BISON_TARGET_outputs "${BISON_${Name}_OUTPUT_HEADER}")
|
||||
if("${BISON_TARGET_output_header}" STREQUAL "")
|
||||
# Header's name generated by bison (see option -d)
|
||||
list(APPEND BISON_TARGET_cmdopt "-d")
|
||||
string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\2" _fileext "${BisonOutput}")
|
||||
string(REPLACE "c" "h" _fileext ${_fileext})
|
||||
string(REGEX REPLACE "^(.*)(\\.[^.]*)$" "\\1${_fileext}"
|
||||
BISON_TARGET_output_header "${BisonOutput}")
|
||||
endif()
|
||||
list(APPEND BISON_TARGET_outputs "${BISON_TARGET_output_header}")
|
||||
|
||||
add_custom_command(OUTPUT ${BISON_TARGET_outputs}
|
||||
${BISON_TARGET_extraoutputs}
|
||||
|
@ -196,6 +213,7 @@ if(BISON_EXECUTABLE)
|
|||
set(BISON_${Name}_OUTPUTS ${BISON_TARGET_outputs})
|
||||
set(BISON_${Name}_COMPILE_FLAGS ${BISON_TARGET_cmdopt})
|
||||
set(BISON_${Name}_OUTPUT_SOURCE "${BisonOutput}")
|
||||
set(BISON_${Name}_OUTPUT_HEADER "${BISON_TARGET_output_header}")
|
||||
|
||||
endif()
|
||||
endmacro()
|
||||
|
|
Loading…
Reference in New Issue