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

Added Conan Packaging #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
*.ipch
*.opensdf
*.sdf
*.suo
*.vcxproj.user
bin/**
build/**
lib/**
ipch/**
obj/**
*ReSharper*
*.VC.*
.vs/*
*.ipch
*.opensdf
*.sdf
*.suo
*.vcxproj.user
bin/**
build/**
lib/**
ipch/**
obj/**
*ReSharper*
*.VC.*
.vs/*
compile_commands.json
CMakeUserPresets.json
test_package/CMakeUserPresets.json
test_package/build
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS} ${WARNING_FLAGS}")


add_subdirectory(Hypodermic)
add_subdirectory(Hypodermic.Tests)
if (NOT BUILD_TESTING STREQUAL OFF)
add_subdirectory(Hypodermic.Tests)
endif()


# uninstall target
Expand Down
4 changes: 2 additions & 2 deletions Hypodermic.Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ set(HypodermicTests_sources

include_directories("..")

add_definitions(-DBOOST_TEST_DYN_LINK)
# add_definitions(-DBOOST_TEST_DYN_LINK)

add_executable(Hypodermic.Tests ${HypodermicTests_sources})
target_link_libraries(Hypodermic.Tests ${Boost_LIBRARIES})
target_link_libraries(Hypodermic.Tests Boost::unit_test_framework)

add_test(cmake_Hypodermic.Tests ${CMAKE_CURRENT_BINARY_DIR}/Hypodermic.Tests --result_code=no --report_level=no)

Expand Down
48 changes: 48 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from conan import ConanFile
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import copy
import os
from os.path import join


class BasicConanfile(ConanFile):
name = "hypodermic"
version = "2.5.3"
description = "Hypodermic is an IoC container for C++. It provides dependency injection to your existing design."
license = "MIT"
homepage = "github.com/ybainier/Hypodermic.git"
settings = "build_type"
default_options = {"boost/*:shared": True}
exports_sources = "Hypodermic/*", "Hypodermic.Tests/*"

def requirements(self):
self.requires("boost/1.81.0")

def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = True
tc.generate()

def layout(self):
cmake_layout(self)

def build(self):
if not self.conf.get("tools.build:skip_test", default=False):
cmake = CMake(self)
cmake.configure(build_script_folder="Hypodermic.Tests")
cmake.build()
self.run(join(self.cpp.build.bindir, "Hypodermic.Tests"))

def package(self):
copy(
self,
"*.h",
join(self.source_folder, "Hypodermic"),
join(self.package_folder, "include/Hypodermic"),
keep_path=False,
)

def package_id(self):
self.info.clear()
7 changes: 7 additions & 0 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

find_package(hypodermic REQUIRED)

add_executable(example src/example.cpp)
target_link_libraries(example hypodermic::hypodermic)
26 changes: 26 additions & 0 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run


class helloTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"

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

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

def layout(self):
cmake_layout(self)

def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "example")
self.run(cmd, env="conanrun")
4 changes: 4 additions & 0 deletions test_package/src/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <Hypodermic/Hypodermic.h>

int main() {
}