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

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 我又胖又丑怎么办 吃避孕药变胖了怎么办 熬夜久了眼睛疼怎么办 熬夜眼睛疼肿了怎么办 胡须长的太快怎么办 乳房有小结结该怎么办 我一点胸都没有怎么办 狗狗不愿意睡窝怎么办 狗狗喜欢睡地板怎么办 小金毛不吃狗粮怎么办 孕前没有吃叶酸怎么办 严重少精和畸形怎么办 大学混了四年怎么办 和家人相处很累怎么办 40多岁眼睛花怎么办 侧方停车右边宽怎么办 有公主病的老婆怎么办? 圆通快递太慢了怎么办 美台军舰互停怎么办 安装包删除不掉怎么办 艾灸后皮肤极痒怎么办 拔罐如果有水泡怎么办 拔罐拔出水泡来怎么办 拔罐拔出了水泡怎么办 风湿引起的背疼怎么办 拔罐减肥不瘦怎么办 艾灸后脸上长痘怎么办 艾灸烟大怎么办 湿毛巾 月经推迟一个月了还不来怎么办 埋线了喝酒了怎么办 对待孩子脾气暴燥怎么办 买的新鞋子臭脚怎么办 鞋子臭脚怎么办如何除 惠普803墨盒干了怎么办 酷派手机无命令怎么办 华为手机锁机了怎么办 小孩被蜘蛛咬了怎么办 我是一个不爱说话的人怎么办 光动能手表停了怎么办 电波表收不到波怎么办 吃了壮阳药头疼怎么办