6
votes

I use find_package in CONFIG mode to find Qt5:

find_package(Qt5 CONFIG REQUIRED COMPONENTS Core)

I don't specify CMAKE_PREFIX_PATH and /home/user/Qt/5.5/gcc_64/bin is not set in PATH but cmake finds *Config.cmake files:

/home/user/Qt/5.5/gcc_64/lib/cmake/Qt5/Qt5Config.cmake
/home/user/Qt/5.5/gcc_64/lib/cmake/Qt5Core/Qt5CoreConfig.cmake

How does it work ? How cmake create search paths ?

Edit1

I read a documentation but it is unclear for me:

<prefix>/(lib/<arch>|lib|share)/cmake/<name>*/          (U)
<prefix>/(lib/<arch>|lib|share)/<name>*/                (U)
<prefix>/(lib/<arch>|lib|share)/<name>*/(cmake|CMake)/  (U)

What is the prefix ? How the above patterns match to the Qt path ? :

/home/user/Qt/5.5/gcc_64/lib/cmake/Qt5/Qt5Config.cmake

I have created a similar path for my library:

/home/user/Mylib/1.0/gcc_64/lib/cmake/Mylib1/Mylib1Config.cmake

but find_package(Mylib1 CONFIG) returns an error:

CMake Warning at CMakeLists.txt:14 (find_package):
Could not find a package configuration file provided by "Mylib1" with any
of the following names:

Mylib1Config.cmake
mylib1-config.cmake

Add the installation prefix of "Mylib1" to CMAKE_PREFIX_PATH or set
"Mylib1_DIR" to a directory containing one of the above files.  If "Mylib1"
provides a separate development package or SDK, be sure it has been
installed.
2
There are much more prefixes, searched by CMake for find config files. See documentation on find_package: cmake.org/cmake/help/v3.0/command/find_package.html - Tsyvarev
This is an interesting question. Have you find the answer? - nn0p

2 Answers

2
votes

Taken <prefix> as /home/user/Qt/5.5/gcc_64, full directory name for Qt5Config.cmake can be obtained via that template:

<prefix>/(lib/<arch>|**lib**|share)/cmake/<name>*/

As for origin of the prefix itself, I guess it comes from User Package Registry:

  1. Search paths stored in the CMake User Package Registry. This can be skipped if NO_CMAKE_PACKAGE_REGISTRY is passed. See the cmake-packages(7) manual for details on the user package registry.

You can check content of ~/.cmake/packages/ folder for check that registry's content.

0
votes

If /home/user/Qt/5.5/gcc_64/bin is in your PATH for example, cmake will search the sibling lib directories automatically.