[CMAKE] Introduce a way to use auto generation using bison and flex. Dedicated to Eric Kohl. CORE-10055

svn path=/trunk/; revision=68840
This commit is contained in:
Amine Khaldi 2015-08-27 23:00:49 +00:00
parent 6c6dae8b30
commit 17228d9d3e
2 changed files with 30 additions and 0 deletions

View file

@ -75,6 +75,9 @@ if(NOT MSVC_IDE)
unset(CMAKE_IMPORT_LIBRARY_SUFFIX)
endif()
# Bison and Flex support
# include(cmake/bison-flex.cmake)
if(NOT CMAKE_CROSSCOMPILING)
add_definitions(-DTARGET_${ARCH})

View file

@ -0,0 +1,27 @@
# Simply use :
# add_bison_files(foo.y)
# and
# add_flex_files(foo.l)
# then add ${CMAKE_CURRENT_BINARY_DIR}/foo.tab.c
# and ${CMAKE_CURRENT_BINARY_DIR}/foo.yy.c to the source list
function(add_bison_files)
foreach(_file ${ARGN})
get_filename_component(_name ${_file} NAME_WE)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}.tab.c ${CMAKE_CURRENT_BINARY_DIR}/${_name}.tab.h
COMMAND bison -p ${_name}_ -o ${CMAKE_CURRENT_BINARY_DIR}/${_name}.tab.c --defines=${CMAKE_CURRENT_BINARY_DIR}/${_name}.tab.h ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
endforeach()
endfunction()
function(add_flex_files)
foreach(_file ${ARGN})
get_filename_component(_name ${_file} NAME_WE)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_name}.yy.c ${CMAKE_CURRENT_BINARY_DIR}/${_name}.yy.h
COMMAND flex -o ${CMAKE_CURRENT_BINARY_DIR}/${_name}.yy.c --header-file=${CMAKE_CURRENT_BINARY_DIR}/${_name}.yy.h ${CMAKE_CURRENT_SOURCE_DIR}/${_file}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_file})
endforeach()
endfunction()