Skip to content

Commit

Permalink
(#13628) libnghttp2: add 1.50.0, bump deps
Browse files Browse the repository at this point in the history
* Add nghttp2 1.50.0

* Bump deps

* Update for Conan 2.0

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Remove extra files

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Use rm_safe from 1.53.0

* Revert "Use rm_safe from 1.53.0"

This reverts commit 51ed248.

* Use src for cmake_layout

Co-authored-by: Jordan Williams <jordan@jwillikers.com>

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Jordan Williams <jordan@jwillikers.com>
  • Loading branch information
3 people authored Oct 24, 2022
1 parent f6e9704 commit 2d9b4b8
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 113 deletions.
7 changes: 0 additions & 7 deletions recipes/libnghttp2/all/CMakeLists.txt

This file was deleted.

22 changes: 3 additions & 19 deletions recipes/libnghttp2/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.50.0":
url: "https://github.com/nghttp2/nghttp2/archive/v1.50.0.tar.gz"
sha256: "6de469efc8e9d47059327a6736aebe0a7d73f57e5e37ab4c4f838fb1eebd7889"
"1.49.0":
url: "https://github.com/nghttp2/nghttp2/archive/v1.49.0.tar.gz"
sha256: "744f38f8d6e400a424bf62df449c91e3ffacbae11b5fab99e44a480f5c735ab9"
Expand Down Expand Up @@ -29,48 +32,29 @@ sources:
patches:
"1.49.0":
- patch_file: "patches/fix-findJemalloc.cmake"
base_path: "source_subfolder"
- patch_file: "patches/fix-findLibevent.cmake"
base_path: "source_subfolder"
"1.48.0":
- patch_file: "patches/fix-findJemalloc.cmake"
base_path: "source_subfolder"
- patch_file: "patches/fix-findLibevent.cmake"
base_path: "source_subfolder"
"1.47.0":
- patch_file: "patches/fix-findJemalloc.cmake"
base_path: "source_subfolder"
- patch_file: "patches/fix-findLibevent.cmake"
base_path: "source_subfolder"
"1.46.0":
- patch_file: "patches/fix-findJemalloc.cmake"
base_path: "source_subfolder"
- patch_file: "patches/fix-findLibevent.cmake"
base_path: "source_subfolder"
"1.45.1":
- patch_file: "patches/fix-findJemalloc.cmake"
base_path: "source_subfolder"
- patch_file: "patches/fix-findLibevent.cmake"
base_path: "source_subfolder"
"1.43.0":
- patch_file: "patches/fix-findJemalloc.cmake"
base_path: "source_subfolder"
- patch_file: "patches/fix-findLibevent.cmake"
base_path: "source_subfolder"
"1.42.0":
- patch_file: "patches/fix-findJemalloc.cmake"
base_path: "source_subfolder"
- patch_file: "patches/fix-findLibevent.cmake"
base_path: "source_subfolder"
"1.40.0":
- patch_file: "patches/fix-findJemalloc.cmake"
base_path: "source_subfolder"
- patch_file: "patches/fix-findLibevent.cmake"
base_path: "source_subfolder"
"1.39.2":
- patch_file: "patches/fix-addNghttp2IncludesPathCMake.patch"
base_path: "source_subfolder"
- patch_file: "patches/fix-findJemalloc.cmake"
base_path: "source_subfolder"
- patch_file: "patches/fix-findLibevent.cmake"
base_path: "source_subfolder"
138 changes: 71 additions & 67 deletions recipes/libnghttp2/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import functools
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.gnu import PkgConfigDeps
from conan.tools.scm import Version
from conan.tools.files import export_conandata_patches, apply_conandata_patches, get, save, replace_in_file, rmdir, copy
from conan.tools.microsoft import is_msvc
from conan.tools.apple import is_apple_os
from conan.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.36.0"

required_conan_version = ">=1.52.0"


class Nghttp2Conan(ConanFile):
Expand All @@ -13,7 +19,6 @@ class Nghttp2Conan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://nghttp2.org"
license = "MIT"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -32,34 +37,34 @@ class Nghttp2Conan(ConanFile):
"with_asio": False,
}

generators = "cmake", "cmake_find_package", "pkg_config"

@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):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
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
try:
del self.options.fPIC
except Exception:
pass
if not (self.options.with_app or self.options.with_hpack or self.options.with_asio):
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
try:
del self.settings.compiler.cppstd
except Exception:
pass
try:
del self.settings.compiler.libcxx
except Exception:
pass
if not self.options.with_app:
del self.options.with_jemalloc

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

def requirements(self):
if self.options.with_app or self.options.with_asio:
self.requires("openssl/1.1.1q")
Expand All @@ -68,101 +73,100 @@ def requirements(self):
self.requires("libev/4.33")
self.requires("libevent/2.1.12")
self.requires("libxml2/2.9.14")
self.requires("zlib/1.2.12")
self.requires("zlib/1.2.13")
if self.options.with_jemalloc:
self.requires("jemalloc/5.2.1")
self.requires("jemalloc/5.3.0")
if self.options.with_hpack:
self.requires("jansson/2.14")
if self.options.with_asio:
self.requires("boost/1.79.0")
self.requires("boost/1.80.0")

def validate(self):
if self.options.with_asio and self._is_msvc:
if self.info.options.with_asio and is_msvc(self):
raise ConanInvalidConfiguration("Build with asio and MSVC is not supported yet, see upstream bug #589")
if self.settings.compiler == "gcc" and tools.Version(self.settings.compiler.version) < "6":
raise ConanInvalidConfiguration("gcc >= 6.0 required")
if self.info.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "6":
raise ConanInvalidConfiguration(f"{self.ref} requires GCC >= 6.0")

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

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["ENABLE_SHARED_LIB"] = self.options.shared
cmake.definitions["ENABLE_STATIC_LIB"] = not self.options.shared
cmake.definitions["ENABLE_HPACK_TOOLS"] = self.options.with_hpack
cmake.definitions["ENABLE_APP"] = self.options.with_app
cmake.definitions["ENABLE_EXAMPLES"] = False
cmake.definitions["ENABLE_PYTHON_BINDINGS"] = False
cmake.definitions["ENABLE_FAILMALLOC"] = False
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ENABLE_SHARED_LIB"] = self.options.shared
tc.variables["ENABLE_STATIC_LIB"] = not self.options.shared
tc.variables["ENABLE_HPACK_TOOLS"] = self.options.with_hpack
tc.variables["ENABLE_APP"] = self.options.with_app
tc.variables["ENABLE_EXAMPLES"] = False
tc.variables["ENABLE_PYTHON_BINDINGS"] = False
tc.variables["ENABLE_FAILMALLOC"] = False
# disable unneeded auto-picked dependencies
cmake.definitions["WITH_LIBXML2"] = False
cmake.definitions["WITH_JEMALLOC"] = self.options.get_safe("with_jemalloc", False)
cmake.definitions["WITH_SPDYLAY"] = False

cmake.definitions["ENABLE_ASIO_LIB"] = self.options.with_asio

if tools.Version(self.version) >= "1.42.0":
tc.variables["WITH_LIBXML2"] = False
tc.variables["WITH_JEMALLOC"] = self.options.get_safe("with_jemalloc", False)
tc.variables["WITH_SPDYLAY"] = False
tc.variables["ENABLE_ASIO_LIB"] = self.options.with_asio
if Version(self.version) >= "1.42.0":
# backward-incompatible change in 1.42.0
cmake.definitions["STATIC_LIB_SUFFIX"] = "_static"

if tools.is_apple_os(self.settings.os):
tc.variables["STATIC_LIB_SUFFIX"] = "_static"
if is_apple_os(self):
# workaround for: install TARGETS given no BUNDLE DESTINATION for MACOSX_BUNDLE executable
cmake.definitions["CMAKE_MACOSX_BUNDLE"] = False
tc.cache_variables["CMAKE_MACOSX_BUNDLE"] = False
tc.generate()

cmake.configure()
return cmake
tc = CMakeDeps(self)
tc.generate()
tc = PkgConfigDeps(self)
tc.generate()

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
apply_conandata_patches(self)
if not self.options.shared:
# easier to patch here rather than have patch 'nghttp_static_include_directories' for each version
tools.save(os.path.join(self._source_subfolder, "lib", "CMakeLists.txt"),
save(self, os.path.join(self.source_folder, "lib", "CMakeLists.txt"),
"target_include_directories(nghttp2_static INTERFACE\n"
"${CMAKE_CURRENT_BINARY_DIR}/includes\n"
"${CMAKE_CURRENT_SOURCE_DIR}/includes)\n",
append=True)
target_libnghttp2 = "nghttp2" if self.options.shared else "nghttp2_static"
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"),
replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"),
"\n"
"link_libraries(\n"
" nghttp2\n",
"\n"
"link_libraries(\n"
" {} ${{CONAN_LIBS}}\n".format(target_libnghttp2))
if not self.options.shared:
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"),
replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"),
"\n"
" add_library(nghttp2_asio SHARED\n",
"\n"
" add_library(nghttp2_asio\n")
tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"),
replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"),
"\n"
" target_link_libraries(nghttp2_asio\n"
" nghttp2\n",
"\n"
" target_link_libraries(nghttp2_asio\n"
" {}\n".format(target_libnghttp2))
f" {target_libnghttp2}\n")

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

def package(self):
self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, pattern="COPYING", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "share"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.components["nghttp2"].set_property("pkg_config_name", "libnghttp2")
suffix = "_static" if tools.Version(self.version) > "1.39.2" and not self.options.shared else ""
suffix = "_static" if Version(self.version) > "1.39.2" and not self.options.shared else ""
self.cpp_info.components["nghttp2"].libs = [f"nghttp2{suffix}"]
if self._is_msvc and not self.options.shared:
if is_msvc(self) and not self.options.shared:
self.cpp_info.components["nghttp2"].defines.append("NGHTTP2_STATICLIB")

if self.options.with_asio:
Expand Down
11 changes: 4 additions & 7 deletions recipes/libnghttp2/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

find_package(libnghttp2 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} libnghttp2::libnghttp2)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
target_link_libraries(${PROJECT_NAME} PRIVATE libnghttp2::libnghttp2)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
26 changes: 13 additions & 13 deletions recipes/libnghttp2/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +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_layout, CMake
import os


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

def build_requirements(self):
if self.settings.os == "Macos" and self.settings.arch == "armv8":
# Workaround for CMake bug with error message:
# Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
# set. This could be because you are using a Mac OS X version less than 10.5
# or because CMake's platform configuration is corrupt.
# FIXME: Remove once CMake on macOS/M1 CI runners is upgraded.
self.build_requires("cmake/3.22.0")
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 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")
7 changes: 7 additions & 0 deletions recipes/libnghttp2/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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}/binary_dir/)
17 changes: 17 additions & 0 deletions recipes/libnghttp2/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)
2 changes: 2 additions & 0 deletions recipes/libnghttp2/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"1.50.0":
folder: all
"1.49.0":
folder: all
"1.48.0":
Expand Down

0 comments on commit 2d9b4b8

Please sign in to comment.