为yaml-cpp库找到正确的cmake配置 [英] Finding correct cmake configuration for yaml-cpp library

查看:1301
本文介绍了为yaml-cpp库找到正确的cmake配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的项目中使用 yaml-cpp .通过尝试以下名称,我花了半个小时才正确链接库.在我最终在此文件,我为此解决了:

I was trying to use yaml-cpp in my project. It took me half an hour to correctly link the library by experimenting with the following names. After I finally stumbled across them in this file, I settled for this:

find_package(yaml-cpp REQUIRED)
include_directories(${YAML_INCLUDE_DIRS})
target_link_libraries(${YAML_CPP_LIBRARIES})

它有效,但是我搜索这些内容的方式似乎毫无头脑.

It works, but the way I was searching for those seems brainless.

如何远程找出包含变量的正确名称?可能是YAML_LIBSYAML_LIBRARYYAML_CPP_LIBRARIES,没有标准,对吗?为大多数C ++库确定正确的cmake配置的合适方法是什么?

How is it remotely possible to figure out the correct name of the include variables? It could be YAML_LIBS, YAML_LIBRARY, YAML_CPP_LIBRARIES, there is no standard, right? What is the appropriate way to determine the correct cmake config for most c++ libraries?

谢谢.

推荐答案

大多数FindXXX.cmake脚本的顶部都有用法说明(因为CMake注释开始于#). XXXConfig.cmake(或xxx-config.cmake)脚本也是如此.

Most of FindXXX.cmake scripts have usage description at the top of them (as CMake comments started #). The same is true about XXXConfig.cmake (or xxx-config.cmake) scripts.

命令find_package(XXX)使用一种这样的脚本(实际存在的一种).因此,在使用这种方法发现软件包之前,请确保已将描述嵌入"到该脚本中.

Command find_package(XXX) uses one of such scripts (the one which actually exists). So, before using this approach for discover the package, make sure that you have read the description "embedded" into such script.

在您的情况下,yaml-cpp-config.cmake文件(在内部版本或安装目录中创建)包含以下描述:

In your case, yaml-cpp-config.cmake file (created in the build or in the install directory) contains following description:

# - Config file for the yaml-cpp package
# It defines the following variables
#  YAML_CPP_INCLUDE_DIR - include directory
#  YAML_CPP_LIBRARIES    - libraries to link against

find_package(yaml-cpp)结果的正确用法是

include_directories(${YAML_CPP_INCLUDE_DIRS})
target_link_libraries(<your-target> ${YAML_CPP_LIBRARIES})

这篇关于为yaml-cpp库找到正确的cmake配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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