How to force the find_package searching inside a specific directory?

Hi all.
I’m trying to cross compile a Qt program using cmake. What I’m trying to do is to force the find_package searching for a directory. From the document I read as follows:

The default search order is designed to be most-specific to least-specific for common use cases. Projects may override the order by simply calling the command multiple times and using the NO_* options:

find_package ( PATHS paths… NO_DEFAULT_PATH) find_package ()

But when I trying to do things like:
find_package(Qt5Gui ${QT_VERSION} PATHS my/directory/to/qt5guiconfig/file/Qt5Gui NO_DEFAULT_PATH)
cmake cannot find the Qt5GuiConfig.cmake file, which is locate at the path I passed to find_package.

Can anyone pls give me some hints? Thank you so much.

When CMake fails to find a package, it usually prints a message which advises you to use the CMAKE_MODULE_PATH variable.
Have you tried calling cmake with



Thanks a lot for your advise Martin. But I still do not understand one thing. The CMAKE_MODULE_PATH is used as a global variable? Can I set different path for different modules?

In this case, Qt5Gui_DIR would probably be better. But CMAKE_MODULE_PATH is a list of paths, so additional directories can be added.

Thank you Ben, I do not know that the CMAKE_MODULE_PATH is a list. And about the Qt5Gui_DIR, does that mean the variable like _DIR will be automatically added to the search list for find_package?

Ben Boeckel via CMake Discourse 于2020年2月16日周日 上午2:03写道:

Yes, <pkgname>_DIR is special for find_package(<pkgname>).

Thx a lot Ben, that saves my life.