Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions arugula/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions arugula/arugula.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "arugula.h"

// test shared lib

int
test_func()
{
return 13;
}
1 change: 1 addition & 0 deletions arugula/arugula.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int test_func();
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <pybind11/pybind11.h>

#include "arugula.h"

int add(int i, int j) {
return i + j;
}
Expand Down Expand Up @@ -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
Expand Down