-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create anyRPC from cmake template * Customize template for anyrpc * log4cplus not compatible with wchar option * Fix shared compilation option * Link consumer to ws2_32 * Fix shared compilation on windows * Fix test_v1_package source location * Fix pylint * Fix asan by backporting a fix from the repo * Add pthread on linux * The package requires at least c++11 * Clean template comment * Trigger CI * Revert "Trigger CI" This reverts commit bf82114. * Review: Prefer features based on cmake targets * Review: Try to exercise some method to validate runtime linkage. * Review: Use self.info.options * Review: simplify test_v1_package * Review: try/catch when deleting fpic in configure * Review: link system libm * Review: combine if statements
- Loading branch information
Showing
11 changed files
with
349 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
sources: | ||
"1.0.2": | ||
url: "https://github.com/sgieseking/anyrpc/archive/refs/tags/v1.0.2.tar.gz" | ||
sha256: "236c9fa0ba417af945d950866c9671a1efa06506af8c86efa2e89ab67607969f" | ||
patches: | ||
"1.0.2": | ||
- patch_file: "patches/0001-fix-asan-1.0.2.patch" | ||
patch_description: "Handle ASAN flag properly in CMakeLists.txt" | ||
patch_type: backport | ||
patch_source: "https://github.com/sgieseking/anyrpc/pull/42" | ||
- patch_file: "patches/0002-fix-shared-library-1.0.2.patch" | ||
patch_description: "Fixed 'undefined reference' error when compile for windows platform" | ||
patch_type: backport | ||
patch_source: "https://github.com/sgieseking/anyrpc/pull/43" | ||
- patch_file: "patches/0003-use-conan-libs-1.0.2.patch" | ||
patch_description: "Link to conan libs" | ||
patch_type: "conan" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir | ||
from conan.tools.build import check_min_cppstd | ||
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout | ||
import os | ||
|
||
|
||
required_conan_version = ">=1.52.0" | ||
|
||
|
||
class AnyRPCConan(ConanFile): | ||
name = "anyrpc" | ||
description = "A multiprotocol remote procedure call system for C++" | ||
license = "MIT" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/sgieseking/anyrpc" | ||
topics = ("rpc") | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
"with_log4cplus": [True, False], | ||
"with_threading": [True, False], | ||
"with_regex": [True, False], | ||
"with_wchar": [True, False], | ||
"with_protocol_json": [True, False], | ||
"with_protocol_xml": [True, False], | ||
"with_protocol_messagepack": [True, False], | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
"with_log4cplus": False, | ||
"with_threading": True, | ||
"with_wchar": True, | ||
"with_regex": True, | ||
"with_protocol_json": True, | ||
"with_protocol_xml": True, | ||
"with_protocol_messagepack": True, | ||
} | ||
|
||
@property | ||
def _minimum_cpp_standard(self): | ||
return 11 | ||
|
||
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 | ||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
def requirements(self): | ||
if self.options.with_log4cplus: | ||
self.requires("log4cplus/2.0.7") | ||
|
||
def validate(self): | ||
if self.info.settings.compiler.cppstd: | ||
check_min_cppstd(self, self._minimum_cpp_standard) | ||
|
||
if self.info.options.with_log4cplus and self.info.options.with_wchar: | ||
raise ConanInvalidConfiguration(f"{self.ref} can not be built with both log4cplus and wchar, see https://github.com/sgieseking/anyrpc/issues/25") | ||
|
||
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["ANYRPC_LIB_BUILD_SHARED"] = self.options.shared | ||
tc.variables["BUILD_EXAMPLES"] = False | ||
tc.variables["BUILD_TEST"] = False | ||
tc.variables["BUILD_WITH_ADDRESS_SANITIZE"] = False | ||
|
||
tc.variables["BUILD_WITH_LOG4CPLUS"] = self.options.with_log4cplus | ||
tc.variables["BUILD_WITH_THREADING"] = self.options.with_threading | ||
tc.variables["BUILD_WITH_REGEX"] = self.options.with_regex | ||
tc.variables["BUILD_WITH_WCHAR"] = self.options.with_wchar | ||
|
||
tc.variables["BUILD_PROTOCOL_JSON"] = self.options.with_protocol_json | ||
tc.variables["BUILD_PROTOCOL_XML"] = self.options.with_protocol_xml | ||
tc.variables["BUILD_PROTOCOL_MESSAGEPACK"] = self.options.with_protocol_messagepack | ||
tc.generate() | ||
|
||
deps = CMakeDeps(self) | ||
deps.generate() | ||
|
||
def _patch_sources(self): | ||
apply_conandata_patches(self) | ||
|
||
def build(self): | ||
self._patch_sources() | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
copy(self, pattern="license", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) | ||
rmdir(self, os.path.join(self.package_folder, "share")) | ||
rm(self, "*.la", os.path.join(self.package_folder, "lib")) | ||
rm(self, "*.pdb", os.path.join(self.package_folder, "lib")) | ||
rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = ["anyrpc"] | ||
|
||
if not self.options.shared and self.settings.os == "Windows": | ||
self.cpp_info.system_libs.append("ws2_32") | ||
|
||
if self.settings.os in ["Linux", "FreeBSD"]: | ||
self.cpp_info.system_libs.append("m") | ||
self.cpp_info.system_libs.append("pthread") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
From 74b4fbb92b654a9483ef3ff64b708fda46bd7b2b Mon Sep 17 00:00:00 2001 | ||
From: Falko Axmann <code@falkoaxmann.de> | ||
Date: Sun, 12 Jan 2020 12:43:00 +0100 | ||
Subject: [PATCH] Handle ASAN flag properly in CMakeLists.txt | ||
|
||
Because of a typo ("else" instead of "elseif"), the | ||
BUILD_WITH_ADDRESS_SANITIZE option was ignored and on | ||
Linux, anyrpc would always be built with ASAN enabled. | ||
--- | ||
CMakeLists.txt | 2 +- | ||
1 file changed, 1 insertion(+), 1 deletion(-) | ||
|
||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index cfeb604..87991bb 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -63,7 +63,7 @@ if (MSVC) | ||
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc" ) | ||
elseif (MINGW) | ||
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -U__STRICT_ANSI__" ) | ||
-else (BUILD_WITH_ADDRESS_SANITIZE) | ||
+elseif (BUILD_WITH_ADDRESS_SANITIZE) | ||
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer" ) | ||
SET( ASAN_LIBRARY asan ) | ||
endif () | ||
-- | ||
2.36.1.windows.1 | ||
|
54 changes: 54 additions & 0 deletions
54
recipes/anyrpc/all/patches/0002-fix-shared-library-1.0.2.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
From c8ece5d572bf68a7d0f63405089a7a8d7d6206ee Mon Sep 17 00:00:00 2001 | ||
From: "email@email.com" <email@email.com> | ||
Date: Fri, 31 Jul 2020 15:37:29 +0300 | ||
Subject: [PATCH] fixed 'undefined reference' error when compile for windows | ||
platform | ||
|
||
--- | ||
include/anyrpc/json/jsonserver.h | 2 +- | ||
include/anyrpc/messagepack/messagepackserver.h | 2 +- | ||
include/anyrpc/xml/xmlserver.h | 2 +- | ||
3 files changed, 3 insertions(+), 3 deletions(-) | ||
|
||
diff --git a/include/anyrpc/json/jsonserver.h b/include/anyrpc/json/jsonserver.h | ||
index d883b16..000bbd4 100644 | ||
--- a/include/anyrpc/json/jsonserver.h | ||
+++ b/include/anyrpc/json/jsonserver.h | ||
@@ -24,7 +24,7 @@ | ||
namespace anyrpc | ||
{ | ||
|
||
-bool JsonRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response); | ||
+ANYRPC_API bool JsonRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response); | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
diff --git a/include/anyrpc/messagepack/messagepackserver.h b/include/anyrpc/messagepack/messagepackserver.h | ||
index cc708f8..708bd72 100644 | ||
--- a/include/anyrpc/messagepack/messagepackserver.h | ||
+++ b/include/anyrpc/messagepack/messagepackserver.h | ||
@@ -24,7 +24,7 @@ | ||
namespace anyrpc | ||
{ | ||
|
||
-bool MessagePackRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response); | ||
+ANYRPC_API bool MessagePackRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response); | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
diff --git a/include/anyrpc/xml/xmlserver.h b/include/anyrpc/xml/xmlserver.h | ||
index 5350ca5..fe0ed23 100644 | ||
--- a/include/anyrpc/xml/xmlserver.h | ||
+++ b/include/anyrpc/xml/xmlserver.h | ||
@@ -24,7 +24,7 @@ | ||
namespace anyrpc | ||
{ | ||
|
||
-bool XmlRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response); | ||
+ANYRPC_API bool XmlRpcHandler(MethodManager* manager, char* request, std::size_t length, Stream &response); | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
-- | ||
2.36.1.windows.1 | ||
|
44 changes: 44 additions & 0 deletions
44
recipes/anyrpc/all/patches/0003-use-conan-libs-1.0.2.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -2,9 +2,6 @@ cmake_minimum_required(VERSION 2.8) | ||
|
||
Project(AnyRPC CXX) | ||
|
||
-# Some of the cmake find_package files are part of this distribution | ||
-set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") | ||
- | ||
# Read out version from "version" file | ||
file(STRINGS "version" ANYRPC_VERSION_FILE) | ||
|
||
@@ -91,7 +88,7 @@ CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/version.h.in" | ||
"${PROJECT_SOURCE_DIR}/include/anyrpc/version.h" ) | ||
|
||
if (BUILD_WITH_LOG4CPLUS) | ||
- find_package( Log4cplus ) | ||
- if (NOT LOG4CPLUS_FOUND) | ||
+ find_package( log4cplus ) | ||
+ if (NOT log4cplus_FOUND) | ||
# the find_package call for Log4cplus doesn't generate an error even if marked as required | ||
message( FATAL_ERROR "LOG4CPLUS library required if BUILD_WITH_LOG4CPLUS on" ) | ||
|
||
--- a/src/CMakeLists.txt | ||
+++ b/src/CMakeLists.txt | ||
@@ -44,15 +44,15 @@ set(ANYRPC_HEADERS ${ANYRPC_HEADERS} ${ANYRPC_INTERNAL_HEADERS} | ||
|
||
# Add the necessary external library references | ||
if (BUILD_WITH_LOG4CPLUS) | ||
- include_directories(${LOG4CPLUS_INCLUDE_DIRS}) | ||
+ set( LOG4CPLUS_TARGET "log4cplus::log4cplus" ) | ||
add_definitions( -DBUILD_WITH_LOG4CPLUS ) | ||
else () | ||
- set( LOG4CPLUS_LIBRARIES "" ) | ||
+ set( LOG4CPLUS_TARGET "" ) | ||
endif () | ||
|
||
# Create the libraries with these header and source files | ||
add_library( anyrpc ${ANYRPC_LIB_TYPE} ${ANYRPC_SOURCES} ${ANYRPC_HEADERS} ) | ||
-target_link_libraries( anyrpc ${ASAN_LIBRARY} ${LOG4CPLUS_LIBRARIES}) | ||
+target_link_libraries( anyrpc ${ASAN_LIBRARY} ${LOG4CPLUS_TARGET}) | ||
|
||
# Need the winsock library for Windows | ||
if (WIN32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
|
||
project(test_anyrpc CXX) | ||
|
||
find_package(anyrpc REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_anyrpc.cpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE anyrpc::anyrpc) | ||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
|
||
|
||
class TestAnyRpcConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
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 can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_anyrpc") | ||
self.run(bin_path, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
#include "anyrpc/anyrpc.h" | ||
|
||
void testFunc(anyrpc::Value& params, anyrpc::Value& result) | ||
{ | ||
} | ||
|
||
int main(void) | ||
{ | ||
anyrpc::JsonHttpServer server; | ||
anyrpc::MethodManager* methodManager = server.GetMethodManager(); | ||
methodManager->AddFunction(&testFunc, "testFunc", "Test function"); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
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/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from conans import ConanFile, CMake | ||
from conan.tools.build import cross_building | ||
import os | ||
|
||
|
||
class TestAnyRpcV1Conan(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 cross_building(self): | ||
bin_path = os.path.join("bin", "test_anyrpc") | ||
self.run(bin_path, run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"1.0.2": | ||
folder: all |