Skip to content

Commit

Permalink
Add pybind11/2.4.3 recipe (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr authored Apr 28, 2020
1 parent 94dcf63 commit f97cd8b
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/pybind11/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.12)
project(cmake_wrapper)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup()

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/pybind11/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
2.4.3:
url: https://github.com/pybind/pybind11/archive/v2.4.3.tar.gz
sha256: 1eed57bc6863190e35637290f97a20c81cfe4d9090ac0a24f3bbf08f265eb71d
51 changes: 51 additions & 0 deletions recipes/pybind11/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from conans import ConanFile, tools, CMake
import os


class PyBind11Conan(ConanFile):
name = "pybind11"
description = "Seamless operability between C++11 and Python"
topics = "conan", "pybind11", "python", "binding"
homepage = "https://github.com/pybind/pybind11"
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
exports_sources = "CMakeLists.txt"
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"
no_copy_source = True

_source_subfolder = "source_subfolder"

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename("{}-{}".format(self.name, self.version), self._source_subfolder)

def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["PYBIND11_INSTALL"] = True
cmake.definitions["PYBIND11_TEST"] = False
cmake.definitions["PYBIND11_CMAKECONFIG_INSTALL_DIR"] = "lib/cmake/pybind11"
cmake.configure()
return cmake

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
cmake.install()
os.unlink(os.path.join(self.package_folder, "lib", "cmake", "pybind11", "pybind11Config.cmake"))
os.unlink(os.path.join(self.package_folder, "lib", "cmake", "pybind11", "pybind11ConfigVersion.cmake"))

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

def package_info(self):
self.cpp_info.includedirs.append(os.path.join(self.package_folder, "include", "pybind11"))

cmake_base_path = os.path.join("lib", "cmake", "pybind11")
self.cpp_info.builddirs = [cmake_base_path]
self.cpp_info.build_modules = [os.path.join(cmake_base_path, "FindPythonLibsNew.cmake"),
os.path.join(cmake_base_path, "pybind11Tools.cmake")]
17 changes: 17 additions & 0 deletions recipes/pybind11/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 2.8.11)
project(test_package CXX)

set(CMAKE_VERBOSE_MAKEFILE TRUE)

find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)

find_package(pybind11 REQUIRED)
include(pybind11Tools)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup()

pybind11_add_module(test_package MODULE
test_package.cpp
)
18 changes: 18 additions & 0 deletions recipes/pybind11/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake
import os
import sys


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"

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

def test(self):
self.run("{} {} {}".format(sys.executable,
os.path.join(self.source_folder, "test.py"),
os.path.join(self.build_folder, "lib")), run_environment=True)
9 changes: 9 additions & 0 deletions recipes/pybind11/all/test_package/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys

sys.path.extend(sys.argv[1:])

import test_package

print("Adding 2 + 3 = {}".format(test_package.add(2, 3)))

print("Message: '{}'".format(test_package.msg()))
16 changes: 16 additions & 0 deletions recipes/pybind11/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <pybind11/pybind11.h>

static int add(int i, int j) {
return i + j;
}

static const char *hello() {
return "Hello from the C++ world!";
}

PYBIND11_MODULE(test_package, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring

m.def("add", &add, "A function which adds two numbers");
m.def("msg", &hello, "A function returning a message");
}
3 changes: 3 additions & 0 deletions recipes/pybind11/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.4.3":
folder: all

0 comments on commit f97cd8b

Please sign in to comment.