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

restbed: add restbed/4.8 recipe #13561

Merged
merged 14 commits into from
Oct 22, 2022
12 changes: 12 additions & 0 deletions recipes/restbed/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sources:
"4.8":
url: "https://github.com/Corvusoft/restbed/archive/refs/tags/4.8.tar.gz"
sha256: "4801833f86a67b8a123c2c01203e259eb81157e1e9ef144a3b6395cb2d838a42"
patches:
madebr marked this conversation as resolved.
Show resolved Hide resolved
"4.8":
- patch_file: "patches/4.8-0001-cmake-conan.patch"
patch_description: "Use CMake targets + separate static/shared"
patch_type: "conan"
- patch_file: "patches/4.8-0002-mingw-deprecated-fix.patch"
patch_description: "MinGW apparently does not support deprecated and __declspec in the same line"
patch_type: "portability"
112 changes: 112 additions & 0 deletions recipes/restbed/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from conan import ConanFile
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, load, rm, save
from conan.tools.build import check_min_cppstd
import os
import re

required_conan_version = ">=1.52.0"


class RestbedConan(ConanFile):
name = "restbed"
homepage = "https://github.com/Corvusoft/restbed"
description = "Corvusoft's Restbed framework brings asynchronous RESTful functionality to C++14 applications."
topics = ("restful", "server", "client", "json", "http", "ssl", "tls")
url = "https://github.com/conan-io/conan-center-index"
license = "AGPL-3.0-or-later", "CPL" # Corvusoft Permissive License (CPL)
madebr marked this conversation as resolved.
Show resolved Hide resolved

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"ipc": [True, False],
"with_openssl": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"ipc": False,
"with_openssl": True,
}

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:
try:
del self.options.fPIC
except Exception:
pass
if self.settings.os in ("Windows", ):
del self.options.ipc

def validate(self):
if getattr(self.info.settings.compiler, "cppstd"):
check_min_cppstd(self, 14)
madebr marked this conversation as resolved.
Show resolved Hide resolved
if self.info.settings.compiler == "gcc":
if self.info.settings.compiler.version < Version(5):
raise ConanInvalidConfiguration("gcc 5+ is required for c++14 support")

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

def requirements(self):
self.requires("asio/1.24.0")
if self.options.with_openssl:
self.requires("openssl/3.0.5")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_TESTS"] = False
tc.variables["BUILD_SSL"] = self.options.with_openssl
tc.variables["BUILD_IPC"] = self.options.get_safe("ipc", False)
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def _patch_sources(self):
apply_conandata_patches(self)
if not self.options.shared:
# Remove __declspec(dllexport) and __declspec(dllimport)
for root, _, files in os.walk(self.source_folder):
for file in files:
if os.path.splitext(file)[1] in (".hpp", ".h"):
full_path = os.path.join(root, file)
data = load(self, full_path)
data, _ = re.subn(r"__declspec\((dllexport|dllimport)\)", "", data)
save(self, full_path, data)

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

def package(self):
copy(self, "LICENSE*", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
libname = "restbed"
if self.settings.os in ("Windows", ) and self.options.shared:
libname += "-shared"
self.cpp_info.libs = [libname]

if self.settings.os in ("FreeBSD", "Linux", ):
self.cpp_info.system_libs.extend(["dl", "m"])
elif self.settings.os in ("Windows", ):
self.cpp_info.system_libs.append("mswsock")
84 changes: 84 additions & 0 deletions recipes/restbed/all/patches/4.8-0001-cmake-conan.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -19,7 +19,7 @@
option( BUILD_TESTS "Build unit tests." ON )
option( BUILD_SSL "Build secure socket layer support." ON )
option( BUILD_IPC "Build unix domain socket layer support." OFF )
-
+set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
#
# Configuration
#
@@ -57,7 +57,7 @@ find_package( asio REQUIRED )

if ( BUILD_SSL )
add_definitions( "-DBUILD_SSL" )
- find_package( openssl REQUIRED )
+ find_package( OpenSSL REQUIRED )
endif ( )

include_directories( ${INCLUDE_DIR} SYSTEM ${asio_INCLUDE} ${ssl_INCLUDE} )
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -68,7 +68,7 @@

if ( WIN32 )
add_definitions( -DWIN_DLL_EXPORT )
- set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251" )
+ #set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251" )
endif ( )

#
@@ -75,13 +75,14 @@
# Build
#
file( GLOB_RECURSE MANIFEST "${SOURCE_DIR}/*.cpp" )
-
+if(NOT BUILD_SHARED_LIBS)
set( STATIC_LIBRARY_NAME "${PROJECT_NAME}-static" )
add_library( ${STATIC_LIBRARY_NAME} STATIC ${MANIFEST} )
set_property( TARGET ${STATIC_LIBRARY_NAME} PROPERTY CXX_STANDARD 14 )
set_property( TARGET ${STATIC_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON )
set_target_properties( ${STATIC_LIBRARY_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME} )
-
+target_link_libraries( ${STATIC_LIBRARY_NAME} LINK_PRIVATE asio::asio )
+else()
set( SHARED_LIBRARY_NAME "${PROJECT_NAME}-shared" )
add_library( ${SHARED_LIBRARY_NAME} SHARED ${MANIFEST} )
set_property( TARGET ${SHARED_LIBRARY_NAME} PROPERTY CXX_STANDARD 14 )
@@ -93,13 +94,20 @@
set_target_properties( ${SHARED_LIBRARY_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME} )
endif ( )
set_target_properties( ${SHARED_LIBRARY_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} )
-
+target_link_libraries( ${SHARED_LIBRARY_NAME} LINK_PRIVATE asio::asio )
+endif()
if ( BUILD_SSL )
- target_link_libraries( ${SHARED_LIBRARY_NAME} LINK_PRIVATE ${ssl_LIBRARY_SHARED} ${crypto_LIBRARY_SHARED} )
- target_link_libraries( ${STATIC_LIBRARY_NAME} LINK_PRIVATE ${ssl_LIBRARY_STATIC} ${crypto_LIBRARY_STATIC} ${CMAKE_DL_LIBS} )
+if(BUILD_SHARED_LIBS)
+ target_link_libraries( ${SHARED_LIBRARY_NAME} LINK_PRIVATE OpenSSL::SSL $<$<BOOL:${WIN32}>:mswsock>)
+else()
+ target_link_libraries( ${STATIC_LIBRARY_NAME} LINK_PRIVATE OpenSSL::SSL ${CMAKE_DL_LIBS} $<$<BOOL:${WIN32}>:mswsock>)
+endif()
else ( )
+if(BUILD_SHARED_LIBS)
- target_link_libraries( ${SHARED_LIBRARY_NAME} )
+ target_link_libraries( ${SHARED_LIBRARY_NAME} OpenSSL::SSL $<$<BOOL:${WIN32}>:mswsock>)
+else()
- target_link_libraries( ${STATIC_LIBRARY_NAME} ${CMAKE_DL_LIBS} )
+ target_link_libraries( ${STATIC_LIBRARY_NAME} ${CMAKE_DL_LIBS} OpenSSL::SSL $<$<BOOL:${WIN32}>:mswsock>)
+endif()
endif ( )

if ( BUILD_TESTS )
@@ -119,5 +127,8 @@

install( FILES "${INCLUDE_DIR}/${PROJECT_NAME}" DESTINATION "${CMAKE_INSTALL_PREFIX}/include" )
install( FILES ${ARTIFACTS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/corvusoft/${PROJECT_NAME}" )
+if(NOT BUILD_SHARED_LIBS)
install( TARGETS ${STATIC_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library )
+else()
-install( TARGETS ${SHARED_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library )
+install( TARGETS ${SHARED_LIBRARY_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT library )
+endif()
12 changes: 12 additions & 0 deletions recipes/restbed/all/patches/4.8-0002-mingw-deprecated-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- source/corvusoft/restbed/http.hpp
+++ source/corvusoft/restbed/http.hpp
@@ -40,7 +40,7 @@
class Response;
class Settings;
-
- class [[deprecated("HTTP client is deprecated; we will release a complimentary client framework at a future date.")]] HTTP_EXPORT Http
+ class HTTP_EXPORT Http;
+ class [[deprecated("HTTP client is deprecated; we will release a complimentary client framework at a future date.")]] Http
{
public:
//Friends
8 changes: 8 additions & 0 deletions recipes/restbed/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(restbed REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE restbed::restbed)
madebr marked this conversation as resolved.
Show resolved Hide resolved
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
30 changes: 30 additions & 0 deletions recipes/restbed/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
import os


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

def layout(self):
cmake_layout(self)

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

def generate(self):
tc = CMakeToolchain(self)
tc.generate()

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")
40 changes: 40 additions & 0 deletions recipes/restbed/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <restbed>

#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cstring>

static void post_method_handler( const std::shared_ptr< restbed::Session > session )
{
const auto request = session->get_request( );

int content_length = request->get_header( "Content-Length", 0 );

session->fetch( content_length, [ ]( const std::shared_ptr< restbed::Session > session, const restbed::Bytes & body )
{
fprintf( stdout, "%.*s\n", ( int ) body.size( ), body.data( ) );
session->close( restbed::OK, "Hello, World!", { { "Content-Length", "13" } } );
} );
}

int main(int argc, char *argv[])
{
auto resource = std::make_shared< restbed::Resource >( );
resource->set_path( "/resource" );
resource->set_method_handler( "POST", post_method_handler );

auto settings = std::make_shared< restbed::Settings >( );
settings->set_port( 1984 );
settings->set_default_header( "Connection", "close" );

restbed::Service service;
service.publish( resource );

if (argc > 1 && strcmp(argv[1], "run") == 0) {
// Don't start the service to avoid blocking
service.start( settings );
}

return EXIT_SUCCESS;
}
11 changes: 11 additions & 0 deletions recipes/restbed/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

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

find_package(restbed REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE restbed::restbed)
madebr marked this conversation as resolved.
Show resolved Hide resolved
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
17 changes: 17 additions & 0 deletions recipes/restbed/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)
3 changes: 3 additions & 0 deletions recipes/restbed/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"4.8":
folder: all