问题
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