且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为yaml-cpp库找到正确的cmake配置

更新时间:2022-01-25 19:09:03

大多数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})