1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: ros-catkin.eclass
9 # Alexis Ballier <aballier@gentoo.org>
10 # @BLURB: Template eclass for catkin based ROS packages.
12 # Provides function for building ROS packages on Gentoo.
13 # It supports selectively building messages, multi-python installation, live ebuilds (git only).
17 die "EAPI='${EAPI}' is not supported"
23 # @ECLASS-VARIABLE: ROS_REPO_URI
25 # URL of the upstream repository. Usually on github.
26 # Serves for fetching tarballs, live ebuilds and inferring the meta-package name.
27 EGIT_REPO_URI="${ROS_REPO_URI}"
29 # @ECLASS-VARIABLE: ROS_SUBDIR
32 # Subdir in which current packages is located.
33 # Usually, a repository contains several packages, hence a typical value is:
37 if [ "${PV#9999}" != "${PV}" ] ; then
41 # @ECLASS-VARIABLE: PYTHON_COMPAT
43 # Tells the eclass the package has python code and forwards it to python-r1.eclass.
45 CATKIN_PYTHON_USEDEP=""
46 if [ -n "${PYTHON_COMPAT}" ] ; then
47 PYTHON_ECLASS="python-r1 python-utils-r1"
50 inherit ${SCM} ${PYTHON_ECLASS} cmake-utils
52 CATKIN_DO_PYTHON_MULTIBUILD=""
53 if [ -n "${PYTHON_COMPAT}" ] ; then
54 CATKIN_PYTHON_USEDEP="[${PYTHON_USEDEP}]"
55 CATKIN_DO_PYTHON_MULTIBUILD="yes"
60 dev-util/catkin${CATKIN_PYTHON_USEDEP}
61 dev-python/empy${CATKIN_PYTHON_USEDEP}
65 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
66 RDEPEND="${RDEPEND} dev-lang/python-exec:2 ${PYTHON_DEPS}"
67 DEPEND="${DEPEND} ${PYTHON_DEPS}"
70 # @ECLASS-VARIABLE: CATKIN_HAS_MESSAGES
72 # Set it to a non-empty value before inherit to tell the eclass the package has messages to build.
73 # Messages will be built based on ROS_MESSAGES USE_EXPANDed variable.
75 # @ECLASS-VARIABLE: CATKIN_MESSAGES_TRANSITIVE_DEPS
77 # Some messages have dependencies on other messages.
78 # In that case, CATKIN_MESSAGES_TRANSITIVE_DEPS should contain a space-separated list of atoms
79 # representing those dependencies. The eclass uses it to ensure proper dependencies on these packages.
80 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
81 IUSE="${IUSE} +ros_messages_python +ros_messages_cxx ros_messages_eus ros_messages_lisp"
83 ros_messages_cxx? ( dev-ros/gencpp:=${CATKIN_PYTHON_USEDEP} )
84 ros_messages_eus? ( dev-ros/geneus:=${CATKIN_PYTHON_USEDEP} )
85 ros_messages_python? ( dev-ros/genpy:=${CATKIN_PYTHON_USEDEP} )
86 ros_messages_lisp? ( dev-ros/genlisp:=${CATKIN_PYTHON_USEDEP} )
87 dev-ros/message_runtime
89 DEPEND="${DEPEND} ${RDEPEND}
90 dev-ros/message_generation
91 dev-ros/genmsg${CATKIN_PYTHON_USEDEP}
93 if [ -n "${CATKIN_MESSAGES_TRANSITIVE_DEPS}" ] ; then
94 for i in ${CATKIN_MESSAGES_TRANSITIVE_DEPS} ; do
95 ds="${i}[ros_messages_python(-)?,ros_messages_cxx(-)?,ros_messages_lisp(-)?,ros_messages_eus(-)?] ros_messages_python? ( ${i}[${PYTHON_USEDEP}] )"
96 RDEPEND="${RDEPEND} ${ds}"
97 DEPEND="${DEPEND} ${ds}"
102 # @ECLASS-VARIABLE: CATKIN_MESSAGES_CXX_USEDEP
104 # Use it as cat/pkg[${CATKIN_MESSAGES_CXX_USEDEP}] to indicate a dependency on the C++ messages of cat/pkg.
105 CATKIN_MESSAGES_CXX_USEDEP="ros_messages_cxx(-)"
107 # @ECLASS-VARIABLE: CATKIN_MESSAGES_PYTHON_USEDEP
109 # Use it as cat/pkg[${CATKIN_MESSAGES_PYTHON_USEDEP}] to indicate a dependency on the Python messages of cat/pkg.
110 CATKIN_MESSAGES_PYTHON_USEDEP="ros_messages_python(-),${PYTHON_USEDEP}"
112 # @ECLASS-VARIABLE: CATKIN_MESSAGES_LISP_USEDEP
114 # Use it as cat/pkg[${CATKIN_MESSAGES_LISP_USEDEP}] to indicate a dependency on the Common-Lisp messages of cat/pkg.
115 CATKIN_MESSAGES_LISP_USEDEP="ros_messages_lisp(-)"
117 # @ECLASS-VARIABLE: CATKIN_MESSAGES_EUS_USEDEP
119 # Use it as cat/pkg[${CATKIN_MESSAGES_EUS_USEDEP}] to indicate a dependency on the EusLisp messages of cat/pkg.
120 CATKIN_MESSAGES_EUS_USEDEP="ros_messages_eus(-)"
122 if [ "${PV#9999}" != "${PV}" ] ; then
125 S=${WORKDIR}/${P}/${ROS_SUBDIR}
127 SRC_URI="${ROS_REPO_URI}/archive/${VER_PREFIX}${PV%_*}${VER_SUFFIX}.tar.gz -> ${ROS_REPO_URI##*/}-${PV}.tar.gz"
128 S=${WORKDIR}/${VER_PREFIX}${ROS_REPO_URI##*/}-${PV}${VER_SUFFIX}/${ROS_SUBDIR}
131 HOMEPAGE="http://wiki.ros.org/${PN}"
133 # @FUNCTION: ros-catkin_src_prepare
135 # Calls cmake-utils_src_prepare (so that PATCHES array is handled there) and initialises the workspace
136 # by installing a recursive CMakeLists.txt to handle bundles.
137 ros-catkin_src_prepare() {
138 cmake-utils_src_prepare
140 if [ ! -f "${S}/CMakeLists.txt" ] ; then
141 catkin_init_workspace || die
145 # @FUNCTION: ros-catkin_src_configure_internal
147 # Internal decoration of cmake-utils_src_configure to handle multiple python installs.
148 ros-catkin_src_configure_internal() {
149 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
150 local mycmakeargs=("${mycmakeargs[@]}" -DPYTHON_EXECUTABLE="${PYTHON}")
151 python_export PYTHON_SCRIPTDIR
153 cmake-utils_src_configure "${@}"
156 # @VARIABLE: mycatkincmakeargs
159 # Optional cmake defines as a bash array. Should be defined before calling
162 # @FUNCTION: ros-catkin_src_configure
164 # Configures a catkin-based package.
165 ros-catkin_src_configure() {
166 export CMAKE_PREFIX_PATH="${EPREFIX}/usr"
167 export ROS_ROOT="${EPREFIX}/usr/share/ros"
168 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
170 use ros_messages_cxx || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gencpp"
171 use ros_messages_eus || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:geneus"
172 use ros_messages_lisp || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genlisp"
173 use ros_messages_python || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genpy"
174 export ROS_LANG_DISABLE
177 "$(cmake-utils_use test CATKIN_ENABLE_TESTING)"
178 "-DCATKIN_BUILD_BINARY_PACKAGE=ON"
179 "-DCATKIN_PREFIX_PATH=${SYSROOT:-${EROOT}}/usr"
180 "${mycatkincmakeargs[@]}"
182 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
183 python_foreach_impl ros-catkin_src_configure_internal "${@}"
185 ros-catkin_src_configure_internal "${@}"
189 # @FUNCTION: ros-catkin_src_compile
191 # Builds a catkin-based package.
192 ros-catkin_src_compile() {
193 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
194 python_foreach_impl cmake-utils_src_compile "${@}"
196 cmake-utils_src_compile "${@}"
200 # @FUNCTION: ros-catkin_src_test_internal
202 # Decorator around cmake-utils_src_test to ensure tests are built before running them.
203 ros-catkin_src_test_internal() {
204 cd "${BUILD_DIR}" || die
205 if nonfatal cmake-utils_src_make tests -n &> /dev/null ; then
206 cmake-utils_src_make tests
208 cmake-utils_src_test "${@}"
211 # @FUNCTION: ros-catkin_src_test
213 # Run the tests of a catkin-based package.
214 ros-catkin_src_test() {
215 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
216 python_foreach_impl ros-catkin_src_test_internal "${@}"
218 ros-catkin_src_test_internal "${@}"
222 # @FUNCTION: ros-catkin_src_install_with_python
224 # Decorator around cmake-utils_src_install to ensure python scripts are properly handled w.r.t. python-exec2.
225 ros-catkin_src_install_with_python() {
226 python_export PYTHON_SCRIPTDIR
227 cmake-utils_src_install "${@}"
228 if [ ! -f "${T}/.catkin_python_symlinks_generated" -a -d "${D}/${PYTHON_SCRIPTDIR}" ]; then
230 for i in "${D}/${PYTHON_SCRIPTDIR}"/* ; do
231 dosym ../lib/python-exec/python-exec2 "/usr/bin/${i##*/}"
233 touch "${T}/.catkin_python_symlinks_generated" || die
237 # @FUNCTION: ros-catkin_src_install
239 # Installs a catkin-based package.
240 ros-catkin_src_install() {
241 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
242 python_foreach_impl ros-catkin_src_install_with_python "${@}"
244 cmake-utils_src_install "${@}"
248 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install