Commit 6217ee3c authored by Jørgen Lien Sellæg's avatar Jørgen Lien Sellæg
Browse files

refactor examples to use one CMAkeLists file

parent 68381bd9
[submodule "pybind/sum_example/lib/pybind11"]
path = pybind/sum_example/lib/pybind11
url = git@github.com:pybind/pybind11
[submodule "lib/pybind11"]
path = lib/pybind11
url = https://github.com/pybind/pybind11
cmake_minimum_required(VERSION 2.8)
project(c-api)
set(project_name pybind-example)
project(project_name)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wall -Wextra")
add_subdirectory("lib/pybind11")
find_package(Python3 COMPONENTS Development)
add_library(c-api main.cpp)
add_library(c-api c-api/main.cpp)
target_include_directories(c-api PUBLIC ${Python3_INCLUDE_DIRS})
target_link_libraries(c-api ${Python3_LIBRARIES})
pybind11_add_module("Prime" pybind/heavy_example/module.cpp)
pybind11_add_module("Maths" pybind/sum_example/module.cpp)
#include <Python.h>
int sum_ints(int a, int b) {
return a + b;
}
static PyObject *bind_sum(PyObject *, PyObject *args) {
int a, b;
if (!PyArg_ParseTuple(args, "ii", &a, &b))
return NULL;
return PyLong_FromLong(sum_ints(a, b));
}
static PyObject *SumError;
static PyMethodDef math_methods[] = {
{ "sum", bind_sum, METH_VARARGS, "Sum two ints" }
};
static struct PyModuleDef math_module = {
PyModuleDef_HEAD_INIT,
"Maths",
nullptr,
-1,
math_methods,
nullptr,
nullptr,
nullptr,
nullptr
};
PyMODINIT_FUNC PyInit_Maths(void) {
PyObject *m = nullptr;
m = PyModule_Create2(&math_module, 1013);
if (!m) {
return nullptr;
}
SumError = PyErr_NewException("sum.error", nullptr, nullptr);
Py_IncRef(SumError);
PyModule_AddObject(m, "error", SumError);
return m;
}
File moved
cmake_minimum_required(VERSION 2.8)
set(project_name pybind-example)
project(project_name)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wall -Wextra")
add_subdirectory("lib/pybind11")
pybind11_add_module("Prime" module.cpp)
cmake_minimum_required(VERSION 2.8)
set(project_name pybind-example)
project(project_name)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -Wall -Wextra")
add_subdirectory("lib/pybind11")
pybind11_add_module("Maths" module.cpp)
Subproject commit 9bb3313162c0b856125e481ceece9d8faa567716
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment