用cmake找到libavahi [英] find libavahi with cmake

查看:454
本文介绍了用cmake找到libavahi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要添加libavahi-client3来对我的项目进行cmake依赖。还需要检查libavahi-client3和libavahi-common3是否存在。仅当前库(avahi)存在问题

I need to add libavahi-client3 to cmake dependency of my project. Also need to check libavahi-client3 and libavahi-common3 existence. Problems only with current library(avahi)

尝试执行以下操作:

find_package(libavahi-common3)
if(NOT libavahi-common3_FOUND)
message(ERROR " libavahi-common3 is not found")
endif(NOT libavahi-common3_FOUND)

或此变体:

find_library(AVAHI_COMMON_LIBRARY NAMES libavahi-common3)
if(NOT AVAHI_COMMON_LIBRARY_FOUND)
message(ERROR " libavahi-common3 is not found")
endif(NOT AVAHI_COMMON_LIBRARY_FOUND)

两者都不起作用,我搜索了诸如findAvahi.cmake之类的东西,但一无所获。因此,我应该编写自己的搜索模块,还是有另一个更好的选择?

Both do not work, i searched for something like findAvahi.cmake, but found nothing. So should i write my own search module or there is another better option?

推荐答案

当前没有使用CMake进行avahi交付的查找脚本,这就是为什么第一个示例不起作用的原因。重要的是要了解 find_package 只是运行一个外部查找脚本,它本身不会执行任何搜索。

There is currently no find script for avahi shipping with CMake, which is why your first example does not work. It is important to understand that find_package simply runs an external find script, it does not perform any searching by itself.

您的第二个示例已损坏,混合了 find_library find_package 的习惯用法。请阅读 find_library 的文档,并 find_path ,这将帮助您找到所需的库并包含路径。

Your second example is broken, mixing idioms from find_library and find_package. Please read up on the documentation of find_library and find_path which will help you find the required libraries and include paths.

如果您希望以后可以将其转换为查找脚本(请查看CMake模块目录中的脚本,以了解此类脚本应具有的外观这样),这将允许您使用更紧凑的find_package再次定位该库。请注意,编写在不同平台上都可以正常使用的查找脚本是一项复杂的任务,需要进行一些研究才能使其正确。

If you want you can turn that into a find script later (look at the scripts in CMake's module directory to get an idea what such a script should look like), which will allow you to use the more compact find_package for locating the library again. Note that writing a find script that works reasonably well on different platforms is a complex task that will require some research effort to get it right.

这篇关于用cmake找到libavahi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆