Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Olena
conan-pybind11
Commits
7dafdf4e
Commit
7dafdf4e
authored
Apr 03, 2019
by
Michaël Roynard
Browse files
Improve packaging
parent
9d8d37f2
Pipeline
#7902
failed with stages
in 5 minutes and 49 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
7dafdf4e
/build/*
/test_package/build/*
\ No newline at end of file
/test_package/build/*
*.pyc
\ No newline at end of file
conanfile.py
View file @
7dafdf4e
...
...
@@ -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=
Tru
e"
default_options
=
"shared=False"
,
"fPIC=True"
,
"build_tests=
Fals
e"
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
()
...
...
test_package/CMakeLists.txt
View file @
7dafdf4e
...
...
@@ -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
test_package/conanfile.py
View file @
7dafdf4e
...
...
@@ -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
))
test_package/test_package.cpp
View file @
7dafdf4e
#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
}
test_package/test_package.py
0 → 100644
View file @
7dafdf4e
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
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment