How package finding works
来源:互联网 发布:泰瑞克埃文斯 数据 编辑:程序博客网 时间:2024/06/07 19:01
The find_package() 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 here. You may also need the documentation for importing and exporting targets.
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:
- <NAME>_FOUND
- <NAME>_INCLUDE_DIRS or <NAME>_INCLUDES
- <NAME>_LIBRARIES or <NAME>_LIBRARIES or <NAME>_LIBS
- <NAME>_DEFINITIONS
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
- How package finding works
- How Internet EDI Works
- How E-mail Works
- How E-mail Works
- How Google Works
- How DES works
- How Google Works
- How Google Map Works
- How NAT Works
- How 4GT Works
- How PAE X86 Works
- How Digital Photography Works
- How Tomcat Works 1
- How Tomcat Works 2
- Books - How Tomcat works
- How Tomcat Works 5
- How Tomcat Works 9
- How Tomcat Works 6
- sort-colors
- javaweb+SSH实现简单的权限管理系统
- MQTT--测试
- MQTT--Python进行发布、订阅测试
- 欢迎使用CSDN-markdown编辑器
- How package finding works
- 爬格子呀6-1、6-2、6-3
- 【线段树】区间求和+区间修改(区间加)
- Android Study Material Design 五 番外篇 之:深入分析SnackBar源码
- 智能指针好用
- MySql从一窍不通到入门(九)Sharding的实现和规避
- Webpack
- easyUI下拉框控件easyui-combobox使用后台json文件填充数据失败的问题
- socket 网络编程