简体   繁体   中英

How to include libcurl in cmake library

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM