# Avoiding Cygwin when searching for FLEX

**URL:** https://discourse.cmake.org/t/avoiding-cygwin-when-searching-for-flex/9447
**Category:** Usage
**Created:** [November 17, 2023, 10:17am UTC](https://discourse.cmake.org/t/avoiding-cygwin-when-searching-for-flex/9447 "2023-11-17T10:17:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![EosPengwern](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eospengwern/32/3904_2.png) [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)
#### Post date: [November 17, 2023, 10:17am UTC](https://discourse.cmake.org/t/avoiding-cygwin-when-searching-for-flex/9447/1 "2023-11-17T10:17:12Z")

</div>

In a [previous question](https://discourse.cmake.org/t/findflex-and-cache-internal/9310) I asked for help with finding Flex. Following the advice given, I was able to find it and work with it. The version of Flex found was in my C:\Cygwin\bin directory.

For various reasons not to do with CMake, that version of Flex turns out not to be suitable, so I have installed win\_flex instead. However, I am having difficulty getting CMake to find it - it seems like whatever I do, it still finds the Cygwin version instead.

I have win\_flex.exe installed, and its directory is the first item in my system path.

I read in the manual that setting CMAKE\_IGNORE\_PATH doesn’t work with find\_package (unless it’s in config mode, but FindFLEX.cmake is in /modules), so I’m using find\_program.

Currently, I have the following code:

In my CMake command line:

```auto
-DCYGWIN_INSTALL_PATH=

```

In my actual script:

```auto
set(required_flex_version 2.5.35) # N.B. win_flex is version 2.6.4
if (MSVC)
   set(CMAKE_IGNORE_PATH "C:/cygwin/bin") # I've also tried "C:\\cygwin\\bin")
   message("Looking specifically for win_flex")
   message("CMAKE_FIND_ROOT_PATH is ${CMAKE_FIND_ROOT_PATH}")
   set(FLEX_EXECUTABLE )
   find_program(FLEX_EXECUTABLE NAMES win_flex DOC "path to the flex executable")
   message("win_flex found at ${FLEX_EXECUTABLE}")
else()
   find_package(FLEX ${required_flex_version})
endif()

```

My output:

```auto
Looking specifically for win_flex
CMAKE_FIND_ROOT_PATH is
win_flex found at C:/cygwin/bin/flex.exe

```

How does one make sense of this?

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [November 17, 2023, 11:41am UTC](https://discourse.cmake.org/t/avoiding-cygwin-when-searching-for-flex/9447/2 "2023-11-17T11:41:59Z")

</div>

You just unset the non-cache variable. Try using

> unset(FLEX\_EXECUTABLE CACHE)

OTOH, this will re-find it on every CMake run. Instead, you should start with a clean cache and not delete it in the script.

---

<div class="post-metadata">

### Author: ![EosPengwern](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eospengwern/32/3904_2.png) [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)
#### Post date: [November 17, 2023, 11:53am UTC](https://discourse.cmake.org/t/avoiding-cygwin-when-searching-for-flex/9447/3 "2023-11-17T11:53:19Z")

</div>

Thank you; that does indeed solve it, and I should have guessed; however, I was put off the trail by the fact that:

(a) In my previous question, the solution had been to leave the cache out of it and work on the basis of FLEX\_INCLUDE\_DIRS (at least) being a non-cache variable, and

(b) There’s no mention of the cache in FindFLEX.cmake.

Anyway, this one is now solved, so thank you again for your help.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 19, 2023, 2:38am UTC](https://discourse.cmake.org/t/avoiding-cygwin-when-searching-for-flex/9447/4 "2023-11-19T02:38:17Z")

</div>

> [@EosPengwern](#):
>
> (b) There’s no mention of the cache in FindFLEX.cmake.

Pretty much all `find_*` calls use the cache for their output to avoid rerunning on every configure. They have `NO_CACHE` arguments though.
