2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-25 11:19:52 +01:00

Add genpybind example

This commit is contained in:
Yannik Stradmann 2019-07-02 11:50:25 +02:00
parent 0c16ab4f65
commit 1fd2e4174c
4 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,9 @@
#include "example.h"
constexpr int Example::not_exposed;
int Example::calculate(int some_argument) const { return _value + some_argument; }
int Example::getSomething() const { return _value; }
void Example::setSomething(int value) { _value = value; }

View File

@ -0,0 +1,20 @@
#pragma once
#include "genpybind.h"
class GENPYBIND(visible) Example {
public:
static constexpr int GENPYBIND(hidden) not_exposed = 10;
/// \brief Do a complicated calculation.
int calculate(int some_argument = 5) const;
GENPYBIND(getter_for(something))
int getSomething() const;
GENPYBIND(setter_for(something))
void setSomething(int value);
private:
int _value = 0;
};

View File

@ -0,0 +1,9 @@
import pyexample as m
def test_example():
obj = m.Example()
obj.something = 42
assert obj.something == 42
assert obj.calculate() == 47 # with default argument
assert obj.calculate(2) == 44

View File

@ -0,0 +1,37 @@
#!/usr/bin/env python
def options(opt):
opt.load('python')
opt.load('compiler_cxx')
opt.load('genpybind')
def configure(cfg):
cfg.load('python')
cfg.load('compiler_cxx')
cfg.check_python_version((2, 7))
cfg.check_python_headers()
cfg.load('genpybind')
cfg.check(compiler='cxx',
features='cxx pyext',
uselib_store='PYBIND11GENPYBIND_EXAMPLE',
mandatory=True,
header_name='pybind11/pybind11.h')
def build(bld):
bld(target='example_inc',
export_includes='.')
bld.shlib(target='example',
source='example.cpp',
features='use',
use='example_inc')
bld(target='pyexample',
source='example.h',
genpybind_tags='genpybind_example',
features='use genpybind cxx cxxshlib pyext',
use=['PYBIND11GENPYBIND_EXAMPLE', 'example'])