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

dylib: new recipe #20803

Merged
merged 6 commits into from
Oct 31, 2023
Merged
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
4 changes: 4 additions & 0 deletions recipes/dylib/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2.2.1":
url: "https://github.com/martin-olivier/dylib/archive/refs/tags/v2.2.1.tar.gz"
sha256: "6af0d2a91860743dc9f564ba0ab7f036a9b37c904395610288791571d4dbea5b"
52 changes: 52 additions & 0 deletions recipes/dylib/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.files import copy, get
from conan.tools.layout import basic_layout
import os

required_conan_version = ">=1.53.0"

class DylibConan(ConanFile):
name = "dylib"
homepage = "https://github.com/martin-olivier/dylib"
url = "https://github.com/conan-io/conan-center-index"
description = "C++ cross-platform wrapper around dynamic loading of shared libraries (dll, so, dylib)"
license = "MIT"
topics = ("shared-library", "cross-platform", "header-only")

package_type = 'header-library'
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
pass

def package_id(self):
self.info.clear()

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def build(self):
pass

def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "dylib.hpp", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "dylib")
self.cpp_info.set_property("cmake_target_name", "dylib::dylib")
self.cpp_info.set_property("pkg_config_name", "dylib")
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["dl"])
12 changes: 12 additions & 0 deletions recipes/dylib/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.8)
martin-olivier marked this conversation as resolved.
Show resolved Hide resolved
project(test_package LANGUAGES CXX)

enable_testing()

find_package(dylib REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE dylib::dylib)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)

add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we dont use ctest because it hides the output, but is not a blocker, just consider for futures PRs.

29 changes: 29 additions & 0 deletions recipes/dylib/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.build import can_run
from conan.tools.files import chdir

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):
with chdir(self, self.build_folder):
self.run(f"ctest --output-on-failure -C {self.settings.build_type}", env="conanrun")
13 changes: 13 additions & 0 deletions recipes/dylib/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include <dylib.hpp>

int main()
{
try {
dylib lib("foo");
std::cerr << "Expected dylib::load_error exception" << std::endl;
return 1;
} catch (const dylib::load_error &) {
return 0;
}
}
3 changes: 3 additions & 0 deletions recipes/dylib/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.2.1":
folder: all