1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: ros-catkin.eclass
8 # Alexis Ballier <aballier@gentoo.org>
9 # @BLURB: Template eclass for catkin based ROS packages.
11 # Provides function for building ROS packages on Gentoo.
12 # It supports selectively building messages, multi-python installation, live ebuilds (git only).
16 die "EAPI='${EAPI}' is not supported"
22 # @ECLASS-VARIABLE: ROS_REPO_URI
24 # URL of the upstream repository. Usually on github.
25 # Serves for fetching tarballs, live ebuilds and inferring the meta-package name.
26 EGIT_REPO_URI="${ROS_REPO_URI}"
28 # @ECLASS-VARIABLE: ROS_SUBDIR
31 # Subdir in which current packages is located.
32 # Usually, a repository contains several packages, hence a typical value is:
35 # @ECLASS-VARIABLE: CATKIN_IN_SOURCE_BUILD
38 # Set to enable in-source build.
41 if [ "${PV#9999}" != "${PV}" ] ; then
45 # This should be temporary. ROS only really works with one global python
46 # version. The idea here is to have a ROS_COMPAT in the same vein as
47 # PYTHON_COMPAT where packages would define what distro they can work on, then
48 # we'd have ros_distro_gentoo_python_2_7 & co plus the OSRF ones (lunar, etc.).
49 # Note that this uncondtionally pulls python but in the ROS world there will
50 # most certainly be something pulling python anyway.
51 PYTHON_COMPAT=( python2_7 )
53 inherit ${SCM} python-r1 cmake-utils flag-o-matic
55 REQUIRED_USE="${PYTHON_REQUIRED_USE}"
58 RDEPEND="${PYTHON_DEPS}"
60 dev-util/catkin[${PYTHON_USEDEP}]
61 dev-python/empy[${PYTHON_USEDEP}]
64 # @ECLASS-VARIABLE: CATKIN_HAS_MESSAGES
66 # Set it to a non-empty value before inherit to tell the eclass the package has messages to build.
67 # Messages will be built based on ROS_MESSAGES USE_EXPANDed variable.
69 # @ECLASS-VARIABLE: CATKIN_MESSAGES_TRANSITIVE_DEPS
71 # Some messages have dependencies on other messages.
72 # In that case, CATKIN_MESSAGES_TRANSITIVE_DEPS should contain a space-separated list of atoms
73 # representing those dependencies. The eclass uses it to ensure proper dependencies on these packages.
74 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
75 IUSE="${IUSE} +ros_messages_python +ros_messages_cxx ros_messages_eus ros_messages_lisp ros_messages_nodejs"
77 ros_messages_cxx? ( dev-ros/gencpp:= dev-ros/gencpp[${PYTHON_USEDEP}] )
78 ros_messages_eus? ( dev-ros/geneus:= dev-ros/geneus[${PYTHON_USEDEP}] )
79 ros_messages_python? ( dev-ros/genpy:= dev-ros/genpy[${PYTHON_USEDEP}] )
80 ros_messages_lisp? ( dev-ros/genlisp:= dev-ros/genlisp[${PYTHON_USEDEP}] )
81 ros_messages_nodejs? ( dev-ros/gennodejs:= dev-ros/gennodejs[${PYTHON_USEDEP}] )
82 dev-ros/message_runtime
84 DEPEND="${DEPEND} ${RDEPEND}
85 dev-ros/message_generation
86 dev-ros/genmsg[${PYTHON_USEDEP}]
88 if [ -n "${CATKIN_MESSAGES_TRANSITIVE_DEPS}" ] ; then
89 for i in ${CATKIN_MESSAGES_TRANSITIVE_DEPS} ; do
90 ds="${i}[ros_messages_python(-)?,ros_messages_cxx(-)?,ros_messages_lisp(-)?,ros_messages_eus(-)?,ros_messages_nodejs(-)?] ros_messages_python? ( ${i}[${PYTHON_USEDEP}] )"
91 RDEPEND="${RDEPEND} ${ds}"
92 DEPEND="${DEPEND} ${ds}"
97 # @ECLASS-VARIABLE: CATKIN_MESSAGES_CXX_USEDEP
99 # Use it as cat/pkg[${CATKIN_MESSAGES_CXX_USEDEP}] to indicate a dependency on the C++ messages of cat/pkg.
100 CATKIN_MESSAGES_CXX_USEDEP="ros_messages_cxx(-)"
102 # @ECLASS-VARIABLE: CATKIN_MESSAGES_PYTHON_USEDEP
104 # Use it as cat/pkg[${CATKIN_MESSAGES_PYTHON_USEDEP}] to indicate a dependency on the Python messages of cat/pkg.
105 CATKIN_MESSAGES_PYTHON_USEDEP="ros_messages_python(-),${PYTHON_USEDEP}"
107 # @ECLASS-VARIABLE: CATKIN_MESSAGES_LISP_USEDEP
109 # Use it as cat/pkg[${CATKIN_MESSAGES_LISP_USEDEP}] to indicate a dependency on the Common-Lisp messages of cat/pkg.
110 CATKIN_MESSAGES_LISP_USEDEP="ros_messages_lisp(-)"
112 # @ECLASS-VARIABLE: CATKIN_MESSAGES_EUS_USEDEP
114 # Use it as cat/pkg[${CATKIN_MESSAGES_EUS_USEDEP}] to indicate a dependency on the EusLisp messages of cat/pkg.
115 CATKIN_MESSAGES_EUS_USEDEP="ros_messages_eus(-)"
117 # @ECLASS-VARIABLE: CATKIN_MESSAGES_NODEJS_USEDEP
119 # Use it as cat/pkg[${CATKIN_MESSAGES_NODEJS_USEDEP}] to indicate a dependency on the nodejs messages of cat/pkg.
120 CATKIN_MESSAGES_NODEJS_USEDEP="ros_messages_nodejs(-)"
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 # If no multibuild, just use cmake IN_SOURCE support
139 [ -n "${CATKIN_IN_SOURCE_BUILD}" ] && export CMAKE_IN_SOURCE_BUILD=yes
141 cmake-utils_src_prepare
143 if [ ! -f "${S}/CMakeLists.txt" ] ; then
144 catkin_init_workspace || die
147 # Most packages require C++11 these days. Do it here, in src_prepare so that
148 # ebuilds can override it in src_configure.
149 append-cxxflags '-std=c++11'
152 # @FUNCTION: ros-catkin_python_setup
154 # Sets up python environment for ROS packages.
155 ros-catkin_python_setup() {
156 # Todo: Need to match this with ros distro.
157 local pyimpl="${PYTHON_COMPAT[0]}"
158 python_export "${pyimpl}" EPYTHON PYTHON
160 python_export PYTHON_SCRIPTDIR
163 # @VARIABLE: mycatkincmakeargs
166 # Optional cmake defines as a bash array. Should be defined before calling
169 # @FUNCTION: ros-catkin_src_configure
171 # Configures a catkin-based package.
172 ros-catkin_src_configure() {
173 ros-catkin_python_setup
175 export CATKIN_PREFIX_PATH="${EPREFIX}/usr"
176 export ROS_ROOT="${EPREFIX}/usr/share/ros"
177 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
179 use ros_messages_cxx || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gencpp"
180 use ros_messages_eus || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:geneus"
181 use ros_messages_lisp || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genlisp"
182 use ros_messages_python || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genpy"
183 use ros_messages_nodejs || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gennodejs"
184 export ROS_LANG_DISABLE
188 "$(cmake-utils_use test CATKIN_ENABLE_TESTING)"
189 "-DCATKIN_BUILD_BINARY_PACKAGE=ON"
190 "-DCATKIN_PREFIX_PATH=${SYSROOT:-${EROOT}}/usr"
191 "${mycatkincmakeargs[@]}"
194 local sitedir="$(python_get_sitedir)"
196 -DPYTHON_EXECUTABLE="${PYTHON}"
197 -DPYTHON_INSTALL_DIR="${sitedir#${EPREFIX}/usr/}"
199 if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
200 export CMAKE_USE_DIR="${BUILD_DIR}"
203 cmake-utils_src_configure "${@}"
206 # @FUNCTION: ros-catkin_src_compile
208 # Builds a catkin-based package.
209 ros-catkin_src_compile() {
210 ros-catkin_python_setup
211 cmake-utils_src_compile "${@}"
214 # @FUNCTION: ros-catkin_src_test
216 # Run the tests of a catkin-based package.
217 ros-catkin_src_test() {
218 cd "${BUILD_DIR}" || die
220 ros-catkin_python_setup
222 # Regenerate env for tests, PYTHONPATH is not set properly otherwise...
223 if [ -f catkin_generated/generate_cached_setup.py ] ; then
224 einfo "Regenerating setup_cached.sh for tests"
225 ${PYTHON:-python} catkin_generated/generate_cached_setup.py || die
227 # Using cmake-utils_src_make with nonfatal does not work and breaks e.g.
229 if nonfatal emake tests -n &> /dev/null ; then
230 cmake-utils_src_make tests
232 cmake-utils_src_test "${@}"
235 # @FUNCTION: ros-catkin_src_install
237 # Installs a catkin-based package.
238 ros-catkin_src_install() {
239 ros-catkin_python_setup
241 if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
242 export CMAKE_USE_DIR="${BUILD_DIR}"
245 cmake-utils_src_install "${@}"
246 if [ ! -f "${T}/.catkin_python_symlinks_generated" -a -d "${D}/${PYTHON_SCRIPTDIR}" ]; then
248 for i in "${D}/${PYTHON_SCRIPTDIR}"/* ; do
249 dosym ../lib/python-exec/python-exec2 "/usr/bin/${i##*/}"
251 touch "${T}/.catkin_python_symlinks_generated" || die
255 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install