FindPackage in config mode.

I would like alter the search paths when doing Find Package in config mode. Is that possible?

There are HINTS and PATHS arguments to find_package that you can pass.

Thanks for your response. It’s just that the call for find package is from a third party and if possible would not like to change it. As a user of the 3rd party’s cmakeLists.txt, can I set/unset the search paths from outside.

Everything that affects finding these files is documented in the find_package docs. It’s…complicated, but there have been a lot of patterns used over the years :confused: .

Note you can effectively pre-empt a call to find_package() deep in a dependency by calling find_package() with your preferred set of arguments first before you pull in that dependency. As the find_package() docs state:

Once one of the calls succeeds the result variable will be set and stored in the cache so that no call will search again.

If you do that, there shouldn’t be any need to try to modify the search paths within the dependency because those calls should then bypass their search.

1 Like

There is a caveat though:
in my project I already find python with VERSION to argument set to 3. Later googletest also tries to find python without VERSION argument. Although the cached result should already match, it finds it again. And next cmake run, twice again…
This could be improved a bit :wink: