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.
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:
- 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With