1#
2# Setup flex to build lexer
3#
4# We don't really support any lex(1) other than flex.  It's possible some
5# minor editing of lex.l could get you through that...
6#
7# If you DO have flex, we go ahead and use it to build the lexer.  If you
8# don't, we check to see if there's a prebuilt one in the tree; one will
9# be shipped with tarballs for releases etc (but you'll still build your
10# own if you have flex).  If neither of those hit, not much we can do but
11# bomb...
12
13# Override for forcing use of pregen'd source files
14if(NOT FORCE_PREGEN_FILES)
15	find_package(FLEX)
16endif()
17
18
19if(FLEX_FOUND)
20	FLEX_TARGET(ctwm_lexer lex.l ${CMAKE_CURRENT_BINARY_DIR}/lex.c)
21else()
22	# See if we have a pre-built lex.c
23	find_file(LEX_C lex.c
24		PATHS ${GENSRCDIR}
25		NO_DEFAULT_PATH)
26	if(LEX_C)
27		# Make the build process just copy it in
28		message(STATUS "No flex found, using prebuilt lex.c")
29		add_custom_command(OUTPUT lex.c
30			DEPENDS ${LEX_C}
31			COMMAND cp ${LEX_C} .
32			COMMENT "Copying in prebuilt lex.c"
33		)
34	else()
35		# No flex, no pre-built lex.c
36		message(FATAL_ERROR "Can't find flex, and no prebuilt files "
37			"available.")
38	endif(LEX_C)
39endif(FLEX_FOUND)
40