Skip to content

Commit

Permalink
Merge pull request #173 from jgsogo/recipe/nghttp2
Browse files Browse the repository at this point in the history
Add libnghttp2
  • Loading branch information
lasote authored Oct 24, 2019
2 parents 01f3d33 + 2ae8eb3 commit f3ab6d4
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/libnghttp2/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)
project(cmake_wrapper)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup()

add_subdirectory("source_subfolder")
4 changes: 4 additions & 0 deletions recipes/libnghttp2/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.39.2":
sha256: 92a23e4522328c8565028ee0c7270e74add7990614fd1148f2a79d873bc2a1d0
url: https://github.com/nghttp2/nghttp2/releases/download/v1.39.2/nghttp2-1.39.2.tar.bz2
152 changes: 152 additions & 0 deletions recipes/libnghttp2/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import os
from conans import ConanFile, CMake, AutoToolsBuildEnvironment, tools
from conans.errors import ConanInvalidConfiguration


class Nghttp2Conan(ConanFile):
name = "libnghttp2"
description = "HTTP/2 C Library and tools"
topics = ("conan", "http")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://nghttp2.org"
license = "MIT"
exports_sources = ["CMakeLists.txt"]
generators = "cmake", "pkg_config"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False],
"fPIC": [True, False],
"with_app": [True, False],
"with_hpack": [True, False],
"with_asio": [True, False]}
default_options = {"shared": False,
"fPIC": True,
"with_app": True,
"with_hpack": True,
"with_asio": False}

_source_subfolder = "source_subfolder"

def configure(self):
if self.settings.compiler == "gcc":
v = tools.Version(str(self.settings.compiler.version))
if v < "6.0":
raise ConanInvalidConfiguration("gcc >= 6.0 required")

def config_options(self):
if self.settings.os == 'Windows':
del self.options.fPIC
if self.options.with_asio and self.settings.compiler == "Visual Studio":
raise ConanInvalidConfiguration("Build with asio and MSVC is not supported yet, see upstream bug #589")

def requirements(self):
self.requires.add("zlib/1.2.11")
if self.options.with_app:
self.requires.add("openssl/1.0.2t")
self.requires.add("c-ares/1.15.0")
self.requires.add("libev/4.25")
self.requires.add("libxml2/2.9.9")
if self.options.with_hpack:
self.requires.add("jansson/2.12")
if self.options.with_asio:
self.requires.add("boost/1.70.0")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_folder = "nghttp2-{0}".format(self.version)
os.rename(extracted_folder, self._source_subfolder)

def _configure_cmake(self):
cmake = CMake(self)

cmake.definitions["ENABLE_SHARED_LIB"] = "ON" if self.options.shared else "OFF"
cmake.definitions["ENABLE_STATIC_LIB"] = "OFF" if self.options.shared else "ON"
cmake.definitions["ENABLE_HPACK_TOOLS"] = "ON" if self.options.with_hpack else "OFF"
cmake.definitions["ENABLE_APP"] = "ON" if self.options.with_app else "OFF"
cmake.definitions["ENABLE_EXAMPLES"] = "OFF"
cmake.definitions["ENABLE_PYTHON_BINDINGS"] = "OFF"
cmake.definitions["ENABLE_FAILMALLOC"] = "OFF"
# disable unneeded auto-picked dependencies
cmake.definitions["WITH_LIBXML2"] = "OFF"
cmake.definitions["WITH_JEMALLOC"] = "OFF"
cmake.definitions["WITH_SPDYLAY"] = "OFF"

cmake.definitions["ENABLE_ASIO_LIB"] = "ON" if self.options.with_asio else "OFF"

if self.options.with_app:
cmake.definitions['OPENSSL_ROOT_DIR'] = self.deps_cpp_info['openssl'].rootpath
if self.options.with_asio:
cmake.definitions['BOOST_ROOT'] = self.deps_cpp_info['boost'].rootpath
cmake.definitions['ZLIB_ROOT'] = self.deps_cpp_info['zlib'].rootpath

cmake.configure()
return cmake

def _build_with_autotools(self):
if self.options.with_app:
os.rename('c-ares.pc', 'libcares.pc')

prefix = os.path.abspath(self.package_folder)
with tools.chdir(self._source_subfolder):
env_build = AutoToolsBuildEnvironment(self)
if self.settings.os == 'Windows':
prefix = tools.unix_path(prefix)
args = []
if self.options.shared:
args.extend(['--disable-static', '--enable-shared'])
else:
args.extend(['--disable-shared', '--enable-static'])
if self.options.with_hpack:
args.append('--enable-hpack-tools')
else:
args.append('--disable-hpack-tools')

if self.options.with_app:
args.append('--enable-app')
else:
args.append('--disable-app')

args.append('--disable-examples')
args.append('--disable-python-bindings')
# disable unneeded auto-picked dependencies
args.append('--without-jemalloc')
args.append('--without-systemd')
args.append('--without-libxml2')

if self.options.with_asio:
args.append('--enable-asio-lib')
args.append('--with-boost=' + self.deps_cpp_info['boost'].rootpath)
else:
args.append('--without-boost')

env_build.configure(args=args)
env_build.make()
env_build.make(args=['install'])

def build(self):
if self.settings.compiler == "Visual Studio":
cmake = self._configure_cmake()
cmake.build()
else:
self._build_with_autotools()

def package(self):
self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
if self.settings.compiler == "Visual Studio":
cmake = self._configure_cmake()
cmake.install()
cmake.patch_config_paths()

# remove unneeded directories
tools.rmdir(os.path.join(self.package_folder, 'share'))
tools.rmdir(os.path.join(self.package_folder, 'lib', 'pkgconfig'))

for la_name in ('libnghttp2.la', 'libnghttp2_asio.la'):
la_file = os.path.join(self.package_folder, "lib", la_name)
if os.path.isfile(la_file):
os.unlink(la_file)

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.compiler == 'Visual Studio':
if not self.options.shared:
self.cpp_info.defines.append('NGHTTP2_STATICLIB')
11 changes: 11 additions & 0 deletions recipes/libnghttp2/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 2.8.12)
project(test_package)

set(CMAKE_VERBOSE_MAKEFILE TRUE)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
19 changes: 19 additions & 0 deletions recipes/libnghttp2/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-

from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

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

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
21 changes: 21 additions & 0 deletions recipes/libnghttp2/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <cstdio>

#if defined(_MSC_VER)
// nghttp2 defaults to int
typedef int ssize_t;
#endif
#include <nghttp2/nghttp2.h>
#include <nghttp2/nghttp2ver.h>

int main()
{
nghttp2_info* info = nghttp2_version(NGHTTP2_VERSION_NUM);
if (info) {
printf("nghttp2 ver=%d version=%s\n", info->version_num, info->version_str);
} else {
printf("nghttp2: cannot get version\n");
}
return 0;
}

// vim: et ts=4 sw=4
3 changes: 3 additions & 0 deletions recipes/libnghttp2/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.39.2":
folder: all

0 comments on commit f3ab6d4

Please sign in to comment.