Commit 7dafdf4e authored by Michaël Roynard's avatar Michaël Roynard
Browse files

Improve packaging

parent 9d8d37f2
Pipeline #7902 failed with stages
in 5 minutes and 49 seconds
/build/*
/test_package/build/*
\ No newline at end of file
/test_package/build/*
*.pyc
\ No newline at end of file
......@@ -13,7 +13,7 @@ class Pybind11(ConanFile):
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [
True, False], "build_tests": [True, False]}
default_options = "shared=False", "fPIC=True", "build_tests=True"
default_options = "shared=False", "fPIC=True", "build_tests=False"
generators = "cmake"
def configure(self):
......@@ -30,6 +30,8 @@ class Pybind11(ConanFile):
if not self.options.build_tests:
cmake.definitions["BUILD_TESTING"] = "OFF"
else:
cmake.definitions["DOWNLOAD_CATCH"] = "ON"
cmake.configure()
return cmake
......@@ -39,7 +41,7 @@ class Pybind11(ConanFile):
cmake.build()
if self.options.build_tests:
cmake.test()
cmake.build(target="check")
def package(self):
cmake = self.get_cmake_config()
......
......@@ -4,11 +4,16 @@ cmake_minimum_required(VERSION 2.8.12)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
add_executable(test_package test_package.cpp)
target_link_libraries(test_package PRIVATE CONAN_PKG::pybind11)
find_package(PythonLibs REQUIRED)
add_library(test_package MODULE test_package.cpp)
target_include_directories(test_package PRIVATE ${PYTHON_INCLUDE_DIRS})
target_link_libraries(test_package PRIVATE CONAN_PKG::pybind11 ${PYTHON_LIBRARIES})
target_compile_features(test_package PRIVATE cxx_std_17)
# set_target_properties(test_package PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
# SUFFIX "${PYTHON_MODULE_EXTENSION}")
enable_testing()
add_test(NAME test_package
add_test(NAME test_package_py
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
COMMAND test_package)
COMMAND $(PYTHON_PREFIX) test_package.py)
\ No newline at end of file
......@@ -19,5 +19,6 @@ class BenchmarkTestConan(ConanFile):
def test(self):
if not tools.cross_building(self.settings):
os.chdir("bin")
self.run(".%stest_package" % os.sep)
os.chdir("lib")
self.run("python3 ..%s..%s..%stest_package.py" %
(os.sep, os.sep, os.sep))
#include <pybind11/pybind11.h>
namespace py = pybind11;
int main()
int add(int i, int j)
{
return 0;
return i + j;
}
PYBIND11_MODULE(test_package, m)
{
m.doc() = R"pbdoc(
Pybind11 example plugin
-----------------------
.. currentmodule:: test_package
.. autosummary::
:toctree: _generate
add
subtract
)pbdoc";
m.def("add", &add, R"pbdoc(
Add two numbers
Some other explanation about the add function.
)pbdoc");
m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc(
Subtract two numbers
Some other explanation about the subtract function.
)pbdoc");
#ifdef VERSION_INFO
m.attr("__version__") = VERSION_INFO;
#else
m.attr("__version__") = "dev";
#endif
}
import unittest
class TestPackage(unittest.TestCase):
def test_add(self):
import test_package
print(test_package.__doc__)
self.assertEqual(test_package.add(1, 2), 3)
def test_substract(self):
import test_package
self.assertEqual(test_package.substract(2, 1), 1)
if __name__ == "__main__":
unittest.main()
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