Linking to curlcpp (a C++ curl wrapper)

I’m trying to link curlcpp, a C++ curl wrapper, to a library of my own.

My idea was to:

  1. FetchContent_Declare both curl and curlcpp.
  2. FetchContent_MakeAvailable both of them as well.
  3. Link libcurl.lib and curlcpp lib to my library.

I’m getting though an error saying that curlcpp needs CURL_LIBRARY variable to be set.

  • Is there any way to 1) set CURL_LIBRARY to wherever the build process is going to leave libcurl.lib, and 2) have it available for curlcpp compilation? I understand a set(CURL_LIBRARY <path to libcurl.lib>) should suffice.
  • I know curl sources are downloaded to ${curl_SOURCE_DIR}. Can I know where the output libcurl.lib will be placed? Is there a ${curl_BINARY_DIR}?

Here’s what I understand can be the relevant code from my CMakeLists.txt files.

cmake_minimum_required(VERSION 3.5)

    LANGUAGES C CXX  # C is needed for curl

    GIT_TAG "55bc50c244ecb5a14ac21b3b2e2931267a5bb802"
FetchContent_MakeAvailable(curl curlcpp)


You may be able to set it to the target that curl makes for you to use (libcurl it appears).

Cc: @craig.scott

1 Like

There’s also the “Curl for People” project, which you can find here:

I’ve embedded that into a larger project hierarchy with FetchContent before. I upstreamed a couple of minor patches to enable that to be done cleanly, and they are part of the official releases now, so I’d expect a fairly smooth path.

The problem you are facing with curlcpp is that it wants to bring curl into the build with find_package(), but you are trying to bring curl into the build with FetchContent. There is a feature coming in CMake 3.24 which would allow you to do this cleanly (see MR 5688), but at the moment, this mixture of methods requires some hacking around one or the other to make it work. Basically, you would have to either force the find_package() call to pick up a dummy Findcurl.cmake or curl-config.cmake that you put somewhere, or abandon using FetchContent bringing in curl and require it to be provided by something outside of CMake.


Thanks for your response. I did try quite a few things, one of them doing a target_link_libraries(curlcpp INTERFACE ${curl_BINARY_DIR}/lib/libcurl.lib) and then linking my library to curlcpp, but no of them work.

I’ll definitely give this libcpr/cpr a go.

Many thanks for the explanation of my issue!

This new integration between FetchContent and find_package sounds amazing! I think it would make the job of a package manager much easier to integrate with CMake.

Is this feature going to be in 3.24.0?

Yes, it is already merged, so should be in CMake 3.24. There’s other associated work too relating to package manager support which should make it in as well (I’ll be putting up that change for review this week).

1 Like

awesome, exciting!

May you point me to an example of a dummy FindXYZ.cmake file?

I’ve seen that, in my project, I have a few other cases where I have the same issue.

For example, PDF-Writer project adds libpng and zlib as submodules, but PNGwriter just relies on those two libraries being installed.

I understand I can add Findzlib.cmake and Findpng.cmake dummies so that CMake wouldn’t complain when processing PNGwriter’s CMakeLists.txt file (I got to that point just by using two empty dummies).

But I also understand I will have to do some work in those dummies:

  1. Set some variables: zlib_FOUND, zlib_INCLUDE_DIRS, zlib_LIBRARIES?
  2. Make them point to wherever that include dir and lib are going to be generated: pdfwriter_SOURCE_DIR/Zlib and pdfwriter_BINARY_DIR/Zlib/Zlib.lib?

I don’t have a suitable example file to point you at. Taking curl as an example, you would have to find an existing curl-config.cmake or similar file from an installed curl. That should show you all the things it normally defines (targets and variables). Anything that your project uses from that are the things that your own dummy Findcurl.cmake file would have to define somehow. I know that’s a bit vague, but that’s the best I can offer right now.

1 Like