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 ros_messages_nodejs"
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 ros_messages_nodejs? ( dev-ros/gennodejs:=${CATKIN_PYTHON_USEDEP} )
88 dev-ros/message_runtime
90 DEPEND="${DEPEND} ${RDEPEND}
91 dev-ros/message_generation
92 dev-ros/genmsg${CATKIN_PYTHON_USEDEP}
94 if [ -n "${CATKIN_MESSAGES_TRANSITIVE_DEPS}" ] ; then
95 for i in ${CATKIN_MESSAGES_TRANSITIVE_DEPS} ; do
96 ds="${i}[ros_messages_python(-)?,ros_messages_cxx(-)?,ros_messages_lisp(-)?,ros_messages_eus(-)?,ros_messages_nodejs(-)?] ros_messages_python? ( ${i}[${PYTHON_USEDEP}] )"
97 RDEPEND="${RDEPEND} ${ds}"
98 DEPEND="${DEPEND} ${ds}"
103 # @ECLASS-VARIABLE: CATKIN_MESSAGES_CXX_USEDEP
105 # Use it as cat/pkg[${CATKIN_MESSAGES_CXX_USEDEP}] to indicate a dependency on the C++ messages of cat/pkg.
106 CATKIN_MESSAGES_CXX_USEDEP="ros_messages_cxx(-)"
108 # @ECLASS-VARIABLE: CATKIN_MESSAGES_PYTHON_USEDEP
110 # Use it as cat/pkg[${CATKIN_MESSAGES_PYTHON_USEDEP}] to indicate a dependency on the Python messages of cat/pkg.
111 CATKIN_MESSAGES_PYTHON_USEDEP="ros_messages_python(-),${PYTHON_USEDEP}"
113 # @ECLASS-VARIABLE: CATKIN_MESSAGES_LISP_USEDEP
115 # Use it as cat/pkg[${CATKIN_MESSAGES_LISP_USEDEP}] to indicate a dependency on the Common-Lisp messages of cat/pkg.
116 CATKIN_MESSAGES_LISP_USEDEP="ros_messages_lisp(-)"
118 # @ECLASS-VARIABLE: CATKIN_MESSAGES_EUS_USEDEP
120 # Use it as cat/pkg[${CATKIN_MESSAGES_EUS_USEDEP}] to indicate a dependency on the EusLisp messages of cat/pkg.
121 CATKIN_MESSAGES_EUS_USEDEP="ros_messages_eus(-)"
123 # @ECLASS-VARIABLE: CATKIN_MESSAGES_NODEJS_USEDEP
125 # Use it as cat/pkg[${CATKIN_MESSAGES_NODEJS_USEDEP}] to indicate a dependency on the nodejs messages of cat/pkg.
126 CATKIN_MESSAGES_NODEJS_USEDEP="ros_messages_nodejs(-)"
128 if [ "${PV#9999}" != "${PV}" ] ; then
131 S=${WORKDIR}/${P}/${ROS_SUBDIR}
133 SRC_URI="${ROS_REPO_URI}/archive/${VER_PREFIX}${PV%_*}${VER_SUFFIX}.tar.gz -> ${ROS_REPO_URI##*/}-${PV}.tar.gz"
134 S=${WORKDIR}/${VER_PREFIX}${ROS_REPO_URI##*/}-${PV}${VER_SUFFIX}/${ROS_SUBDIR}
137 HOMEPAGE="http://wiki.ros.org/${PN}"
139 # @FUNCTION: ros-catkin_src_prepare
141 # Calls cmake-utils_src_prepare (so that PATCHES array is handled there) and initialises the workspace
142 # by installing a recursive CMakeLists.txt to handle bundles.
143 ros-catkin_src_prepare() {
144 cmake-utils_src_prepare
146 if [ ! -f "${S}/CMakeLists.txt" ] ; then
147 catkin_init_workspace || die
151 # @FUNCTION: ros-catkin_src_configure_internal
153 # Internal decoration of cmake-utils_src_configure to handle multiple python installs.
154 ros-catkin_src_configure_internal() {
155 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
156 local mycmakeargs=("${mycmakeargs[@]}" -DPYTHON_EXECUTABLE="${PYTHON}")
157 python_export PYTHON_SCRIPTDIR
159 cmake-utils_src_configure "${@}"
162 # @VARIABLE: mycatkincmakeargs
165 # Optional cmake defines as a bash array. Should be defined before calling
168 # @FUNCTION: ros-catkin_src_configure
170 # Configures a catkin-based package.
171 ros-catkin_src_configure() {
172 export CMAKE_PREFIX_PATH="${EPREFIX}/usr"
173 export ROS_ROOT="${EPREFIX}/usr/share/ros"
174 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
176 use ros_messages_cxx || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gencpp"
177 use ros_messages_eus || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:geneus"
178 use ros_messages_lisp || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genlisp"
179 use ros_messages_python || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genpy"
180 use ros_messages_nodejs || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gennodejs"
181 export ROS_LANG_DISABLE
184 "$(cmake-utils_use test CATKIN_ENABLE_TESTING)"
185 "-DCATKIN_BUILD_BINARY_PACKAGE=ON"
186 "-DCATKIN_PREFIX_PATH=${SYSROOT:-${EROOT}}/usr"
187 "${mycatkincmakeargs[@]}"
189 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
190 python_foreach_impl ros-catkin_src_configure_internal "${@}"
192 ros-catkin_src_configure_internal "${@}"
196 # @FUNCTION: ros-catkin_src_compile
198 # Builds a catkin-based package.
199 ros-catkin_src_compile() {
200 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
201 python_foreach_impl cmake-utils_src_compile "${@}"
203 cmake-utils_src_compile "${@}"
207 # @FUNCTION: ros-catkin_src_test_internal
209 # Decorator around cmake-utils_src_test to ensure tests are built before running them.
210 ros-catkin_src_test_internal() {
211 cd "${BUILD_DIR}" || die
212 # Using cmake-utils_src_make with nonfatal does not work and breaks e.g.
214 if nonfatal emake tests -n &> /dev/null ; then
215 cmake-utils_src_make tests
217 cmake-utils_src_test "${@}"
220 # @FUNCTION: ros-catkin_src_test
222 # Run the tests of a catkin-based package.
223 ros-catkin_src_test() {
224 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
225 python_foreach_impl ros-catkin_src_test_internal "${@}"
227 ros-catkin_src_test_internal "${@}"
231 # @FUNCTION: ros-catkin_src_install_with_python
233 # Decorator around cmake-utils_src_install to ensure python scripts are properly handled w.r.t. python-exec2.
234 ros-catkin_src_install_with_python() {
235 python_export PYTHON_SCRIPTDIR
236 cmake-utils_src_install "${@}"
237 if [ ! -f "${T}/.catkin_python_symlinks_generated" -a -d "${D}/${PYTHON_SCRIPTDIR}" ]; then
239 for i in "${D}/${PYTHON_SCRIPTDIR}"/* ; do
240 dosym ../lib/python-exec/python-exec2 "/usr/bin/${i##*/}"
242 touch "${T}/.catkin_python_symlinks_generated" || die
246 # @FUNCTION: ros-catkin_src_install
248 # Installs a catkin-based package.
249 ros-catkin_src_install() {
250 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
251 python_foreach_impl ros-catkin_src_install_with_python "${@}"
253 cmake-utils_src_install "${@}"
257 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install