@@ -26,14 +26,21 @@ if(NOT USE_SYSTEM_CPR)
2626
2727 # if a system provided installed libcurl is too "new", we want to have CPR build its own
2828 # otherwise, we want to use the system provided library
29- # this way, we can build against a system-wide libcurl on older systems (e.g., Ubuntu focal) while allowing development on newer systems
30- # see
31- find_package (CURL)
32- if (CURL_FOUND)
33- message (STATUS "Found libcurl ${CURL_VERSION_STRING} " )
29+ # this way, we can build against a system-wide libcurl on older systems (e.g., Ubuntu focal) while
30+ # allowing development on newer systems
31+ # see https://github.com/libcpr/cpr/issues/804
32+ # note: don't use find_package(CURL), for some reason it'd cause zsync2 to link to the system libcurl in
33+ # addition to the statically linked CPR; we just need the version
34+ find_package (PkgConfig REQUIRED)
35+ pkg_search_module(PKGCONFIG_CURL libcurl)
36+ set (PKGCONFIG_CURL_FOUND ${PKGCONFIG_CURL_FOUND} PARENT_SCOPE)
37+ set (PKGCONFIG_CURL_VERSION ${PKGCONFIG_CURL_VERSION} PARENT_SCOPE)
38+
39+ if (PKGCONFIG_CURL_FOUND)
40+ message (STATUS "Found libcurl ${PKGCONFIG_CURL_VERSION} " )
3441
3542 if (NOT DEFINED CPR_FORCE_USE_SYSTEM_CURL)
36- if (CURL_VERSION_STRING VERSION_LESS_EQUAL 7.80.0)
43+ if (PKGCONFIG_CURL_VERSION VERSION_LESS_EQUAL 7.80.0)
3744 message (STATUS "libcurl is old enough to work with CPR, so we use the system one (use -DCPR_FORCE_USE_SYSTEM_CURL=OFF to change this behavior)" )
3845 set (CPR_FORCE_USE_SYSTEM_CURL ON )
3946 else ()
@@ -43,6 +50,8 @@ if(NOT USE_SYSTEM_CPR)
4350 else ()
4451 message (WARNING "CPR_FORCE_USE_SYSTEM_CURL is set to ${CPR_FORCE_USE_SYSTEM_CURL} by the user" )
4552 endif ()
53+ else ()
54+ message (WARNING "Could not find libcurl with pkg-config, relying on CPR auto-configuration" )
4655 endif ()
4756
4857 include (FetchContent)
0 commit comments