需要帮助试图让Cmake找到第三方库 [英] Need help trying to make Cmake find third party libraries

查看:345
本文介绍了需要帮助试图让Cmake找到第三方库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个项目链接到两个第三方库。这些库必须由自己构建,然后链接到项目。一个是taglib,另一个是zlib。我注意到当你在taglib目录中使用Cmake-gui程序时,需要指定zlib已经在哪里构建和安装。

I currently have a project that links to two third party libraries. These libraries have to be built by themselves and then linked to the project. One is taglib and the other is zlib. I noticed that when you use the Cmake-gui program on the taglib directory you're required to specify where zlib has been built and installed.

我的目标是获取CMake为我的程序做类似的事情。由于这些库的存储位置不一致,我如何提示用户提供所需的库的路径?

My goal is to get CMake to do a similar thing for my program. Since the place these libraries are stored will be inconsistent how can I prompt the user to provide the path to the libraries required?

我希望这是足够具体的。感谢您的帮助。

I hope this is specific enough. Thank you for your help.

推荐答案

在ZLib的情况下,Finduplib.cmake提供CMake, 将 find_package 电话拨入您的会议室。如果有必要,您可以对findzlib.cmake进行一些修改以满足您的需要。例如。在搜索库时添加ZLIB_DIR作为附加提示。然后可以由用户设置此ZLIB_DIR。

In the case of ZLib, a FindZLIB.cmake is provided with CMake and you can "simply" put a find_package call in your cmakelists. If necessary you can make some modifications to findzlib.cmake to suit your needs. E.g. adding ZLIB_DIR as an additional hint when searching for the library. This ZLIB_DIR can then be set by the user.

假设您的库/可执行文件称为YourProject,您可以使用它如下。

Assuming your library/executable is called YourProject, you can use it as follows.

find_package( ZLIB REQUIRED )
if ( ZLIB_FOUND )
    include_directories( ${ZLIB_INCLUDE_DIRS} )
    target_link_libraries( YourProject ${ZLIB_LIBRARIES} )
endif( ZLIB_FOUND )

您应该对TagLib使用相同的方法,写你自己的FindTagLib.cmake(或搜索一个好的)。

You should use the same approach for TagLib, but instead should write your own FindTagLib.cmake (or search for a good one).

这里的重要部分是给用户设置一个TagLib_DIR变量的选项,用于搜索TagLib,并使用 FindPackageHandleStandardArgs 报告成功或失败。

The important part here is that you give the user the option to set a TagLib_DIR variable, which you use to search for TagLib and that you use FindPackageHandleStandardArgs to report success or failure.

这篇关于需要帮助试图让Cmake找到第三方库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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