Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Getting CMake to find flex on Windows

I am trying to use flex on a project and I am trying to use CMake to link flex with my project. I found a FindFLEX.cmake online which I am using for this. You can find it here. This was supposed to be in CMake by default, but I dont think it was. My directory structure is as follows

   ---flex - Where flex is installed

My src/CMakeLists.txt is as follows

cmake_minimum_required(VERSION 2.8)
set( project_name "try_flex" )
FLEX_TARGET(Mylexer tokenize.lex ${CMAKE_CURRENT_BINARY_DIR}/tokenize.cpp)
add_executable(${project_name} ${FLEX_Mylexer_OUTPUTS})
target_link_libraries(${project_name} ${FLEX_LIBRARIES})

FLEX_TARGET is supposed to be provided by FindFLEX.cmake when it finds the Flex package. Running the following command in build/ directory didnt find the flex packages

build> cmake ..\src

Then I added the prefix and that worked partially

build> cmake -DCMAKE_PREFIX_PATH=c:\root\external\flex\ ..\src

That found the executable flex.exe , but not the library. The relevant portions of FindFLEX.cmake is shown below

FIND_PROGRAM(FLEX_EXECUTABLE flex DOC "path to the flex executable")

FIND_LIBRARY(FL_LIBRARY NAMES fl DOC "path to the fl library")

The message I get on running cmake is

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake file s:FL_LIBRARY (ADVANCED)
linked by target "try_flex" in directory C:/root/src

-- Configuring incomplete, errors occurred!

Could anyone tell me why I am finding the flex binary but not the library after including the prefix path? Any help would be appreciated.


like image 239
Mahesh Ravishankar Avatar asked May 22 '13 16:05

Mahesh Ravishankar

1 Answers

I figured out what the problem is. On Windows, cmake is looking for libfl.lib. But the Windows installation of Flex provides only libfl.a So I needed to add these two lines to my cmake

FIND_LIBRARY(FL_LIBRARY NAMES libfl fl DOC "path to the fl library")

The first line adss .a to list of suffixes searched for libraries, and the second line looks for libfl. That worked

like image 116
Mahesh Ravishankar Avatar answered Nov 06 '22 09:11

Mahesh Ravishankar