-
Notifications
You must be signed in to change notification settings - Fork 2.2k
export interface lib through pybind11Config.cmake
#506
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6a8c13d
make installation include and Config dirs configurable. set CMake pro…
loriab ae6ed96
add CMake exported interface library and Config detection file
loriab 9b8bc85
separate main CMakeLists.txt into Tools file also available upon inst…
loriab 0bb755c
test installed pybind
loriab 92973d8
reflow some docs paragraphs
loriab 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -33,3 +33,5 @@ MANIFEST | |
/cmake/ | ||
.cache/ | ||
sosize-*.txt | ||
pybind11Config*.cmake | ||
pybind11Targets.cmake |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 2.8.12) | ||
project(test_installed_module CXX) | ||
|
||
set(CMAKE_MODULE_PATH "") | ||
|
||
find_package(pybind11 CONFIG REQUIRED) | ||
|
||
message(STATUS "Found pybind11: ${pybind11_INCLUDE_DIRS} (found version ${pybind11_VERSION})") | ||
message(STATUS "Found Python: ${PYTHON_INCLUDE_DIRS} (found version ${PYTHON_VERSION_STRING})") | ||
|
||
pybind11_add_module(test_installed_module SHARED main.cpp) | ||
|
||
add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_installed_module> | ||
${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test.py) |
This file contains hidden or 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,10 @@ | ||
#include <pybind11/pybind11.h> | ||
namespace py = pybind11; | ||
|
||
PYBIND11_PLUGIN(test_installed_module) { | ||
py::module m("test_installed_module"); | ||
|
||
m.def("add", [](int i, int j) { return i + j; }); | ||
|
||
return m.ptr(); | ||
} |
This file contains hidden or 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,3 @@ | ||
import test_installed_module | ||
assert test_installed_module.add(11, 22) == 33 | ||
print('test_installed_module imports, runs, and adds: 11 + 22 = 33') |
This file contains hidden or 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,20 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
project(test_installed_target CXX) | ||
|
||
set(CMAKE_MODULE_PATH "") | ||
|
||
find_package(pybind11 CONFIG REQUIRED) | ||
|
||
message(STATUS "Found pybind11: ${pybind11_INCLUDE_DIRS} (found version ${pybind11_VERSION})") | ||
message(STATUS "Found Python: ${PYTHON_INCLUDE_DIRS} (found version ${PYTHON_VERSION_STRING})") | ||
|
||
add_library(test_installed_target MODULE main.cpp) | ||
|
||
target_link_libraries(test_installed_target PRIVATE pybind11::pybind11) | ||
|
||
# make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib | ||
set_target_properties(test_installed_target PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" | ||
SUFFIX "${PYTHON_MODULE_EXTENSION}") | ||
|
||
add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_installed_target> | ||
${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test.py) |
This file contains hidden or 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,10 @@ | ||
#include <pybind11/pybind11.h> | ||
namespace py = pybind11; | ||
|
||
PYBIND11_PLUGIN(test_installed_target) { | ||
py::module m("test_installed_target"); | ||
|
||
m.def("add", [](int i, int j) { return i + j; }); | ||
|
||
return m.ptr(); | ||
} |
This file contains hidden or 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,3 @@ | ||
import test_installed_target | ||
assert test_installed_target.add(1, 2) == 3 | ||
print('test_installed_target imports, runs, and adds: 1 + 2 = 3') |
Oops, something went wrong.
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.
This option and the related
pybind11_enable_warnings
function should stay in the mainCMakeLists.txt
file. It's not for export.