Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer HINTS to PATHS in cmake find modules #6218

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

bartgol
Copy link
Contributor

@bartgol bartgol commented Feb 7, 2024

For all the cmake find_XYZ utilities, there is a well defined ordered list in which CMake scans paths while searching. In this list, the paths passed via the argument HINTS appear early on. On the other hand, the paths passed via the argument PATHS appear quite late. After trying HINTS and before trying PATHS, CMake consider other options, among which we have

  • system paths (e.g., /usr directory on linux)
  • cmake package registry (this is only for find_package, but can be quite annoying and hard to find, as we experienced with EKAT)

CMake states that HINTS and PATHS should be used for different reasons. In particular, regarding HINTS it states that

These should be paths computed by system introspection, such as a hint provided by the location of another item already found. Hard-coded guesses should be specified with the PATHS option.

However, the fact that PATHS is scanned after system folders makes its usage more complicated. Since HINTS and PATHS are treated in the same way (meaning, CMake grabs the paths contained in them, and just scan them), from the practical point of view, the difference between the two is just the fact that one is considered much earlier than the other.

The alternative would have been to add NO_SYSTEM_PATH to the find_XYZ calls, but it comes with a drawback: if on some testing machine (a shared workstation, perhaps) we do have a valid installation of a tpl in the system paths, we would not pick it up. Using HINTS, we can still pick up the system install (leaving HINTS empty).

Fixes #6217 .

In the list of paths searched by CMake, the content of
the HINTS arg appears early on, while the content of
PATHS is down the list. In particular, between HINTS
and PATHS in that list there are

- system paths
- cmake package registry

These can cause system installation of a tpl or
previous installation of a tpl to be picked up
instead of the passed PATHS arg
@bartgol bartgol requested a review from jgfouca February 7, 2024 17:26
@bartgol bartgol self-assigned this Feb 7, 2024
Copy link

github-actions bot commented Feb 7, 2024

PR Preview Action v1.4.7
🚀 Deployed preview to https://E3SM-Project.github.io/E3SM/pr-preview/pr-6218/
on branch gh-pages at 2024-02-07 17:28 UTC

@rljacob rljacob assigned jgfouca and unassigned bartgol Feb 15, 2024
@rljacob
Copy link
Member

rljacob commented Feb 15, 2024

@jgfouca you can merge this.

jgfouca added a commit that referenced this pull request Feb 15, 2024
…6218)

Prefer HINTS to PATHS in cmake find modules

For all the cmake find_XYZ utilities, there is a well defined ordered
list in which CMake scans paths while searching. In this list, the
paths passed via the argument HINTS appear early on. On the other
hand, the paths passed via the argument PATHS appear quite late. After
trying HINTS and before trying PATHS, CMake consider other options,
among which we have:
 * system paths (e.g., /usr directory on linux)
 * cmake package registry (this is only for find_package, but can be quite
annoying and hard to find, as we experienced with EKAT)

CMake states that HINTS and PATHS should be used for different
reasons. In particular, regarding HINTS it states that:
  These should be paths computed by system introspection, such as a hint
  provided by the location of another item already found. Hard-coded
  guesses should be specified with the PATHS option.

However, the fact that PATHS is scanned after system folders makes its
usage more complicated. Since HINTS and PATHS are treated in the same
way (meaning, CMake grabs the paths contained in them, and just scan
them), from the practical point of view, the difference between the
two is just the fact that one is considered much earlier than the
other.

The alternative would have been to add NO_SYSTEM_PATH to the find_XYZ
calls, but it comes with a drawback: if on some testing machine (a
shared workstation, perhaps) we do have a valid installation of a tpl
in the system paths, we would not pick it up. Using HINTS, we can
still pick up the system install (leaving HINTS empty).

Fixes #6217

[BFB]
@jgfouca
Copy link
Member

jgfouca commented Feb 15, 2024

Merged to next.

@jgfouca jgfouca merged commit ccbccc1 into master Feb 19, 2024
3 checks passed
@jgfouca jgfouca deleted the bartgol/cmake/use-hints-instead-of-paths branch February 19, 2024 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Current impl of FindNETCDF.cmake picks up system installation before the one pointed by netcdf cmake vars
3 participants