Skip to content

Commit 830f0f9

Browse files
committed
Add pybind11/2.4.3 recipe
1 parent 269d326 commit 830f0f9

File tree

8 files changed

+125
-0
lines changed

8 files changed

+125
-0
lines changed

recipes/pybind11/all/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 2.8.12)
2+
project(cmake_wrapper)
3+
4+
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
5+
conan_basic_setup()
6+
7+
add_subdirectory(source_subfolder)

recipes/pybind11/all/conandata.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
sources:
2+
2.4.3:
3+
url: https://github.com/pybind/pybind11/archive/v2.4.3.tar.gz
4+
sha256: 1eed57bc6863190e35637290f97a20c81cfe4d9090ac0a24f3bbf08f265eb71d

recipes/pybind11/all/conanfile.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from conans import ConanFile, tools, CMake
2+
import os
3+
4+
5+
class PyBind11Conan(ConanFile):
6+
name = "pybind11"
7+
description = "Seamless operability between C++11 and Python"
8+
topics = "conan", "pybind11", "python", "binding"
9+
homepage = "https://github.com/pybind/pybind11"
10+
license = "BSD-3-Clause"
11+
url = "https://github.com/conan-io/conan-center-index"
12+
exports_sources = "CMakeLists.txt"
13+
settings = "os", "arch", "compiler", "build_type"
14+
generators = "cmake"
15+
no_copy_source = True
16+
17+
_source_subfolder = "source_subfolder"
18+
19+
def source(self):
20+
tools.get(**self.conan_data["sources"][self.version])
21+
os.rename("{}-{}".format(self.name, self.version), self._source_subfolder)
22+
23+
def _configure_cmake(self):
24+
cmake = CMake(self)
25+
cmake.definitions["PYBIND11_INSTALL"] = True
26+
cmake.definitions["PYBIND11_TEST"] = False
27+
cmake.definitions["PYBIND11_CMAKECONFIG_INSTALL_DIR"] = "lib/cmake/pybind11"
28+
cmake.configure()
29+
return cmake
30+
31+
def build(self):
32+
cmake = self._configure_cmake()
33+
cmake.build()
34+
35+
def package(self):
36+
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
37+
cmake = self._configure_cmake()
38+
cmake.install()
39+
os.unlink(os.path.join(self.package_folder, "lib", "cmake", "pybind11", "pybind11Config.cmake"))
40+
os.unlink(os.path.join(self.package_folder, "lib", "cmake", "pybind11", "pybind11ConfigVersion.cmake"))
41+
42+
def package_id(self):
43+
self.info.header_only()
44+
45+
def package_info(self):
46+
self.cpp_info.includedirs.append(os.path.join(self.package_folder, "include", "pybind11"))
47+
48+
cmake_base_path = os.path.join("lib", "cmake", "pybind11")
49+
self.cpp_info.builddirs = [cmake_base_path]
50+
self.cpp_info.build_modules = [os.path.join(cmake_base_path, "FindPythonLibsNew.cmake"),
51+
os.path.join(cmake_base_path, "pybind11Tools.cmake")]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 2.8.11)
2+
project(test_package CXX)
3+
4+
set(CMAKE_VERBOSE_MAKEFILE TRUE)
5+
6+
find_package(PythonInterp REQUIRED)
7+
find_package(PythonLibs REQUIRED)
8+
9+
find_package(pybind11 REQUIRED)
10+
include(pybind11Tools)
11+
12+
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
13+
conan_basic_setup()
14+
15+
pybind11_add_module(test_package MODULE
16+
test_package.cpp
17+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from conans import ConanFile, CMake
2+
import os
3+
import sys
4+
5+
6+
class TestPackageConan(ConanFile):
7+
settings = "os", "compiler", "build_type", "arch"
8+
generators = "cmake", "cmake_find_package"
9+
10+
def build(self):
11+
cmake = CMake(self)
12+
cmake.configure()
13+
cmake.build()
14+
15+
def test(self):
16+
self.run("{} {} {}".format(sys.executable,
17+
os.path.join(self.source_folder, "test.py"),
18+
os.path.join(self.build_folder, "lib")), run_environment=True)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import sys
2+
3+
sys.path.extend(sys.argv[1:])
4+
5+
import test_package
6+
7+
print("Adding 2 + 3 = {}".format(test_package.add(2, 3)))
8+
9+
print("Message: '{}'".format(test_package.msg()))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <pybind11/pybind11.h>
2+
3+
static int add(int i, int j) {
4+
return i + j;
5+
}
6+
7+
static const char *hello() {
8+
return "Hello from the C++ world!";
9+
}
10+
11+
PYBIND11_MODULE(test_package, m) {
12+
m.doc() = "pybind11 example plugin"; // optional module docstring
13+
14+
m.def("add", &add, "A function which adds two numbers");
15+
m.def("msg", &hello, "A function returning a message");
16+
}

recipes/pybind11/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
versions:
2+
"2.4.3":
3+
folder: all

0 commit comments

Comments
 (0)