Derek
Derek

Reputation: 11915

How to use FLEX in CMAKE

I am trying to figure out what I am doing wrong when trying to use just flex in a Cmake file to build a shared lib.

i basically have the following

find_package(FLEX)
FLEX_TARGET(Test ../src/test.l ../src/test.c)
set(SRC_FILES mysource.c ${FLEX_Test_OUTPUTS})
add_libary(testlib ${SRC_FILES})
target_link_libraries(testlib crypto c ${FLEX_LIBRARIES})

this is giving me a problem saying it cant find ../src/test.c

any ideas how I can make sure Lex ran first? secondly,how can i pass my -L and -d options to lex (like I am doing in my normal, pre-cmake version of this makefile)

Upvotes: 3

Views: 2861

Answers (1)

arrowd
arrowd

Reputation: 34401

Why do you want output file to be in the source dir?

I'd recommend using ${CMAKE_CURRENT_BINARY_DIR}:

FLEX_TARGET(Test ../src/test.l ${CMAKE_CURRENT_BINARY_DIR}/../src/test.c)

As for

any ideas how I can make sure Lex ran first?

you don't need to do it, CMake can guess this dependency by it's own. I think the problem is either in using source dir for output file, or the ../src dir doesn't exist before flex runs.

secondly,how can i pass my -L and -d options to lex

List them after the output parameter:

FLEX_TARGET(Test ../src/test.l ${CMAKE_CURRENT_BINARY_DIR}/../src/test.c -L -d)

Upvotes: 4

Related Questions