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

http_request: new recipe #24778

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/http-request/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0.0":
url: "https://github.com/Nevermore1994/http-request/archive/refs/tags/v1.0.0.zip"
sha256: "20dc2f6c0d7ce6d467f978e8c59fb2d181b571c889a687505c052d139b34c42f"
87 changes: 87 additions & 0 deletions recipes/http-request/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.files import copy, get
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os

required_conan_version = ">=1.50.0"


class CpphttplibConan(ConanFile):
name = "http-request"
description = "A modern C++ lightweight cross-platform HTTP request library."
license = "MIT"
homepage = "https://github.com/Nevermore1994/http-request"
url = "https://github.com/conan-io/conan-center-index"
topics = ("http", "https", "modern C++")
package_type = "header-library"
settings = "os", "arch", "compiler", "build_type"
options = {
"with_openssl": [True, False]
Copy link
Member

Choose a reason for hiding this comment

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

In upstream, this option is called DISABLE_HTTPS, we might want to have symmetry there :)

}
default_options = {
"with_openssl": True,
}
no_copy_source = True

def requirements(self):
if self.options.with_openssl:
self.requires("openssl/[>=1.1 <4]")
Comment on lines +30 to +31
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/Nevermore1994/http-request#notes seems to note that openssl is required in Windows and not optional. Is this right? Should this not be an option to disable it on Windows? Or how does this work? Thanks!


def package_id(self):
self.info.clear()

@property
def _min_cppstd(self):
return 17

@property
def _compilers_minimum_version(self):
return {
"apple-clang": "10",
"clang": "7",
"gcc": "7.1",
"msvc": "192",
"Visual Studio": "15.3",
Comment on lines +37 to +47
Copy link
Member

Choose a reason for hiding this comment

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

There's a missing validate() method to check these values, see the template in https://github.com/conan-io/conan-center-index/blob/master/docs/package_templates/cmake_package/all/conanfile.py#L80 as to how to do it

}

def validate(self):
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def layout(self):
basic_layout(self, src_folder="src")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def build(self):
pass

def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "*.h", src=self.source_folder, dst=os.path.join(self.package_folder, "include", "public"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "http-request")
self.cpp_info.set_property("cmake_target_name", "http-request")
self.cpp_info.includedirs.append(os.path.join("include", "public"))
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
if self.options.with_openssl:
self.cpp_info.defines.append("ENABLE_HTTPS")
if self.settings.os in ["Linux", "FreeBSD", "Macos", "Android", "iOS"]:
self.cpp_info.system_libs = ["pthread"]
elif self.settings.os == "Windows":
self.cpp_info.system_libs = ["crypt32", "cryptui", "ws2_32"]

# TODO: to remove in conan v2 once legacy generators removed
self.cpp_info.names["cmake_find_package"] = "http_request"
self.cpp_info.names["cmake_find_package_multi"] = "http_request"
Comment on lines +85 to +87
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed :)

8 changes: 8 additions & 0 deletions recipes/http-request/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(http-request REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE http-request)
Copy link
Member

Choose a reason for hiding this comment

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

I modified this to be in line with upstream's cmakelist

target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
25 changes: 25 additions & 0 deletions recipes/http-request/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
7 changes: 7 additions & 0 deletions recipes/http-request/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <Request.h>

int main() {
Request::init();
Request::clear();
return 0;
}
3 changes: 3 additions & 0 deletions recipes/http-request/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.0":
folder: all
Loading