summaryrefslogtreecommitdiff
path: root/ext/pybind11/tests/test_cmake_build
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pybind11/tests/test_cmake_build')
-rw-r--r--ext/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt12
-rw-r--r--ext/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt22
-rw-r--r--ext/pybind11/tests/test_cmake_build/main.cpp10
-rw-r--r--ext/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt8
-rw-r--r--ext/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt15
-rw-r--r--ext/pybind11/tests/test_cmake_build/test.py5
6 files changed, 72 insertions, 0 deletions
diff --git a/ext/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt b/ext/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt
new file mode 100644
index 000000000..e0c20a8a3
--- /dev/null
+++ b/ext/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(test_installed_module CXX)
+
+set(CMAKE_MODULE_PATH "")
+
+find_package(pybind11 CONFIG REQUIRED)
+message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
+
+pybind11_add_module(test_cmake_build SHARED NO_EXTRAS ../main.cpp)
+
+add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
+ ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME})
diff --git a/ext/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt b/ext/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt
new file mode 100644
index 000000000..cd3ae6f7d
--- /dev/null
+++ b/ext/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt
@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 3.0)
+project(test_installed_target CXX)
+
+set(CMAKE_MODULE_PATH "")
+
+find_package(pybind11 CONFIG REQUIRED)
+message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
+
+add_library(test_cmake_build MODULE ../main.cpp)
+
+target_link_libraries(test_cmake_build PRIVATE pybind11::module)
+
+# make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib
+set_target_properties(test_cmake_build PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
+ SUFFIX "${PYTHON_MODULE_EXTENSION}")
+
+# Do not treat includes from IMPORTED target as SYSTEM (Python headers in pybind11::module).
+# This may be needed to resolve header conflicts, e.g. between Python release and debug headers.
+set_target_properties(test_cmake_build PROPERTIES NO_SYSTEM_FROM_IMPORTED ON)
+
+add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
+ ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME})
diff --git a/ext/pybind11/tests/test_cmake_build/main.cpp b/ext/pybind11/tests/test_cmake_build/main.cpp
new file mode 100644
index 000000000..e0f5b69c9
--- /dev/null
+++ b/ext/pybind11/tests/test_cmake_build/main.cpp
@@ -0,0 +1,10 @@
+#include <pybind11/pybind11.h>
+namespace py = pybind11;
+
+PYBIND11_PLUGIN(test_cmake_build) {
+ py::module m("test_cmake_build");
+
+ m.def("add", [](int i, int j) { return i + j; });
+
+ return m.ptr();
+}
diff --git a/ext/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt b/ext/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt
new file mode 100644
index 000000000..278007aeb
--- /dev/null
+++ b/ext/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(test_subdirectory_module CXX)
+
+add_subdirectory(${PYBIND11_PROJECT_DIR} pybind11)
+pybind11_add_module(test_cmake_build THIN_LTO ../main.cpp)
+
+add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
+ ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME})
diff --git a/ext/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt b/ext/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt
new file mode 100644
index 000000000..6b142d62a
--- /dev/null
+++ b/ext/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 3.0)
+project(test_subdirectory_target CXX)
+
+add_subdirectory(${PYBIND11_PROJECT_DIR} pybind11)
+
+add_library(test_cmake_build MODULE ../main.cpp)
+
+target_link_libraries(test_cmake_build PRIVATE pybind11::module)
+
+# make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib
+set_target_properties(test_cmake_build PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
+ SUFFIX "${PYTHON_MODULE_EXTENSION}")
+
+add_custom_target(check ${CMAKE_COMMAND} -E env PYTHONPATH=$<TARGET_FILE_DIR:test_cmake_build>
+ ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/../test.py ${PROJECT_NAME})
diff --git a/ext/pybind11/tests/test_cmake_build/test.py b/ext/pybind11/tests/test_cmake_build/test.py
new file mode 100644
index 000000000..1467a61dc
--- /dev/null
+++ b/ext/pybind11/tests/test_cmake_build/test.py
@@ -0,0 +1,5 @@
+import sys
+import test_cmake_build
+
+assert test_cmake_build.add(1, 2) == 3
+print("{} imports, runs, and adds: 1 + 2 = 3".format(sys.argv[1]))