-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
pybind11 cmakedeps #9348
Closed
Closed
pybind11 cmakedeps #9348
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b8573f4
pybind11 tested with cmakedeps
lasote 01de7bf
support for <2.6.0
lasote 0d587cd
Renamed folder
lasote 3b812fa
Link target
lasote 9b4d4f4
try replace path
lasote f9c6a16
Merge remote-tracking branch 'origin/master' into feature/pybin11_cma…
lasote 5f88d7c
recipe
lasote 6353545
cmake_layout from layout
lasote 9a58484
remove unnecesary change
lasote 7d7096c
Link with target
lasote 9e3fa7b
Not link
lasote ff47c50
Add python version
lasote 519edf9
no link target if not necessary
lasote a456729
print to debug
lasote 7f4738f
up
lasote File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cmake_minimum_required(VERSION 3.4) | ||
project(test_package CXX) | ||
|
||
|
||
find_package(pybind11 REQUIRED) | ||
|
||
pybind11_add_module(test_package MODULE test_package.cpp) | ||
target_link_libraries(test_package PRIVATE pybind11::pybind11) | ||
set_property(TARGET test_package PROPERTY CXX_STANDARD 11) | ||
|
||
enable_testing() | ||
|
||
add_test(run_example | ||
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test.py ${CMAKE_CURRENT_BINARY_DIR}/lib) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from conans import ConanFile | ||
from conan.tools.cmake import CMake, CMakeToolchain | ||
from conan.tools.layout import cmake_layout | ||
from conan.tools.env import Environment | ||
from conan.tools.cross_building import cross_building | ||
import os | ||
import sys | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "CMakeToolchain", "CMakeDeps" | ||
|
||
def generate(self): | ||
toolchain = CMakeToolchain(self) | ||
toolchain.variables["PYTHON_EXECUTABLE"] = self._python_interpreter.replace("\\", "/") | ||
toolchain.generate() | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
@property | ||
def _python_interpreter(self): | ||
if getattr(sys, "frozen", False): | ||
return "python" | ||
return sys.executable | ||
|
||
def test(self): | ||
if not cross_building(self): | ||
env = Environment() | ||
env.define("PYTHONPATH", self.cpp.build.libdirs[0]) | ||
env.vars(self).save_script("launcher") | ||
test_path = os.path.join(self.source_folder, "test.py") | ||
self.run("{} {}".format(self._python_interpreter, test_path), env="launcher") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import test_package | ||
|
||
print("Adding 2 + 3 = {}".format(test_package.add(2, 3))) | ||
|
||
print("Message: '{}'".format(test_package.msg())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the same project files (
CMakeLists.txt
) fromtest_package
, even if you need someif
to skip theconanbuildinfo.cmake
. It is important to check that both generators use the samefind_package
call, same target names,...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that is a good practice:
../test_package/CMakeLists.txt
is very dirty and not something you will do except for this situation.CMakelists.txt
to skip theconanbuildinfo.cmake
would be very very weird, so you edit that file and you are supposed to know that is shared between several test_packages.Overall I think that code reuse, far from helping, will cause more trouble and dirty code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank God it is more or less easy with the layout, just:
I find it important, but let's wait for other reviewers, they are the ones that will maintain this recipe and possible inconsistencies between the two files.