Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (31 sloc) 1.46 KB
.. spelling::

    flex

.. index:: compiler ; flex

flex

Simple flex example (no bison).

hunter_add_package(flex)
find_package(FLEX REQUIRED)

FLEX_TARGET(MyScanner numbers.lex ${CMAKE_CURRENT_BINARY_DIR}/numbers.cpp)
add_executable(main ${FLEX_MyScanner_OUTPUTS})
target_include_directories(main PUBLIC ${FLEX_INCLUDE_DIRS})
target_link_libraries(main ${FLEX_LIBRARIES})

More complex example involving flex and bison. Based on FindFLEX.

find_package(BISON REQUIRED)
hunter_add_package(flex)
find_package(FLEX REQUIRED)
BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp)
FLEX_TARGET(MyScanner lexer.l  ${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp)
ADD_FLEX_BISON_DEPENDENCY(MyScanner MyParser)  # MyParser defines tokens for MyScanner

add_executable(main main.cpp ${BISON_MyParser_OUTPUTS} ${FLEX_MyScanner_OUTPUTS})
target_include_directories(main
    $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
    ${BISON_INCLUDE_DIRS}
    ${FLEX_INCLUDE_DIRS})
target_link_libraries(main ${BISON_LIBRARIES} ${FLEX_LIBRARIES})
You can’t perform that action at this time.