I'm debugging a cmake file which fails to find certain packages (using find_package()
). What does find_package()
actually do when it searches for packages, and can I simulate it with a command line call (without invoking cmake)?
CMake searches for a file called Find<package>. cmake in the CMAKE_MODULE_PATH followed by the CMake installation. If the file is found, it is read and processed by CMake. It is responsible for finding the package, checking the version, and producing any needed messages.
CMake ships with its own set of built-in find_package scripts, and their location is in the default CMAKE_MODULE_PATH.
CMake maintains a list of package information in the Windows registry under HKEY_CURRENT_USER\Software\Kitware\CMake\Packages\ . Packages build from source can register there using the export command. Other projects build later on the same machine will then be able to find that package without additional configuration.
Using Modules For CMake, these sections are called cmake-modules and can be found in the Modules subdirectory of your installation.
1. What find_package does:
From the documentation of find_package():
CMake searches for a file called Find.cmake in the CMAKE_MODULE_PATH followed by the CMake installation. If the file is found, it is read and processed by CMake.
On Linux, the default scripts usually are located here:
ls /usr/share/cmake*/Modules/Find*.cmake
2. How to use find_package on the command-line:
# cmake --find-package -DNAME=Boost -DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=EXIST
Boost found
# cmake --find-package -DNAME=Boost -DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=COMPILE
-I/usr/include
# cmake --find-package -DNAME=Boost -DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=LINK
-rdynamic
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