如何在cmake库中包含libcurl [英] How to include libcurl in cmake library
问题描述
我正在创建一个将libcurl作为依赖项的cpp库.我希望用户在他们的计算机上提供libcurl的路径.最好的方法是什么?
I am creating a cpp library that has libcurl as a dependency. I would like for the user to supply the path to libcurl on their computer. What is the best way to do this?
为澄清起见,我在Windows上制作了该库,但我希望它是跨平台的
To clarify, I am making the library on windows, but I would like for it to be cross-platform
推荐答案
根据您的描述,您必须将调用路径添加到cmake在试图通过调用[find_package]
Based on your description, you have to add the search path to the list of paths that cmake inspects when it tries to find a package by calling [find_package]
如果要支持用于链接libcurl
共享库(libcurl.so
)的用户定义路径,则可以通过cmake
命令通过CMAKE_PREFIX_PATH
传递它
If you want to support user-defined path for linking libcurl
shared object (libcurl.so
), you can pass it via CMAKE_PREFIX_PATH
from cmake
command
用法示例
cmake -DCMAKE_PREFIX_PATH=<full_path_where_curl_is_installed> -B build -S .
假定构建工件位于主项目的build
子目录(存在顶级CMakeLists.txt
的子目录)中,并且使用的cmake版本为 3.16 +
Assuming that the build artifacts will be at build
sub-directory of main project (where the top-level CMakeLists.txt
exists) and used cmake version is 3.16+
如果要将信息嵌入到自己的CMakeLists.txt
中,则可以启用curl的路径作为搜索路径
If you want to embed the information at your own CMakeLists.txt
, you can enable the path for curl as search path
用法示例
在您的CMakeLists.txt
中,在为CURL
调用find_package
之前添加以下行
in your CMakeLists.txt
, add the following line before calling find_package
for CURL
list(APPEND CMAKE_PREFIX_PATH <full_path_where_curl_is_installed>)
这篇关于如何在cmake库中包含libcurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!