CMake is searching for packages in a strange location

500 Views Asked by At

I have been trying to track down why CMake find_package is finding the wrong package in my build. From CMake find_package: where did it find the package? I learned how to get it to tell me what paths it was searching, and thus where it found the package. But now I need to figure out why CMake is searching a certain path, because it is searching in a non-default location for some reason. I checked the variables

CMAKE_MODULE_PATH
CMAKE_PREFIX_PATH
CMAKE_INCLUDE_PATH
CMAKE_LIBRARY_PATH
CMAKE_PROGRAM_PATH

but they are empty. The variable

CMAKE_SYSTEM_PREFIX_PATH

is non-empty, but all it contains is

/usr/local;/usr;/;/usr;/tmp/pip-req-build-ckl98h8g/build/lib.linux-x86_64-3.6

so that is not the reason.

What else can make CMake search some strange prefix?

The exact problem is the following: find_package(yaml-cpp) is searching as follows:

  ...
  Checking prefix [/]
  Checking file [/yaml-cppConfig.cmake]
  Checking file [/yaml-cpp-config.cmake]
  Checking prefix [/usr/games/]
  Checking file [/usr/games/yaml-cppConfig.cmake]
  Checking file [/usr/games/yaml-cpp-config.cmake]
  Checking prefix [/usr/local/games/]
  Checking file [/usr/local/games/yaml-cppConfig.cmake]
  Checking file [/usr/local/games/yaml-cpp-config.cmake]
  Checking prefix [/snap/]
  Checking file [/snap/yaml-cppConfig.cmake]
  Checking file [/snap/yaml-cpp-config.cmake]
  Checking prefix [/home/farmer/repos/gambit/copy3/build/contrib/yaml-cpp-0.6.2/]
  Checking file [/home/farmer/repos/gambit/copy3/build/contrib/yaml-cpp-0.6.2/yaml-cppConfig.cmake]
  Checking file [/home/farmer/repos/gambit/copy3/build/contrib/yaml-cpp-0.6.2/yaml-cpp-config.cmake]

It finds the package config file in that last path. But that is some private build directory of some other code, so I have no idea why find_package would search there. Some variable somewhere must have told it to do so, but I don't know which one. I do not want this path to be searched.

1

There are 1 best solutions below

0
On

Ok I think the answer is that CMake follows a horribly complicated procedure to search all over the place for packages. In my case it seems that it found something under

~/.cmake/packages/<package>

which then must have directed it to the strange prefix I was seeing. Deleting this package registry entry fixed the problem. The full search procedure that CMake follows is described towards the end of the find_package documentation: https://cmake.org/cmake/help/v3.0/command/find_package.html