mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
Simplify generation of pybind11 modules
* Install module libs into CATKIN_GLOBAL_PYTHON_DESTINATION (assuming unique names). This avoids the need to link them into the source space, because they are found also from devel space. * Use pybind11's def_submodule() to create the `core` and `stages` submodules, everything linked into the same lib
This commit is contained in:
parent
d9b7aa37a3
commit
3cf92442fb
@ -1 +1 @@
|
||||
from ._python_tools import *
|
||||
from pymoveit_python_tools import *
|
||||
|
||||
@ -0,0 +1 @@
|
||||
from . import core, stages
|
||||
@ -1 +1 @@
|
||||
from ._core import *
|
||||
from pymoveit_mtc.core import *
|
||||
|
||||
@ -1,2 +1 @@
|
||||
from ._core import Stage
|
||||
from ._stages import *
|
||||
from pymoveit_mtc.stages import *
|
||||
|
||||
@ -19,62 +19,27 @@ install(TARGETS ${TOOLS_LIB_NAME}
|
||||
)
|
||||
|
||||
|
||||
# python_tools
|
||||
set(TOOLS_LIB_NAME _python_tools)
|
||||
configure_file(src/python_tools.cpp.in python_tools.cpp @ONLY)
|
||||
pybind11_add_module(${TOOLS_LIB_NAME} MODULE ${CMAKE_CURRENT_BINARY_DIR}/python_tools.cpp)
|
||||
target_link_libraries(${TOOLS_LIB_NAME} PRIVATE moveit_python_tools)
|
||||
# moveit.python_tools
|
||||
pybind11_add_module(pymoveit_python_tools src/python_tools.cpp)
|
||||
target_link_libraries(pymoveit_python_tools PRIVATE ${TOOLS_LIB_NAME})
|
||||
set_target_properties(pymoveit_python_tools PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION})
|
||||
|
||||
# python tools: configure install directory and create symlink in source space
|
||||
set(MOVEIT_PYTHON_MODULE_PATH moveit/python_tools)
|
||||
install(TARGETS ${TOOLS_LIB_NAME}
|
||||
LIBRARY DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION}/${MOVEIT_PYTHON_MODULE_PATH}
|
||||
)
|
||||
add_custom_command(TARGET ${TOOLS_LIB_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E create_symlink "$<TARGET_FILE:${TOOLS_LIB_NAME}>" "${CMAKE_CURRENT_SOURCE_DIR}/../src/${MOVEIT_PYTHON_MODULE_PATH}/$<TARGET_FILE_NAME:${TOOLS_LIB_NAME}>"
|
||||
COMMENT "Creating symlink to ${TOOLS_LIB_NAME} in source space"
|
||||
)
|
||||
|
||||
|
||||
# core
|
||||
set(CORE_LIB_NAME _core)
|
||||
# moveit.task_constructor
|
||||
set(INCLUDES ${PROJECT_SOURCE_DIR}/include/moveit/python/task_constructor)
|
||||
configure_file(src/core.cpp.in core.cpp @ONLY)
|
||||
pybind11_add_module(${CORE_LIB_NAME} SHARED
|
||||
pybind11_add_module(pymoveit_mtc
|
||||
${INCLUDES}/properties.h
|
||||
|
||||
src/properties.cpp
|
||||
src/solvers.cpp
|
||||
src/core.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/core.cpp
|
||||
)
|
||||
target_include_directories(${CORE_LIB_NAME}
|
||||
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
)
|
||||
target_link_libraries(${CORE_LIB_NAME} PUBLIC ${PROJECT_NAME} moveit_python_tools)
|
||||
|
||||
|
||||
# stages
|
||||
set(STAGES_LIB_NAME _stages)
|
||||
configure_file(src/stages.cpp.in stages.cpp @ONLY)
|
||||
pybind11_add_module(${STAGES_LIB_NAME} MODULE
|
||||
src/stages.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/stages.cpp
|
||||
src/module.cpp
|
||||
)
|
||||
target_link_libraries(${STAGES_LIB_NAME} PUBLIC ${PROJECT_NAME}_stages ${CORE_LIB_NAME} moveit_python_tools)
|
||||
target_include_directories(pymoveit_mtc PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
|
||||
target_link_libraries(pymoveit_mtc PUBLIC ${PROJECT_NAME} ${PROJECT_NAME}_stages ${TOOLS_LIB_NAME})
|
||||
set_target_properties(pymoveit_mtc PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_PYTHON_DESTINATION})
|
||||
|
||||
|
||||
|
||||
# core, stages: configure install directory
|
||||
set(MOVEIT_PYTHON_MODULE_PATH moveit/task_constructor)
|
||||
install(TARGETS ${CORE_LIB_NAME} ${STAGES_LIB_NAME}
|
||||
LIBRARY DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION}/${MOVEIT_PYTHON_MODULE_PATH}
|
||||
# install python libs
|
||||
install(TARGETS pymoveit_python_tools pymoveit_mtc
|
||||
LIBRARY DESTINATION ${CATKIN_GLOBAL_PYTHON_DESTINATION}
|
||||
)
|
||||
# Add symlinks from source space to devel-space libs
|
||||
# This is necessary to find them from devel-space too
|
||||
foreach(tgt ${CORE_LIB_NAME} ${STAGES_LIB_NAME})
|
||||
add_custom_command(TARGET ${tgt} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E create_symlink "$<TARGET_FILE:${tgt}>" "${CMAKE_CURRENT_SOURCE_DIR}/../src/${MOVEIT_PYTHON_MODULE_PATH}/$<TARGET_FILE_NAME:${tgt}>"
|
||||
COMMENT "Creating symlink to ${tgt} in source space"
|
||||
)
|
||||
endforeach()
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
namespace moveit {
|
||||
namespace python {
|
||||
|
||||
void export_properties(pybind11::module& m);
|
||||
void export_solvers(pybind11::module& m);
|
||||
void export_core(pybind11::module& m);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
PYBIND11_MODULE(@CORE_LIB_NAME@, m) {
|
||||
m.doc() = "MoveIt Task Constructor";
|
||||
|
||||
moveit::python::export_properties(m);
|
||||
moveit::python::export_solvers(m);
|
||||
moveit::python::export_core(m);
|
||||
}
|
||||
26
core/python/wrapper/src/module.cpp
Normal file
26
core/python/wrapper/src/module.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
namespace moveit {
|
||||
namespace python {
|
||||
|
||||
void export_properties(pybind11::module& m);
|
||||
void export_solvers(pybind11::module& m);
|
||||
void export_core(pybind11::module& m);
|
||||
void export_stages(pybind11::module& m);
|
||||
|
||||
} // namespace python
|
||||
} // namespace moveit
|
||||
|
||||
PYBIND11_MODULE(pymoveit_mtc, m) {
|
||||
m.doc() = "MoveIt Task Constructor";
|
||||
|
||||
auto msub = m.def_submodule("core");
|
||||
msub.doc() = "MTC core components";
|
||||
moveit::python::export_properties(msub);
|
||||
moveit::python::export_solvers(msub);
|
||||
moveit::python::export_core(msub);
|
||||
|
||||
msub = m.def_submodule("stages");
|
||||
msub.doc() = "MTC stages";
|
||||
moveit::python::export_stages(msub);
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
namespace py = pybind11;
|
||||
using namespace moveit::python;
|
||||
|
||||
PYBIND11_MODULE(@TOOLS_LIB_NAME@, m) {
|
||||
PYBIND11_MODULE(pymoveit_python_tools, m) {
|
||||
m.doc() = "MoveIt python tools";
|
||||
|
||||
m.def("roscpp_init", &InitProxy::init, "Initialize C++ ROS", py::arg("node_name") = "moveit_python_wrapper",
|
||||
@ -1,14 +0,0 @@
|
||||
#include <pybind11/pybind11.h>
|
||||
|
||||
namespace moveit {
|
||||
namespace python {
|
||||
|
||||
void export_stages(pybind11::module& m);
|
||||
|
||||
} }
|
||||
|
||||
PYBIND11_MODULE(@STAGES_LIB_NAME@, m) {
|
||||
m.doc() = "MoveIt Task Constructor Stages";
|
||||
|
||||
moveit::python::export_stages(m);
|
||||
}
|
||||
@ -1,11 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from setuptools import setup
|
||||
from setuptools import find_packages, setup
|
||||
from catkin_pkg.python_setup import generate_distutils_setup
|
||||
|
||||
d = generate_distutils_setup(
|
||||
# list of packages to setup
|
||||
packages=["moveit", "moveit.python_tools", "moveit.task_constructor"],
|
||||
packages=find_packages("python/src"),
|
||||
# specify location of root ("") package dir
|
||||
package_dir={"": "python/src"},
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user