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

llhttp: conan v2 support #17447

Merged
merged 1 commit into from
Jun 5, 2023
Merged
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
9 changes: 0 additions & 9 deletions recipes/llhttp/all/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion recipes/llhttp/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ sources:
patches:
"6.0.6":
- patch_file: "patches/cmake_install_dirs.patch"
base_path: "source_subfolder"
74 changes: 27 additions & 47 deletions recipes/llhttp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from conans import ConanFile, tools, CMake
from conan.tools.files import patch
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.53.0"


class LlhttpParserConan(ConanFile):
name = "llhttp"
description = "http request/response parser for c "
description = "http request/response parser for c"
topics = ("http", "parser")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/nodejs/llhttp"
license = ("MIT",)
generators = ("cmake",)
settings = "os", "compiler", "build_type", "arch"
license = "MIT"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -22,66 +23,45 @@ class LlhttpParserConan(ConanFile):
"shared": False,
"fPIC": True,
}
exports_sources = "CMakeLists.txt", "patches/*"

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]
def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def _configure_cmake(self):
if self._cmake:
return self._cmake

self._cmake = CMake(self)
self._cmake.configure()
return self._cmake
def layout(self):
cmake_layout(self, src_folder="src")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy(
"LICENSE-MIT",
src=os.path.join(self.source_folder, self._source_subfolder),
dst="licenses",
)
cmake = self._configure_cmake()
copy(self, "LICENSE-MIT", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "llhttp")
self.cpp_info.set_property("cmake_target_name", "llhttp::llhttp")
self.cpp_info.set_property("pkg_config_name", "libllhttp")
self.cpp_info.libs = ["llhttp"]

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "llhttp"
self.cpp_info.names["cmake_find_package_multi"] = "llhttp"
self.cpp_info.names["pkg_config"] = "libllhttp"
8 changes: 2 additions & 6 deletions recipes/llhttp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
project(test_package LANGUAGES C)

find_package(llhttp REQUIRED CONFIG)


add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} llhttp::llhttp)
target_link_libraries(${PROJECT_NAME} PRIVATE llhttp::llhttp)
21 changes: 15 additions & 6 deletions recipes/llhttp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
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", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

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

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/llhttp/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
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)
17 changes: 17 additions & 0 deletions recipes/llhttp/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(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 tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)