diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/python/CMakeLists.txt | 11 | ||||
-rw-r--r-- | examples/python/hello.cpp | 19 |
2 files changed, 30 insertions, 0 deletions
diff --git a/examples/python/CMakeLists.txt b/examples/python/CMakeLists.txt new file mode 100644 index 0000000..f43c3a7 --- /dev/null +++ b/examples/python/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.5) # for Boost::* imported targets + +project(example_python) + +find_package(Python REQUIRED COMPONENTS Development) +set(boost_python "python${Python_VERSION_MAJOR}${Python_VERSION_MINOR}") +find_package(Boost REQUIRED COMPONENTS "${boost_python}") + +add_library(hello SHARED hello.cpp) +target_link_libraries(hello PRIVATE Python::Module) +target_link_libraries(hello PRIVATE Boost::disable_autolinking "Boost::${boost_python}") diff --git a/examples/python/hello.cpp b/examples/python/hello.cpp new file mode 100644 index 0000000..b7516e4 --- /dev/null +++ b/examples/python/hello.cpp @@ -0,0 +1,19 @@ +#include <string> + +#include <boost/python.hpp> +using namespace boost::python; + +struct World +{ + void set(const std::string& msg) { this->msg = msg; } + std::string greet() const { return msg; } + std::string msg; +}; + +BOOST_PYTHON_MODULE(hello) +{ + class_<World>("World") + .def("greet", &World::greet) + .def("set", &World::set) + ; +} |