本文共 2127 字,大约阅读时间需要 7 分钟。
The command will look in the module path for Find<name>.cmake, which is the typical way for finding libraries. First CMake checks all directories in ${CMAKE_MODULE_PATH}, then it looks in its own module directory <CMAKE_ROOT>/share/cmake-x.y/Modules/.
If no such file is found, it looks for <Name>Config.cmake or <lower-case-name>-config.cmake, which are supposed to be installed by libraries (but there are currently not yet many libraries which install them) and that don't do detection, but rather just contain hardcoded values for the installed library.
The former is called module mode and the latter is called config mode. Creation of config mode files is documented . You may also need the documentation for .
For the module system there seems to be no documentation elsewhere, so this article concentrates on it.
No matter which mode is used, if the package has been found, a set of variables will be defined:
All this takes place in the Find<name>.cmake file.
Now, in the CMakeLists.txt file in the top level directory of your code (the client code that is actually going to make use of the library <name>, we check for the variable <NAME>_FOUND to see whether the package has been found or not. For most packages the resulting variables use the name of the package all uppercased, e.g. LIBFOO_FOUND, for some packages the exact case of the package is used, e.g. LibFoo_FOUND. If this variable is found, then, we pass the<NAME>_INCLUDE_DIRS to the include_directories() command and <NAME>_LIBRARIES to the target_link_libraries() command of CMake.
These conventions are documented in the file readme.txt in the CMake module directory.
The "REQUIRED" and other optional find_package arguments are forwarded to the module by find_package and the module should affect its operation based on them.
https://cmake.org/Wiki/CMake:How_To_Find_Libraries
updated on 24/Oct/2017
please also note that there are many findxxxx.cmake files under /usr/share/cmake-3.5/Modules to help find corresponding package
转载地址:http://yxxdi.baihongyu.com/