This template provides two scripts:
- scripts/flex-bison.cmake
- scripts/bison-shim.sh.in (linux shim)
Which provide support for fetching (if not already present) and compiling Flex and Bison on Windows, Linux, and MacOS.
The reflex branch includes a version of the scripts that provides RE-flex instead of flex.
The library is used by including flex-bison.cmake and calling the fetch function:
include(scripts/flex-bison.cmake)
fetch_flex_bison()
There will then be be flex
and bison
executable targets that can be used in cmake custom commands.
Additionally two new functions, which both take create a new target which uses flex/bision respectively to create the given output file whenever the input file changes are provided:
add_flex_target(run_flex ${CMAKE_SOURCE_DIR}/in.l OUTPUT ${CMAKE_SOURCE_DIR}/gen/scanner.h <extra flags here>)
add_bison_target(run_bison ${CMAKE_SOURCE_DIR}/in.y OUTPUT ${CMAKE_SOURCE_DIR}/gen/parser.h <extra flags here>)
NOTE: Extra flags can be passed at the end of the function and will be directly appended to the flex/bison call.
The scripts are MIT licensed, Flex and Re-flex are BSD licensed, Bison and the Windows versions of both libraries are GPL-3.0 licensed.