diff --git a/CMakeLists.txt b/CMakeLists.txt index 31449ec..b312f73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 2.8.12) project(cmake_example) +include_directories(${cmake_example_SOURCE_DIR}/arugula) +add_subdirectory(arugula) add_subdirectory(pybind11) -pybind11_add_module(cmake_example src/main.cpp) + +pybind11_add_module(cmake_example src/main.cpp MODULE) +target_link_libraries(cmake_example PUBLIC arugula) diff --git a/arugula/CMakeLists.txt b/arugula/CMakeLists.txt new file mode 100644 index 0000000..59b42e5 --- /dev/null +++ b/arugula/CMakeLists.txt @@ -0,0 +1,6 @@ +set(ARUGULA_HEADER_FILES arugula.h) + +add_library(arugula SHARED arugula.cpp ${ARUGULA_HEADER_FILES}) + +install(TARGETS arugula LIBRARY DESTINATION lib) +install(FILES ${ARUGULA_HEADER_FILES} DESTINATION include/arugula) diff --git a/arugula/arugula.cpp b/arugula/arugula.cpp new file mode 100644 index 0000000..6ccef75 --- /dev/null +++ b/arugula/arugula.cpp @@ -0,0 +1,9 @@ +#include "arugula.h" + +// test shared lib + +int +test_func() +{ + return 13; +} diff --git a/arugula/arugula.h b/arugula/arugula.h new file mode 100644 index 0000000..77722f1 --- /dev/null +++ b/arugula/arugula.h @@ -0,0 +1 @@ +int test_func(); diff --git a/setup.py b/setup.py index 7db697f..d853154 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,11 @@ def run(self): def build_extension(self, ext): extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) + + # from cmake_example PR #16 + if not extdir.endswith(os.path.sep): + extdir += os.path.sep + cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, '-DPYTHON_EXECUTABLE=' + sys.executable] diff --git a/src/main.cpp b/src/main.cpp index 86ab582..b1f2722 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,7 @@ #include +#include "arugula.h" + int add(int i, int j) { return i + j; } @@ -32,6 +34,8 @@ PYBIND11_MODULE(cmake_example, m) { Some other explanation about the subtract function. )pbdoc"); + m.def("test_func", [] () { return test_func(); }); + #ifdef VERSION_INFO m.attr("__version__") = VERSION_INFO; #else