find_package does not find existing package

Hi Ben,

Thank you for that extremely valuable tip!
Helped me a lot to understand the process a bit better - even if I was not
able to come to a successful conclusion.

I have these locations of cmake executable on my sytem:

/usr/bin/cmake
/usr/local/bin/cmake (softlink to cmake at /opt/qt5.15...)
/opt/qt6.2/Tools/CMake/bin/cmake
/opt/qt5.15/Tools/CMake/bin/cmake
/opt/qt5.12/Tools/CMake/bin/cmake

According to output of “which cmake” /usr/local is the winner, which means
/opt/qt5.15 (the toolkit I actually use with that project).

When I run cmake --debug-find without any path or dir settings in
CMakeLists.txt, I get this output:

  find_program considered the following locations:

    /home/common/bin/uname
    /home/myself/.local/bin/uname
    /usr/local/bin/uname

  The item was found at

    /usr/bin/uname

That already shows, that cmake does not evaluate the path in the same order as OS.

Next I added a prefix setting for the cmake I use:

set(CMAKE_PREFIX_PATH "/opt/qt5.15/Tools/CMake/bin" CACHE PATH "path of cmake executable")

which leads to this output:

  find_program considered the following locations:

    /opt/qt5.15/Tools/CMake/bin/bin/uname
    /opt/qt5.15/Tools/CMake/bin/sbin/uname
    /opt/qt5.15/Tools/CMake/bin/uname
    /home/common/bin/uname
    /home/myself/.local/bin/uname
    /usr/local/bin/uname

  The item was found at

    /usr/bin/uname

Very very frustrating. The third path should result in a hit, but cmake “finds”
an executable at a location it had not searched for :frowning:

That smells like hardcoded path and debug output is just cheating …

I guess, that’s the key point. If cmake does not find the right location for
itself - I suppose anything else will fail too.