blob: 7d0394fb8d6da7f2e635c4d4d913237f5c35f91b [file] [log] [blame]
Brian Waters13d96012017-12-08 16:53:31 -06001# - Look for GNU flex, the lexer generator.
2# Defines the following:
3# FLEX_EXECUTABLE - path to the flex executable
4# FLEX_FILE - parse a file with flex
5# FLEX_PREFIX_OUTPUTS - Set to true to make FLEX_FILE produce outputs of
6# lex.${filename}.c, not lex.yy.c . Passes -P to flex.
7
8IF(NOT DEFINED FLEX_PREFIX_OUTPUTS)
9 SET(FLEX_PREFIX_OUTPUTS FALSE)
10ENDIF(NOT DEFINED FLEX_PREFIX_OUTPUTS)
11
12IF(NOT FLEX_EXECUTABLE)
13 MESSAGE(STATUS "Looking for flex")
14 FIND_PROGRAM(FLEX_EXECUTABLE flex)
15 IF(FLEX_EXECUTABLE)
16 MESSAGE(STATUS "Looking for flex -- ${FLEX_EXECUTABLE}")
17 ENDIF(FLEX_EXECUTABLE)
18 MARK_AS_ADVANCED(FLEX_EXECUTABLE)
19ENDIF(NOT FLEX_EXECUTABLE)
20
21IF(FLEX_EXECUTABLE)
22 MACRO(FLEX_FILE FILENAME)
23 GET_FILENAME_COMPONENT(PATH "${FILENAME}" PATH)
24 IF("${PATH}" STREQUAL "")
25 SET(PATH_OPT "")
26 ELSE("${PATH}" STREQUAL "")
27 SET(PATH_OPT "/${PATH}")
28 ENDIF("${PATH}" STREQUAL "")
29 IF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
30 FILE(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
31 ENDIF(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}")
32 IF(FLEX_PREFIX_OUTPUTS)
33 GET_FILENAME_COMPONENT(PREFIX "${FILENAME}" NAME_WE)
34 ELSE(FLEX_PREFIX_OUTPUTS)
35 SET(PREFIX "yy")
36 ENDIF(FLEX_PREFIX_OUTPUTS)
37 SET(OUTFILE "${CMAKE_CURRENT_BINARY_DIR}${PATH_OPT}/lex.${PREFIX}.c")
38 ADD_CUSTOM_COMMAND(
39 OUTPUT "${OUTFILE}"
40 COMMAND "${FLEX_EXECUTABLE}"
41 ARGS "-P${PREFIX}"
42 "-o${OUTFILE}"
43 "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}"
44 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}")
45 SET_SOURCE_FILES_PROPERTIES("${OUTFILE}" PROPERTIES GENERATED TRUE)
46 ENDMACRO(FLEX_FILE)
47ENDIF(FLEX_EXECUTABLE)