# How to find directory from glob expression?

**URL:** https://discourse.cmake.org/t/how-to-find-directory-from-glob-expression/5740
**Category:** Usage
**Created:** [May 26, 2022, 6:44pm UTC](https://discourse.cmake.org/t/how-to-find-directory-from-glob-expression/5740 "2022-05-26T18:44:54Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![tomoreilly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)
#### Post date: [May 26, 2022, 6:44pm UTC](https://discourse.cmake.org/t/how-to-find-directory-from-glob-expression/5740/1 "2022-05-26T18:44:54Z")

</div>

My linux machine has directory /usr/local/include/vtk-8.2/  
How can cmake find this directory using glob expression “_vtk-8_”?  
I tried this:

`file(GLOB result LIST_DIRECTORIES true RELATIVE /usr/local “*vtk-8*”)`

But ${result} is empty.

What am I doing wrong?

Thanks!

---

<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: [May 26, 2022, 7:12pm UTC](https://discourse.cmake.org/t/how-to-find-directory-from-glob-expression/5740/2 "2022-05-26T19:12:14Z")

</div>

Why do you want to find this directory by globbing? Is `find_package(VTK)` not working?

---

<div class="post-metadata">

### Author: ![tomoreilly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)
#### Post date: [May 26, 2022, 7:17pm UTC](https://discourse.cmake.org/t/how-to-find-directory-from-glob-expression/5740/3 "2022-05-26T19:17:14Z")

</div>

Correct, find\_package(vtk) is not working on this machine. I built vtk-8.2 from source, followed by ‘make install’ which put code in /usr/local/include/vtk-8.2, and libraries in /usr/local/lib. Yet find\_package() does not find the include directory.

---

<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: [May 26, 2022, 7:24pm UTC](https://discourse.cmake.org/t/how-to-find-directory-from-glob-expression/5740/4 "2022-05-26T19:24:45Z")

</div>

Does passing `--debug-find` to `cmake` give you any indication why it might be rejecting it?

---

<div class="post-metadata">

### Author: ![tomoreilly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)
#### Post date: [May 26, 2022, 7:58pm UTC](https://discourse.cmake.org/t/how-to-find-directory-from-glob-expression/5740/5 "2022-05-26T19:58:36Z")

</div>

I try to vtk with find\_package:

```auto
find_package(VTK)
message("VTK_FOUND: ${VTK_FOUND}")
message("VTK_INCLUDE_DIRS: ${VTK_INCLUDE_DIRS}")
message("VTK_LIBRARIES: ${VTK_LIBRARIES}")

```

Which returns VTK\_FOUND=1 and VTK\_LIBRARIES, but VTK\_INCLUDE\_DIRS is blank:

```auto
VTK_FOUND: 1
VTK_INCLUDE_DIRS: 
VTK_LIBRARIES: VTK::WrappingTools;VTK::ViewsQt;VTK::ViewsInfovis;VTK::CommonColor;VTK::ViewsContext2D;VTK::loguru;VTK::TestingRendering;VTK::TestingCore;VTK::vtksys;VTK::RenderingQt;VTK::PythonCon (et cetera...)

```

When I use --debug-find to cmake, there is a lot of output from find\_package(VTK), most of which I don’t understand. But no obvious error in there.

I _do_ see file /usr/local/lib/cmake/vtk-8.2, which contains many \*.cmake files. But I don’t see a corresponding /usr/local/include/cmake directory, despite the presence of /usr/local/include/vtk-8.2.

Thanks!

---

<div class="post-metadata">

### Author: ![tomoreilly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/439d5e/32.png) [@tomoreilly](https://discourse.cmake.org/u/tomoreilly)
#### Post date: [May 26, 2022, 8:25pm UTC](https://discourse.cmake.org/t/how-to-find-directory-from-glob-expression/5740/6 "2022-05-26T20:25:58Z")

</div>

It seems that cmake’s glob expressions _never_ match the path separator character ‘/’. This returns the expected result:

`file(GLOB result LIST_DIRECTORIES true RELATIVE /usr/local “/usr/local/*/*vtk-8*”)`

I.e. the glob expression must hard-code ‘/’. I do not see cmake’s glob expression rules anywhere - are they documented?

---

<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: [May 27, 2022, 1:01am UTC](https://discourse.cmake.org/t/how-to-find-directory-from-glob-expression/5740/7 "2022-05-27T01:01:21Z")

</div>

> [@tomoreilly](#):
>
> `VTK_LIBRARIES: VTK::WrappingTools`

This is VTK 9, not 8.2 (or the 8.90 pre-release era). I have no idea why it thinks it is 8.2 here. What is `${VTK_VERSION}`? VTK 8.90 and newer do _not_ have any include directories provided as a variable because they are not needed. The targets provide the usage requirements, so all you need to do is `target_link_libraries(mytgt ${vis} VTK::CommonCore)` for whatever modules you need to use.
