diff --git a/recipes/restbed/all/conandata.yml b/recipes/restbed/all/conandata.yml new file mode 100644 index 0000000000000..6e0b42fcccc44 --- /dev/null +++ b/recipes/restbed/all/conandata.yml @@ -0,0 +1,12 @@ +sources: + "4.8": + url: "https://github.com/Corvusoft/restbed/archive/refs/tags/4.8.tar.gz" + sha256: "4801833f86a67b8a123c2c01203e259eb81157e1e9ef144a3b6395cb2d838a42" +patches: + "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" diff --git a/recipes/restbed/all/conanfile.py b/recipes/restbed/all/conanfile.py new file mode 100644 index 0000000000000..0a5e2d6cfc925 --- /dev/null +++ b/recipes/restbed/all/conanfile.py @@ -0,0 +1,128 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +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.microsoft import is_msvc +from conan.tools.scm import Version +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", "LicenseRef-CPL" # Corvusoft Permissive License (CPL) + + 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, + } + + @property + def _minimum_cpp_standard(self): + return 14 + + @property + def _compilers_minimum_version(self): + return { + "gcc": "5", + "clang": "7", + "apple-clang": "10", + } + + 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, self._minimum_cpp_standard) + if not is_msvc(self): + minimum_version = self._compilers_minimum_version.get(str(self.info.settings.compiler), False) + if minimum_version and Version(self.info.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._minimum_cpp_standard}, which your compiler does not 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") diff --git a/recipes/restbed/all/patches/4.8-0001-cmake-conan.patch b/recipes/restbed/all/patches/4.8-0001-cmake-conan.patch new file mode 100644 index 0000000000000..e239976a0dfce --- /dev/null +++ b/recipes/restbed/all/patches/4.8-0001-cmake-conan.patch @@ -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 $<$:mswsock>) ++else() ++ target_link_libraries( ${STATIC_LIBRARY_NAME} LINK_PRIVATE OpenSSL::SSL ${CMAKE_DL_LIBS} $<$:mswsock>) ++endif() + else ( ) ++if(BUILD_SHARED_LIBS) +- target_link_libraries( ${SHARED_LIBRARY_NAME} ) ++ target_link_libraries( ${SHARED_LIBRARY_NAME} OpenSSL::SSL $<$:mswsock>) ++else() +- target_link_libraries( ${STATIC_LIBRARY_NAME} ${CMAKE_DL_LIBS} ) ++ target_link_libraries( ${STATIC_LIBRARY_NAME} ${CMAKE_DL_LIBS} OpenSSL::SSL $<$: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() diff --git a/recipes/restbed/all/patches/4.8-0002-mingw-deprecated-fix.patch b/recipes/restbed/all/patches/4.8-0002-mingw-deprecated-fix.patch new file mode 100644 index 0000000000000..98f35027afdd1 --- /dev/null +++ b/recipes/restbed/all/patches/4.8-0002-mingw-deprecated-fix.patch @@ -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 diff --git a/recipes/restbed/all/test_package/CMakeLists.txt b/recipes/restbed/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..3bad6b5f5053d --- /dev/null +++ b/recipes/restbed/all/test_package/CMakeLists.txt @@ -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) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) diff --git a/recipes/restbed/all/test_package/conanfile.py b/recipes/restbed/all/test_package/conanfile.py new file mode 100644 index 0000000000000..f72d1f660e19f --- /dev/null +++ b/recipes/restbed/all/test_package/conanfile.py @@ -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") diff --git a/recipes/restbed/all/test_package/test_package.cpp b/recipes/restbed/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..d4731f4f97f74 --- /dev/null +++ b/recipes/restbed/all/test_package/test_package.cpp @@ -0,0 +1,40 @@ +#include + +#include +#include +#include +#include + +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; +} diff --git a/recipes/restbed/all/test_v1_package/CMakeLists.txt b/recipes/restbed/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..87b1318ff1676 --- /dev/null +++ b/recipes/restbed/all/test_v1_package/CMakeLists.txt @@ -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) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) diff --git a/recipes/restbed/all/test_v1_package/conanfile.py b/recipes/restbed/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/restbed/all/test_v1_package/conanfile.py @@ -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) diff --git a/recipes/restbed/config.yml b/recipes/restbed/config.yml new file mode 100644 index 0000000000000..5a6e56bf2599d --- /dev/null +++ b/recipes/restbed/config.yml @@ -0,0 +1,3 @@ +versions: + "4.8": + folder: all