Skip to content

Commit

Permalink
add pybind11 test example
Browse files Browse the repository at this point in the history
  • Loading branch information
weihuayi committed May 10, 2020
1 parent 0a70e0b commit a1f8acd
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ dist
*.png
*.fig
*.vtk
*.so
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake_minimum_required(VERSUION 3.0)
project(fealpy_extent CXX)
add_subdirectory(src)
48 changes: 48 additions & 0 deletions setup_linux_with_extent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from setuptools import Extension, setup

class get_pybind_include:
"""Helper class to determine the pybind11 include path. The purpose of this class is
to postpone importing pybind11 until it is actually installed, so that the
``get_include()`` method can be invoked.
"""
def __init__(self, user=False):
self.user = user

def __str__(self):
import pybind11
return pybind11.get_include(self.user)

ext_modules = [
Extension(
"fealpy_extent",
[
"src/pybind11.cpp",
],
language="C++",
include_dirs=[
get_pybind_include(),
get_pybind_include(user=True)
],
libraries=["stdc++"],
)
]

if __name__ == "__main__":
setup(name='fealpy',
version='1.0',
description='FEALPy: Finite Element Analysis Library in Python',
url='http://github.com/weihuayi/fealpy',
author='Huayi Wei',
author_email='[email protected]',
license='GNU',
packages=['fealpy'],
install_requires=[
'numpy',
'scipy',
'matplotlib',
'pyamg',
'meshpy',
'meshio'
],
ext_modules = ext_modules
)
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
find_package(pybind11 REQUIRED)
FILE(GLOB SRCS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
pybind11_add_module(fealpy_extent ${SRCS})
target_link_libraries(fealpy_extent PRIVATE)
13 changes: 13 additions & 0 deletions src/pybind11.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace py = pybind11;

int add(int i, int j) {
return i + j;
}

PYBIND11_MODULE(fealpy_extent, m){
m.doc() = "My first pybind11 example!";
m.def("add", &add, "A function which adds two numbers");
}

0 comments on commit a1f8acd

Please sign in to comment.