How to include libcurl in cmake library

落爺英雄遲暮 提交于 2020-02-16 10:44:08

问题


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?

Edit: To clarify, I am making the library on windows, but I would like for it to be cross-platform


回答1:


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]

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

Usage example

cmake -DCMAKE_PREFIX_PATH=<full_path_where_curl_is_installed> -B build -S .

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+

If you want to embed the information at your own CMakeLists.txt, you can enable the path for curl as search path

Usage example

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>)



来源:https://stackoverflow.com/questions/60178270/how-to-include-libcurl-in-cmake-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!