# cmake find\_package(X \[version\]) always finds highest version of X if multiple versions installed

**URL:** https://discourse.cmake.org/t/cmake-find-package-x-version-always-finds-highest-version-of-x-if-multiple-versions-installed/5750
**Category:** Usage
**Created:** [May 27, 2022, 9:03pm UTC](https://discourse.cmake.org/t/cmake-find-package-x-version-always-finds-highest-version-of-x-if-multiple-versions-installed/5750 "2022-05-27T21:03:07Z")
**Posts on this page:** 8
**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 27, 2022, 9:03pm UTC](https://discourse.cmake.org/t/cmake-find-package-x-version-always-finds-highest-version-of-x-if-multiple-versions-installed/5750/1 "2022-05-27T21:03:07Z")

</div>

I’m running cmake 3.23.0. I want to find\_library(VTK) based on version criteria. My ubuntu 20.04 system has two installed versions of VTK:

```auto
/usr/local/lib/cmake/vtk-8.2
/usr/local/lib/cmake/vtk-9.0

```

My project requires VTK version 8.x.x, i.e. need to exclude VTK 9.x.x - so CMakeLists.txt includes:

```auto
   find_package(VTK "8...<9" REQUIRED)

```

But VTK\_VERSION found is 9.0.1 - why, given the constraint? Also tried

```auto
find_package(VTK "8.0...<9.0" REQUIRED)
find_package(VTK "8.0.0...<9.0.0" REQUIRED)

```

with the same result - VTK\_VERSION 9.0.1 is found. Tried without a version range, but still find\_package() returns VTK\_VERSION 9.0.1:

```auto
   find_package(VTK "8" REQUIRED) 
   find_package(VTK “8.2” REQUIRED)
   find_package(VTK “8.2.0” REQUIRED)

```

The only thing that actually returns VTK\_VERSION 8.2.0:

```auto
   find_package(VTK “8.2.0” REQUIRED EXACT)

```

Is this behavior due to the fact that two VTK versions are installed on my system, and find\_packages() assumes just one is installed?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [May 27, 2022, 9:25pm UTC](https://discourse.cmake.org/t/cmake-find-package-x-version-always-finds-highest-version-of-x-if-multiple-versions-installed/5750/2 "2022-05-27T21:25:50Z")

</div>

Version range is not supported by all modules. This probably explains why specifying a range seems ignored.

Moreover, without the `EXACT` keyword, the standard meaning, when a version is specified, is to search for the most recent version which is greater or equal to this version.

So what you describe is the expected behavior…

---

<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 27, 2022, 9:34pm UTC](https://discourse.cmake.org/t/cmake-find-package-x-version-always-finds-highest-version-of-x-if-multiple-versions-installed/5750/3 "2022-05-27T21:34:59Z")

</div>

Thanks - so when I’m building a new project which needs third-party packages, I can’t count on version-range support? Makes the feature not-so-useful 😉 So how to determine whether it’s supported for a given package?

---

<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, 9:45pm UTC](https://discourse.cmake.org/t/cmake-find-package-x-version-always-finds-highest-version-of-x-if-multiple-versions-installed/5750/4 "2022-05-27T21:45:31Z")

</div>

You can’t in general. VTK could certainly be updated to handle this though. Could you please file [an issue](https://gitlab.kitware.com/vtk/vtk/-/issues)?

---

<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 27, 2022, 9:48pm UTC](https://discourse.cmake.org/t/cmake-find-package-x-version-always-finds-highest-version-of-x-if-multiple-versions-installed/5750/5 "2022-05-27T21:48:02Z")

</div>

So @ben.boeckel from my description, it’s safe to say that version-range is either not implemented or is broken for at VTK-8.2 (rather than a cmake problem)? Sure I can file an issue!

---

<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, 11:09pm UTC](https://discourse.cmake.org/t/cmake-find-package-x-version-always-finds-highest-version-of-x-if-multiple-versions-installed/5750/6 "2022-05-27T23:09:37Z")

</div>

Well, 8.2 isn’t getting fixed (nor 9.1 for that matter), but future VTK versions can learn new tricks at least

---

<div class="post-metadata">

### Author: ![triddlelover69](https://discourse.cmake.org/user_avatar/discourse.cmake.org/triddlelover69/32/1326_2.png) [@triddlelover69](https://discourse.cmake.org/u/triddlelover69)
#### Post date: [May 28, 2022, 7:12am UTC](https://discourse.cmake.org/t/cmake-find-package-x-version-always-finds-highest-version-of-x-if-multiple-versions-installed/5750/7 "2022-05-28T07:12:38Z")

</div>

> [@ben.boeckel](#):
>
> VTK versions can learn new tricks at least

Yeah, that’s what I and many other users are expecting.

---

<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 30, 2022, 12:43pm UTC](https://discourse.cmake.org/t/cmake-find-package-x-version-always-finds-highest-version-of-x-if-multiple-versions-installed/5750/8 "2022-05-30T12:43:26Z")

</div>

FWIW, VTK does have a `vtk-config-version.cmake` that should be doing this. Could you trace that code to see why it thinks `...8.2` is suitable for it?
