diff --git a/recipes/picohttpparser/all/conandata.yml b/recipes/picohttpparser/all/conandata.yml new file mode 100644 index 0000000000000..fd9e7caca1336 --- /dev/null +++ b/recipes/picohttpparser/all/conandata.yml @@ -0,0 +1,9 @@ +sources: + "cci.20230804": + url: "https://github.com/h2o/picohttpparser/archive/066d2b1e9ab820703db0837a7255d92d30f0c9f5.tar.gz" + sha256: "637ff2ab6f5c7f7e05a5b5dc393d5cf2fea8d4754fcaceaaf935ffff5c1323ee" +patches: + "cci.20230804": + - patch_file: "patches/cci.20230804-0001-add-cmake.patch" + patch_description: "add CMakeLists.txt" + patch_type: "conan" diff --git a/recipes/picohttpparser/all/conanfile.py b/recipes/picohttpparser/all/conanfile.py new file mode 100644 index 0000000000000..9881be76dfb27 --- /dev/null +++ b/recipes/picohttpparser/all/conanfile.py @@ -0,0 +1,43 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.files import get, apply_conandata_patches, export_conandata_patches +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout +from conan.tools.layout import basic_layout + +required_conan_version = ">=1.51.1" + + +class PicohttpparserConan(ConanFile): + name = "picohttpparser" + description = "tiny HTTP parser written in C (used in HTTP::Parser::XS et al.)" + url = "https://github.com/conan-io/conan-center-index" + license = "MIT" + homepage = "https://github.com/h2o/picohttpparser" + topics = ("http", "parser") + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = {"shared": [True, False], "fPIC": [True, False]} + default_options = {"shared": False, "fPIC": True} + + def layout(self): + cmake_layout(self, src_folder="src") + + def export_sources(self): + export_conandata_patches(self) + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def package(self): + cmake = CMake(self) + cmake.install() + + def generate(self): + tc = CMakeToolchain(self) + tc.generate() + + def build(self): + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() + cmake.build() diff --git a/recipes/picohttpparser/all/patches/cci.20230804-0001-add-cmake.patch b/recipes/picohttpparser/all/patches/cci.20230804-0001-add-cmake.patch new file mode 100644 index 0000000000000..8c9453be4a108 --- /dev/null +++ b/recipes/picohttpparser/all/patches/cci.20230804-0001-add-cmake.patch @@ -0,0 +1,25 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +new file mode 100644 +index 0000000..45a748c +--- /dev/null ++++ b/CMakeLists.txt +@@ -0,0 +1,19 @@ ++cmake_minimum_required(VERSION 3.16) ++project(picohttpparser) ++ ++# Set the C standard ++set(CMAKE_C_STANDARD 99) ++ ++# Build the library from picohttpparser.c ++add_library(picohttpparser STATIC picohttpparser.c) ++ ++# Include the current directory to find picohttpparser.h ++target_include_directories(picohttpparser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) ++ ++# Install the library and headers ++install(TARGETS picohttpparser ++ ARCHIVE DESTINATION lib ++ LIBRARY DESTINATION lib) ++install ( ++ FILES picohttpparser.h ++ DESTINATION include) diff --git a/recipes/picohttpparser/all/test_package/CMakeLists.txt b/recipes/picohttpparser/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..e7a32ea861214 --- /dev/null +++ b/recipes/picohttpparser/all/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.12) +project(test_package LANGUAGES CXX) + +find_package(picohttpparser REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE picohttpparser::picohttpparser) diff --git a/recipes/picohttpparser/all/test_package/conanfile.py b/recipes/picohttpparser/all/test_package/conanfile.py new file mode 100644 index 0000000000000..a9fb96656f203 --- /dev/null +++ b/recipes/picohttpparser/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + 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") diff --git a/recipes/picohttpparser/all/test_package/test_package.cpp b/recipes/picohttpparser/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..d4590c003d598 --- /dev/null +++ b/recipes/picohttpparser/all/test_package/test_package.cpp @@ -0,0 +1,41 @@ +#include +#include +#include + +#define REQ \ + "GET /wp-content/uploads/2010/03/hello-kitty-darth-vader-pink.jpg " \ + "HTTP/1.1\r\n" \ + "Host: www.kittyhell.com\r\n" \ + "User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ja-JP-mac; " \ + "rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 " \ + "Pathtraq/0.9\r\n" \ + "Accept: " \ + "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" \ + "Accept-Language: ja,en-us;q=0.7,en;q=0.3\r\n" \ + "Accept-Encoding: gzip,deflate\r\n" \ + "Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\r\n" \ + "Keep-Alive: 115\r\n" \ + "Connection: keep-alive\r\n" \ + "Cookie: wp_ozh_wsa_visits=2; wp_ozh_wsa_visit_lasttime=xxxxxxxxxx; " \ + "__utma=xxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.x; " \ + "__utmz=xxxxxxxxx.xxxxxxxxxx.x.x.utmccn=(referral)|utmcsr=reader." \ + "livedoor.com|utmcct=/reader/|utmcmd=referral\r\n" \ + "\r\n" + +int main(int argc, char **) { + const char *method; + size_t method_len; + const char *path; + size_t path_len; + int minor_version; + struct phr_header headers[32]; + size_t num_headers; + int i, ret; + + num_headers = sizeof(headers) / sizeof(headers[0]); + ret = + phr_parse_request(REQ, sizeof(REQ) - 1, &method, &method_len, &path, + &path_len, &minor_version, headers, &num_headers, 0); + assert(ret == sizeof(REQ) - 1); + return 0; +} diff --git a/recipes/picohttpparser/all/test_v1_package/CMakeLists.txt b/recipes/picohttpparser/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..9652e22fc19d5 --- /dev/null +++ b/recipes/picohttpparser/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.12) + +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/picohttpparser/all/test_v1_package/conanfile.py b/recipes/picohttpparser/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..5a05af3c2dfd2 --- /dev/null +++ b/recipes/picohttpparser/all/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +from conans import ConanFile, CMake +from conan.tools.build import cross_building +import os + + +class TestPackageV1Conan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/picohttpparser/config.yml b/recipes/picohttpparser/config.yml new file mode 100644 index 0000000000000..2624f552c9442 --- /dev/null +++ b/recipes/picohttpparser/config.yml @@ -0,0 +1,3 @@ +versions: + "cci.20230804": + folder: all