# CMAKE\_IGNORE\_PREFIX\_PATH

**URL:** <https://discourse.cmake.org/t/cmake-ignore-prefix-path/5559>\
**Category:** Code\
**Created:** [April 27, 2022, 8:26pm UTC](https://discourse.cmake.org/t/cmake-ignore-prefix-path/5559 "2022-04-27T20:26:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)\
**Post date:** [April 27, 2022, 8:26pm UTC](https://discourse.cmake.org/t/cmake-ignore-prefix-path/5559/1 "2022-04-27T20:26:39Z")

</div>

I am trying to use [CMAKE\_IGNORE\_PREFIX\_PATH](https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6880) to avoid having to set a long list of CMAKE\_IGNORE\_PATH subdirectories. However, it appears not to work for the use case described in the MR discussion.

My case is Anaconda Python’s HDF5 library interfering with system HDF5, since Anaconda puts itself first in PATH, and I can’t disable Anaconda since it’s also used by the project. I currently fix this by having a long list of manually set CMAKE\_IGNORE\_PATH. It appears that this script below should work, but CMAKE\_IGNORE\_PREFIX\_PATH seems to have no effect. This is tested with CMake 3.23.1 on Linux and Windows below.

NOTE: if I “conda deactivate”, removing Anaconda from PATH, then the find\* works. Also using CMAKE\_IGNORE\_PATH with numerous Anaconda subdirectories works.

```cmake
set(CMAKE_IGNORE_PREFIX_PATH $ENV{CONDA_PREFIX})
message(STATUS "$ENV{CONDA_PREFIX}")

find_program(exe NAMES h5cc)
find_library(lib NAMES hdf5)

message(STATUS "${exe} ${lib}")

```

On Linux, I would expect “exe” and “lib” to find the system HDF5, but instead:

```auto
-- /opt/miniconda3
-- /opt/miniconda3/bin/h5cc /usr/lib/libhdf5.a

```

On Windows I would expect “exe” and “lib” to find my installed HDF5, but instead:

```auto
-- C:\miniconda3
-- c:\<path to installed h5cc.exe> C:/miniconda3/Library/lib/hdf5.lib

```

---

<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:** [April 27, 2022, 8:38pm UTC](https://discourse.cmake.org/t/cmake-ignore-prefix-path/5559/2 "2022-04-27T20:38:49Z")

</div>

Cc: @kyle.edwards

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [April 27, 2022, 8:42pm UTC](https://discourse.cmake.org/t/cmake-ignore-prefix-path/5559/3 "2022-04-27T20:42:36Z")

</div>

The problem is that `CMAKE_IGNORE_PREFIX_PATH` doesn’t have a way of deducing the prefix from `$ENV{PATH}`. Sure, if the component ends in `/bin` then there’s a chance that the preceding component might be the prefix, but do we want to bet on that?

How is it finding the libraries? Is there an equivalent of `PATH` that it’s using for that?

---

<div class="post-metadata">

**Author:** ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)\
**Post date:** [April 27, 2022, 8:53pm UTC](https://discourse.cmake.org/t/cmake-ignore-prefix-path/5559/4 "2022-04-27T20:53:37Z")

</div>

I don’t set anything special. If I set CMAKE\_PREFIX\_PATH I see via `--debug-find` that that is searched first, then environment variable PATH.

The idea is that I have a known “bad” directory tree like CONDA\_PREFIX I always want to avoid on user systems.

This does works, but seems less elegant than what I thought CMAKE\_IGNORE\_PREFIX\_PATH would do.

```cmake
set(CMAKE_IGNORE_PATH
    $ENV{CONDA_PREFIX}/bin $ENV{CONDA_PREFIX}/lib $ENV{CONDA_PREFIX}/include
    $ENV{CONDA_PREFIX}/Library/bin $ENV{CONDA_PREFIX}/Library/lib $ENV{CONDA_PREFIX}/Library/include
  )

```

The first row is Linux/Mac, second row is Windows. There’s more paths than this so I have to keep adding to this list as packages change. But I want to ignore all subdirectories of CONDA\_PREFIX

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [April 27, 2022, 8:59pm UTC](https://discourse.cmake.org/t/cmake-ignore-prefix-path/5559/5 "2022-04-27T20:59:50Z")

</div>

Please post the entire output from `--debug-find`. That will help me track down the problem.

---

<div class="post-metadata">

**Author:** ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)\
**Post date:** [August 28, 2023, 2:38pm UTC](https://discourse.cmake.org/t/cmake-ignore-prefix-path/5559/6 "2023-08-28T14:38:33Z")

</div>

The end result was, CMAKE\_IGNORE\_PREFIX\_PATH must be set outside any custom Find\*.cmake the project has. So I set that variable before my custom find\_package(HDF5) is called and it works to ignore the entire tree under the prefix.
