Skip to content

Commit 12943e8

Browse files
committed
Add conan support
1 parent 9d19555 commit 12943e8

File tree

5 files changed

+183
-0
lines changed

5 files changed

+183
-0
lines changed

.circleci/config.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,25 @@ jobs:
5353
cd build && cmake -DBUILD_DOC=on -DBUILD_THREAD=on -DBUILD_BOOST_ASIO=on -DBUILD_EV=on ..
5454
make -j2 && ctest .
5555
56+
build_conan:
57+
docker:
58+
- image: debian:10
59+
resource_class: medium
60+
steps:
61+
- checkout
62+
- run:
63+
name: "prepare & build"
64+
command: |
65+
apt-get update
66+
apt-get install -y cmake clang python3-pip
67+
pip3 install conan
68+
conan create conanfile.py rotor/0.20@
69+
70+
5671
workflows:
5772
build-all-workflow:
5873
jobs:
5974
- build_gcc
6075
- build_clang
6176
- build_arm
77+
- build_conan

conanfile.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
from conans import ConanFile, CMake, tools
2+
from conans.errors import ConanInvalidConfiguration
3+
import os
4+
5+
required_conan_version = ">=1.43.0"
6+
7+
8+
class RotorConan(ConanFile):
9+
name = "rotor"
10+
license = "MIT"
11+
homepage = "https://github.com/basiliscos/cpp-rotor"
12+
url = "https://github.com/conan-io/conan-center-index"
13+
description = (
14+
"Event loop friendly C++ actor micro-framework, supervisable"
15+
)
16+
topics = ("concurrency", "actor-framework", "actors", "actor-model", "erlang", "supervising", "supervisor")
17+
18+
settings = "os", "arch", "compiler", "build_type"
19+
options = {
20+
"fPIC": [True, False],
21+
"boost_asio": [True, False],
22+
"thread": [True, False],
23+
}
24+
default_options = {
25+
"fPIC": True,
26+
"boost_asio": True,
27+
"thread": True,
28+
}
29+
30+
exports_sources = ["CMakeLists.txt"]
31+
generators = "cmake"
32+
_cmake = None
33+
34+
@property
35+
def _source_subfolder(self):
36+
return "source_subfolder"
37+
38+
@property
39+
def _build_subfolder(self):
40+
return "build_subfolder"
41+
42+
def config_options(self):
43+
if self.settings.os == "Windows":
44+
del self.options.fPIC
45+
46+
def requirements(self):
47+
self.requires("boost/1.69.0")
48+
49+
50+
def validate(self):
51+
minimal_cpp_standard = "17"
52+
if self.settings.compiler.get_safe("cppstd"):
53+
tools.check_min_cppstd(self, minimal_cpp_standard)
54+
minimal_version = {
55+
"gcc": "7",
56+
"clang": "6",
57+
"apple-clang": "10",
58+
"Visual Studio": "15"
59+
}
60+
compiler = str(self.settings.compiler)
61+
if compiler not in minimal_version:
62+
self.output.warn(
63+
"%s recipe lacks information about the %s compiler standard version support" % (self.name, compiler))
64+
self.output.warn(
65+
"%s requires a compiler that supports at least C++%s" % (self.name, minimal_cpp_standard))
66+
return
67+
68+
version = tools.Version(self.settings.compiler.version)
69+
if version < minimal_version[compiler]:
70+
raise ConanInvalidConfiguration("%s requires a compiler that supports at least C++%s" % (self.name, minimal_cpp_standard))
71+
72+
def _configure_cmake(self):
73+
if self._cmake:
74+
return self._cmake
75+
76+
self._cmake = CMake(self)
77+
self._cmake.definitions["BUILD_BOOST_ASIO"] = self.options.boost_asio
78+
self._cmake.definitions["BUILD_THREAD"] = self.options.thread
79+
self._cmake.configure(build_folder=self._build_subfolder)
80+
return self._cmake
81+
82+
def build(self):
83+
cmake = self._configure_cmake()
84+
cmake.build()
85+
86+
def source(self):
87+
tools.get(**self.conan_data["sources"][self.version],
88+
destination=self._source_subfolder, strip_root=True)
89+
90+
def package(self):
91+
cmake = self._configure_cmake()
92+
cmake.install()
93+
self.copy("license*", src=self._source_subfolder, dst="licenses", ignore_case=True, keep_path=False)
94+
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
95+
96+
def package_info(self):
97+
self.cpp_info.components["core"].libs = ["rotor-core"]
98+
self.cpp_info.components["core"].requires = ["boost::date_time", "boost::system", "boost::regex"]
99+
100+
self.cpp_info.components["asio"].libs = ["rotor-asio"]
101+
self.cpp_info.components["asio"].requires = ["core"]
102+
103+
self.cpp_info.components["thread"].libs = ["rotor-thread"]
104+
self.cpp_info.components["thread"].requires = ["core"]
105+
106+
# TODO: to remove in conan v2 once cmake_find_package* generators removed
107+
self.cpp_info.names["cmake_find_package"] = "rotor"
108+
self.cpp_info.names["cmake_find_package_multi"] = "rotor"
109+

test_package/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.8)
2+
project(test_package CXX)
3+
4+
find_package("rotor" COMPONENTS asio thread REQUIRED)
5+
6+
add_executable(${PROJECT_NAME} test_package.cpp)
7+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
8+
target_link_libraries(${PROJECT_NAME} rotor::asio rotor::thread)

test_package/conanfile.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "arch", "compiler", "build_type"
7+
generators = "cmake_find_package"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
def test(self):
15+
if not tools.cross_building(self):
16+
self.run("test_package", run_environment=True)
17+

test_package/test_package.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <rotor/asio.hpp>
2+
#include <rotor/thread.hpp>
3+
4+
namespace asio = boost::asio;
5+
namespace pt = boost::posix_time;
6+
7+
struct server_actor : public rotor::actor_base_t {
8+
using rotor::actor_base_t::actor_base_t;
9+
void on_start() noexcept override {
10+
rotor::actor_base_t::on_start();
11+
std::cout << "hello world\n";
12+
do_shutdown();
13+
}
14+
};
15+
16+
int main() {
17+
asio::io_context io_context;
18+
auto system_context = rotor::asio::system_context_asio_t::ptr_t{new rotor::asio::system_context_asio_t(io_context)};
19+
auto strand = std::make_shared<asio::io_context::strand>(io_context);
20+
auto timeout = boost::posix_time::milliseconds{500};
21+
auto sup =
22+
system_context->create_supervisor<rotor::asio::supervisor_asio_t>().strand(strand).timeout(timeout).finish();
23+
24+
sup->create_actor<server_actor>().timeout(timeout).autoshutdown_supervisor().finish();
25+
26+
sup->start();
27+
io_context.run();
28+
29+
rotor::thread::system_context_thread_t thread_ctx;
30+
31+
return 0;
32+
}
33+

0 commit comments

Comments
 (0)