Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for cpr 1.6.2 #5353

Merged
merged 11 commits into from
May 12, 2021
7 changes: 7 additions & 0 deletions recipes/cpr/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ sources:
"1.6.0":
sha256: "5a20a9f014b47988f5230d008174e5db2b33f8c547df825e6beae0c78fc05a9e"
url: https://github.com/whoshuu/cpr/archive/1.6.0.tar.gz
"1.6.2":
sha256: "c45f9c55797380c6ba44060f0c73713fbd7989eeb1147aedb8723aa14f3afaa3"
url: https://github.com/whoshuu/cpr/archive/1.6.2.tar.gz

patches:
"1.3.0":
- patch_file: "patches/001-fix-curl-define.patch"
Expand All @@ -39,3 +43,6 @@ patches:
base_path: "source_subfolder"
- patch_file: "patches/007-patch-sanitizer.patch"
base_path: "source_subfolder"
"1.6.2":
- patch_file: "patches/008-fix-curl-components.patch"
base_path: "source_subfolder"
39 changes: 34 additions & 5 deletions recipes/cpr/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ class CprConan(ConanFile):
"fPIC": [True, False],
"with_openssl": [True, False],
"with_winssl": [True, False],
"with_darwinssl": [True, False],
"no_ssl": [True, False],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was afraid of this...

Can we copy the curl recipe and use an with_ssl and provide string options? and deprecate the older two?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know, that makes total sense, and frankly I don't know why I didn't think about it. Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a proper way to deprecate options, by the way? I took a quick peek at the docs and didn't see it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5020 We just wrote it recently 🎉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh awesome! Will flip to using that way

}
default_options = {
"shared": False,
"fPIC": True,
"with_openssl": True,
"with_winssl": False,
"with_darwinssl": False,
"no_ssl": False,
}

_cmake = None
Expand All @@ -40,13 +44,23 @@ def _build_subfolder(self):
def _supports_openssl(self):
# https://github.com/whoshuu/cpr/commit/b036a3279ba62720d1e43362d32202bf412ea152
# https://github.com/whoshuu/cpr/releases/tag/1.5.0
return tools.Version(self.version) >= "1.5.0"
return tools.Version(self.version) >= "1.5.0" and not tools.is_apple_os(self.settings.os)

@property
def _supports_winssl(self):
# https://github.com/whoshuu/cpr/commit/18e1fc5c3fc0ffc07695f1d78897fb69e7474ea9
# https://github.com/whoshuu/cpr/releases/tag/1.5.1
return tools.Version(self.version) >= "1.5.1"
return tools.Version(self.version) >= "1.5.1" and self.settings.os == "Windows"

@property
def _supports_darwinssl(self):
# https://github.com/whoshuu/cpr/releases/tag/1.6.1
return tools.Version(self.version) >= "1.6.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return tools.Version(self.version) >= "1.6.1"
return tools.Version(self.version) >= "1.6.1" and tools.is_apple_os(self.settings.os)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read this change and I could have SWORN I already did it. Guess not, lol. On it.


@property
def _can_disable_ssl(self):
# https://github.com/whoshuu/cpr/releases/tag/1.6.0
return not self._uses_old_cmake_options

@property
def _uses_old_cmake_options(self):
Expand Down Expand Up @@ -74,6 +88,8 @@ def configure(self):
del self.options.with_openssl
if not self._supports_winssl:
del self.options.with_winssl
if not self._supports_darwinssl:
del self.options.with_darwinssl

# Make sure libcurl uses the same SSL implementation
if self.options.get_safe("with_openssl", False):
Expand All @@ -82,6 +98,8 @@ def configure(self):
if self.options.get_safe("with_winssl", False):
# self.options["libcurl"].with_winssl = True # deprecated in https://github.com/conan-io/conan-center-index/pull/2880
self.options["libcurl"].with_ssl = "schannel"
if self.options.get_safe("with_darwinssl", False):
self.options["libcurl"].with_ssl = "darwinssl"


def source(self):
Expand Down Expand Up @@ -120,27 +138,38 @@ def _configure_cmake(self):
self._cmake.definitions[self._get_cmake_option("CPR_BUILD_TESTS")] = False
self._cmake.definitions[self._get_cmake_option("CPR_GENERATE_COVERAGE")] = False
self._cmake.definitions[self._get_cmake_option("CPR_USE_SYSTEM_GTEST")] = False

if self._supports_openssl:
self._cmake.definitions["CMAKE_USE_OPENSSL"] = self.options.get_safe("with_openssl", False)

if self._supports_darwinssl:
self._cmake.definitions[self._get_cmake_option("CPR_FORCE_DARWINSSL_BACKEND")] = self.options.get_safe("with_darwinssl", False)

if self._supports_winssl: # The CMake options changed
# https://github.com/whoshuu/cpr/commit/18e1fc5c3fc0ffc07695f1d78897fb69e7474ea9#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aR39-R40
self._cmake.definitions[self._get_cmake_option("CPR_FORCE_OPENSSL_BACKEND")] = self.options.get_safe("with_openssl", False)
self._cmake.definitions[self._get_cmake_option("CPR_FORCE_WINSSL_BACKEND")] = self.options.get_safe("with_winssl", False)

supports_any_ssl = self.options.get_safe("with_openssl", False) or self.options.get_safe("with_winssl", False)
if not self._uses_old_cmake_options and not supports_any_ssl:
if self._can_disable_ssl and self.options.get_safe("no_ssl", False):
self._cmake.definitions["CPR_ENABLE_SSL"] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def validate(self):
if not self._uses_valid_abi_and_compiler:
raise ConanInvalidConfiguration("Cannot compile CPR/1.6.0 with libstdc++ on clang < 9")
raise ConanInvalidConfiguration("Cannot compile cpr/1.6.0 with libstdc++ on clang < 9")

if not self._can_disable_ssl and self.options.get_safe("no_ssl", False):
# https://github.com/whoshuu/cpr/issues/546
raise ConanInvalidConfiguration("cpr < 1.6.0 cannot manually disable SSL.")

if self.options.get_safe("with_openssl", False) and tools.is_apple_os(self.settings.os):
# https://github.com/whoshuu/cpr/issues/546
raise ConanInvalidConfiguration("cpr cannot be built on macOS with openssl")

if self.options.get_safe("with_darwinssl", False) and not tools.is_apple_os(self.settings.os):
raise ConanInvalidConfiguration("cpr only supports darwinssl on macOS")

if self.options.get_safe("with_winssl", False) and self.settings.os != "Windows":
raise ConanInvalidConfiguration("cpr only supports winssl on Windows")

Expand Down
36 changes: 36 additions & 0 deletions recipes/cpr/all/patches/008-fix-curl-components.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -120,29 +120,11 @@ endif()

# Curl configuration
if(CPR_FORCE_USE_SYSTEM_CURL)
- if(CPR_ENABLE_SSL)
- find_package(CURL COMPONENTS HTTP HTTPS SSL)
- if(CURL_FOUND)
- message(STATUS "Curl ${CURL_VERSION_STRING} found on this system.")
- # To be able to load certificates under Windows when using OpenSSL:
- if(CMAKE_USE_OPENSSL AND WIN32 AND (NOT (CURL_VERSION_STRING VERSION_GREATER_EQUAL "7.71.0")))
- message(FATAL_ERROR "Your system curl version (${CURL_VERSION_STRING}) is too old to support OpenSSL on Windows which requires curl >= 7.71.0. Update your curl version, use WinSSL, disable SSL or use the build in version of curl.")
- endif()
- else()
- find_package(CURL COMPONENTS HTTP)
- if(CURL_FOUND)
- message(FATAL_ERROR "Curl found on this system but WITHOUT HTTPS/SSL support. Either disable SSL by setting CPR_ENABLE_SSL to OFF or use the build in version of curl by setting CPR_FORCE_USE_SYSTEM_CURL to OFF.")
- else()
- message(FATAL_ERROR "Curl not found on this system. To use the build in version set CPR_FORCE_USE_SYSTEM_CURL to OFF.")
- endif()
- endif()
+ find_package(CURL)
+ if(CURL_FOUND)
+ message(STATUS "Curl found on this system.")
else()
- find_package(CURL COMPONENTS HTTP)
- if(CURL_FOUND)
- message(STATUS "Curl found on this system.")
- else()
- message(FATAL_ERROR "Curl not found on this system. To use the build in version set CPR_FORCE_USE_SYSTEM_CURL to OFF.")
- endif()
+ message(FATAL_ERROR "Curl not found on this system. To use the build in version set CPR_FORCE_USE_SYSTEM_CURL to OFF.")
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use find_package(REQUIRED) here?

else()
message(STATUS "Configuring build in curl...")
2 changes: 2 additions & 0 deletions recipes/cpr/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ versions:
folder: all
"1.6.0":
folder: all
"1.6.2":
folder: all