Skip to content

Commit

Permalink
Merge pull request #8 from lukaszlaszko/feature-conan-packaging
Browse files Browse the repository at this point in the history
Feature conan packaging
  • Loading branch information
lukaszlaszko authored Dec 23, 2018
2 parents 28914a8 + 61173a8 commit def12a9
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Download](https://api.bintray.com/packages/lukaszlaszko/shadow/di%3Ashadow/images/download.svg) ](https://bintray.com/lukaszlaszko/shadow/di%3Ashadow/_latestVersion)
[![Build Status](https://travis-ci.org/lukaszlaszko/di.svg?branch=master)](https://travis-ci.org/lukaszlaszko/di)
[![codecov](https://codecov.io/gh/lukaszlaszko/di/branch/master/graph/badge.svg)](https://codecov.io/gh/lukaszlaszko/di)
[![CodeFactor](https://www.codefactor.io/repository/github/lukaszlaszko/di/badge)](https://www.codefactor.io/repository/github/lukaszlaszko/di)
Expand All @@ -16,6 +17,7 @@
* [Annotations](#annotations)
* [Usage](#usage)
* [Compilation](#compilation)
* [Conan package](#conan-package)

----

Expand Down Expand Up @@ -521,3 +523,58 @@ $ sudo apt-get install libstdc++-6-dev
```

after prior registration of `ubuntu-toolchain-r-test` source channel.

#### Conan package

[Conan](https://docs.conan.io/en/latest) is an opena source package manager for C/C++. [Bintray shadow](https://bintray.com/lukaszlaszko/shadow)
repository provides latest redistributable package with project artefacts. In order to use it in your cmake based project:

1. Add following block to root `CMakeLists.txt` of your project:

```cmake
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
else()
message(WARNING "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
endif()
```
2. Add `conanfile.txt` side by side with your top level `CMakeLists.txt`:
```text
[requires]
di/1.0@shadow/stable
[generators]
cmake
```
4. Add `shadow` to your list of conan remotes:
```
$ conan remote add shadow https://api.bintray.com/conan/lukaszlaszko/shadow
```
3. Install conan dependencies into your cmake build directory:
```
$ conan install . -if <build dir>
```
if for whatever reason installation of binary package fails, add `--build di` flag to the above. This will perform install the source package and compile all necessary modules.
4. To link against libraries provided by the package, either add:
```cmake
target_link_libraries([..] ${CONAN_LIBS})
```
for your target. Or specifically:
```cmake
target_link_libraries([..] ${CONAN_LIBS_DI})
```
5. Reload cmake configuration.
33 changes: 33 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from conans import ConanFile, CMake


class DiConan(ConanFile):
name = "di"
version = "1.0"
license = "Apache-2.0"
author = "Lukasz Laszko lukaszlaszko@gmail.com"
url = "https://github.com/lukaszlaszko/di"
description = "Compile and runtime dependency injection for C++ 14"
topics = ("dependency injection", "di", "c++", "cpp", "", "cxx")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = "shared=False"
generators = "cmake"
exports_sources = ["CMakeLists.txt", "src/*", "external/*", "tests/*"]

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build(target="di")

def package(self):
self.copy("*.hpp", dst="include", src="src")
self.copy("*.ipp", dst="include", src="src")
self.copy("*.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.dylib*", dst="lib", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)

def package_info(self):
self.cpp_info.libs = ["di"]
24 changes: 24 additions & 0 deletions tests/unit/di/definition_builder_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,11 +1041,15 @@ TEST(definition_builder, define_decorator__lambda__unique_pointer__context)
{
struct interface
{
virtual ~interface() = default;

virtual void method() { };
};

struct component : interface
{
virtual ~component() = default;

void method() override
{
}
Expand Down Expand Up @@ -1088,11 +1092,15 @@ TEST(definition_builder, define_decorator__lambda__unique_pointer__no_context)
{
struct interface
{
virtual ~interface() = default;

virtual void method() { };
};

struct component : interface
{
virtual ~component() = default;

void method() override
{
}
Expand Down Expand Up @@ -1221,11 +1229,15 @@ TEST(definition_builder, define_decorator__unique_pointer__static_method__conte
{
struct interface
{
virtual ~interface() = default;

virtual void method() { };
};

struct component : interface
{
virtual ~component() = default;

void method() override
{
}
Expand Down Expand Up @@ -1272,11 +1284,15 @@ TEST(definition_builder, define_decorator__unique_pointer__static_method__no_co
{
struct interface
{
virtual ~interface() = default;

virtual void method() { };
};

struct component : interface
{
virtual ~component() = default;

void method() override
{
}
Expand Down Expand Up @@ -1323,11 +1339,15 @@ TEST(definition_builder, define_decorator__unique_pointer__non_static_method__c
{
struct interface
{
virtual ~interface() = default;

virtual void method() { };
};

struct component : interface
{
virtual ~component() = default;

void method() override
{
}
Expand Down Expand Up @@ -1377,11 +1397,15 @@ TEST(definition_builder, define_decorator__unique_pointer__non_static_method__n
{
struct interface
{
virtual ~interface() = default;

virtual void method() { };
};

struct component : interface
{
virtual ~component() = default;

void method() override
{
}
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/di/instance_activator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1904,11 +1904,15 @@ TEST(instance_activator, activate__decorate__unique_ptr)

struct interface
{
virtual ~interface() = default;

virtual void method() = 0;
};

struct component : interface
{
virtual ~component() = default;

void method() override
{
component_count++;
Expand Down Expand Up @@ -1958,11 +1962,15 @@ TEST(instance_activator, activate__decorate__unique_ptr__multidecoration)

struct interface
{
virtual ~interface() = default;

virtual void method() = 0;
};

struct component : interface
{
virtual ~component() = default;

void method() override
{
component_count++;
Expand Down

0 comments on commit def12a9

Please sign in to comment.