-
Notifications
You must be signed in to change notification settings - Fork 27
Add advanced example that installs a CMake package #8
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
Conversation
|
I will also add a |
AKA Windows... |
|
Did I stutter? 😉 It is updated with a minimal example of an entry point configured with the top level CMake file to correctly point to the installed CMake package files. |
|
@henryiii I updated to use |
|
I'll try to look at this soon, ping me if I don't get to it this week! |
henryiii
left a comment
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.
A few very minor suggestions.
| # call pybind11-config to obtain the root of the cmake package | ||
| execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pybind11 --cmakedir OUTPUT_VARIABLE pybind11_ROOT_RAW) | ||
| string(STRIP ${pybind11_ROOT_RAW} pybind11_ROOT) | ||
| find_package(pybind11) |
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'm hoping to remove the need to do this eventually. :)
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.
How's that?
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.
Current idea is to add an entry point mechanism to scikit-build. Pybind11 would define the entrypoint:
[options.entry_points]
scikit-build.module =
module=pybind11.skbuild:moduleThe "module" function returns a path pointing to the CMake files in the package. This is added to CMake’s search path by scikit-build, iterating over all matching entry points.
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.
Hmmm... I'm not familiar with the tooling around discovering entry points, but it sounds reasonable. Are those CMake files to be added via something akin to add_subdirectory? I have a project I'm writing in C++, but also want to distribute a Python wrapper (using pybind11) and distribute the C++ libraries, CMake to consume those libraries, and the Python wrapper using pip.
I did make the changes suggested. Are we waiting on @jcfr to do a final review and pull?
Output on my machine. |
This advanced example, unlike the other examples, builds a separate shared library and installs a CMake package to use that shared library with the Python package. The example uses pybind11 to implement the C++-Python binding. The example has Python tests, but is missing C++ tests.
Co-authored-by: Henry Schreiner <[email protected]>
|
Tests pass too, so I'm happy. |
|
Any idea how to fix this on Windows? hello.lib is not available. |
|
I suppose I'd have to figure out how to generate and install import libraries on Windows in CMake. I'll get around to it. |
|
Considering the date I last left a comment and when I first did the work, you can consider this abandoned. I'm not particularly knowledgeable about building on Windows. I think this example is worthwhile, perhaps even if it doesn't work with Windows yet. |
|
I"m fine to drop it in as UNIX only, I'd just need to add an if into the noxfile, I think. It should be pretty easy to make it work if someone knew more about Windows building than I do. :) |
This advanced example, unlike the other examples, builds a separate shared library and installs a CMake package to use that shared library within the Python package. The example uses pybind11 to implement the C++-Python binding, but it's not a pybind11 best practices example.
The example will contain both Python tests, and a C++ test that consumes the C++ library using the CMake package as installed into the Python package directory.
I'm open to name changes, code formatting changes, anything, as long as we drive best practices home.
This was done in reaction to the discussion in #6. Pinging @henryiii @phcerdan @jcfr.
TODO