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 # @ECLASS-VARIABLE: PYTHON_COMPAT
47 # Tells the eclass the package has python code and forwards it to python-r1.eclass.
49 CATKIN_PYTHON_USEDEP=""
50 if [ -n "${PYTHON_COMPAT}" ] ; then
51 PYTHON_ECLASS="python-r1"
54 inherit ${SCM} ${PYTHON_ECLASS} cmake-utils flag-o-matic
56 CATKIN_DO_PYTHON_MULTIBUILD=""
57 if [ -n "${PYTHON_COMPAT}" ] ; then
58 CATKIN_PYTHON_USEDEP="[${PYTHON_USEDEP}]"
59 CATKIN_DO_PYTHON_MULTIBUILD="yes"
60 REQUIRED_USE="${PYTHON_REQUIRED_USE}"
65 dev-util/catkin${CATKIN_PYTHON_USEDEP}
66 dev-python/empy${CATKIN_PYTHON_USEDEP}
70 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
71 RDEPEND="${RDEPEND} ${PYTHON_DEPS}"
72 DEPEND="${DEPEND} ${PYTHON_DEPS}"
75 # @ECLASS-VARIABLE: CATKIN_HAS_MESSAGES
77 # Set it to a non-empty value before inherit to tell the eclass the package has messages to build.
78 # Messages will be built based on ROS_MESSAGES USE_EXPANDed variable.
80 # @ECLASS-VARIABLE: CATKIN_MESSAGES_TRANSITIVE_DEPS
82 # Some messages have dependencies on other messages.
83 # In that case, CATKIN_MESSAGES_TRANSITIVE_DEPS should contain a space-separated list of atoms
84 # representing those dependencies. The eclass uses it to ensure proper dependencies on these packages.
85 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
86 IUSE="${IUSE} +ros_messages_python +ros_messages_cxx ros_messages_eus ros_messages_lisp ros_messages_nodejs"
88 ros_messages_cxx? ( dev-ros/gencpp:=${CATKIN_PYTHON_USEDEP} )
89 ros_messages_eus? ( dev-ros/geneus:=${CATKIN_PYTHON_USEDEP} )
90 ros_messages_python? ( dev-ros/genpy:=${CATKIN_PYTHON_USEDEP} )
91 ros_messages_lisp? ( dev-ros/genlisp:=${CATKIN_PYTHON_USEDEP} )
92 ros_messages_nodejs? ( dev-ros/gennodejs:=${CATKIN_PYTHON_USEDEP} )
93 dev-ros/message_runtime
95 DEPEND="${DEPEND} ${RDEPEND}
96 dev-ros/message_generation
97 dev-ros/genmsg${CATKIN_PYTHON_USEDEP}
99 if [ -n "${CATKIN_MESSAGES_TRANSITIVE_DEPS}" ] ; then
100 for i in ${CATKIN_MESSAGES_TRANSITIVE_DEPS} ; do
101 ds="${i}[ros_messages_python(-)?,ros_messages_cxx(-)?,ros_messages_lisp(-)?,ros_messages_eus(-)?,ros_messages_nodejs(-)?] ros_messages_python? ( ${i}[${PYTHON_USEDEP}] )"
102 RDEPEND="${RDEPEND} ${ds}"
103 DEPEND="${DEPEND} ${ds}"
108 # @ECLASS-VARIABLE: CATKIN_MESSAGES_CXX_USEDEP
110 # Use it as cat/pkg[${CATKIN_MESSAGES_CXX_USEDEP}] to indicate a dependency on the C++ messages of cat/pkg.
111 CATKIN_MESSAGES_CXX_USEDEP="ros_messages_cxx(-)"
113 # @ECLASS-VARIABLE: CATKIN_MESSAGES_PYTHON_USEDEP
115 # Use it as cat/pkg[${CATKIN_MESSAGES_PYTHON_USEDEP}] to indicate a dependency on the Python messages of cat/pkg.
116 CATKIN_MESSAGES_PYTHON_USEDEP="ros_messages_python(-),${PYTHON_USEDEP}"
118 # @ECLASS-VARIABLE: CATKIN_MESSAGES_LISP_USEDEP
120 # Use it as cat/pkg[${CATKIN_MESSAGES_LISP_USEDEP}] to indicate a dependency on the Common-Lisp messages of cat/pkg.
121 CATKIN_MESSAGES_LISP_USEDEP="ros_messages_lisp(-)"
123 # @ECLASS-VARIABLE: CATKIN_MESSAGES_EUS_USEDEP
125 # Use it as cat/pkg[${CATKIN_MESSAGES_EUS_USEDEP}] to indicate a dependency on the EusLisp messages of cat/pkg.
126 CATKIN_MESSAGES_EUS_USEDEP="ros_messages_eus(-)"
128 # @ECLASS-VARIABLE: CATKIN_MESSAGES_NODEJS_USEDEP
130 # Use it as cat/pkg[${CATKIN_MESSAGES_NODEJS_USEDEP}] to indicate a dependency on the nodejs messages of cat/pkg.
131 CATKIN_MESSAGES_NODEJS_USEDEP="ros_messages_nodejs(-)"
133 if [ "${PV#9999}" != "${PV}" ] ; then
136 S=${WORKDIR}/${P}/${ROS_SUBDIR}
138 SRC_URI="${ROS_REPO_URI}/archive/${VER_PREFIX}${PV%_*}${VER_SUFFIX}.tar.gz -> ${ROS_REPO_URI##*/}-${PV}.tar.gz"
139 S=${WORKDIR}/${VER_PREFIX}${ROS_REPO_URI##*/}-${PV}${VER_SUFFIX}/${ROS_SUBDIR}
142 HOMEPAGE="http://wiki.ros.org/${PN}"
144 # @FUNCTION: ros-catkin_src_prepare
146 # Calls cmake-utils_src_prepare (so that PATCHES array is handled there) and initialises the workspace
147 # by installing a recursive CMakeLists.txt to handle bundles.
148 ros-catkin_src_prepare() {
149 # If no multibuild, just use cmake IN_SOURCE support
150 [ -n "${CATKIN_IN_SOURCE_BUILD}" ] && [ -z "${CATKIN_DO_PYTHON_MULTIBUILD}" ] && export CMAKE_IN_SOURCE_BUILD=yes
152 cmake-utils_src_prepare
154 if [ ! -f "${S}/CMakeLists.txt" ] ; then
155 catkin_init_workspace || die
158 # If python multibuild, copy the sources
159 [ -n "${CATKIN_IN_SOURCE_BUILD}" ] && [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] && python_copy_sources
161 # Most packages require C++11 these days. Do it here, in src_prepare so that
162 # ebuilds can override it in src_configure.
163 append-cxxflags '-std=c++11'
166 # @FUNCTION: ros-catkin_src_configure_internal
168 # Internal decoration of cmake-utils_src_configure to handle multiple python installs.
169 ros-catkin_src_configure_internal() {
170 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
171 local sitedir="$(python_get_sitedir)"
174 -DPYTHON_EXECUTABLE="${PYTHON}"
175 -DPYTHON_INSTALL_DIR="${sitedir#${EPREFIX}/usr/}"
177 python_export PYTHON_SCRIPTDIR
178 if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
179 export CMAKE_USE_DIR="${BUILD_DIR}"
182 cmake-utils_src_configure "${@}"
185 # @VARIABLE: mycatkincmakeargs
188 # Optional cmake defines as a bash array. Should be defined before calling
191 # @FUNCTION: ros-catkin_src_configure
193 # Configures a catkin-based package.
194 ros-catkin_src_configure() {
195 export CATKIN_PREFIX_PATH="${EPREFIX}/usr"
196 export ROS_ROOT="${EPREFIX}/usr/share/ros"
197 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
199 use ros_messages_cxx || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gencpp"
200 use ros_messages_eus || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:geneus"
201 use ros_messages_lisp || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genlisp"
202 use ros_messages_python || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genpy"
203 use ros_messages_nodejs || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gennodejs"
204 export ROS_LANG_DISABLE
207 "$(cmake-utils_use test CATKIN_ENABLE_TESTING)"
208 "-DCATKIN_BUILD_BINARY_PACKAGE=ON"
209 "-DCATKIN_PREFIX_PATH=${SYSROOT:-${EROOT}}/usr"
210 "${mycatkincmakeargs[@]}"
212 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
213 python_foreach_impl ros-catkin_src_configure_internal "${@}"
215 ros-catkin_src_configure_internal "${@}"
219 # @FUNCTION: ros-catkin_src_compile
221 # Builds a catkin-based package.
222 ros-catkin_src_compile() {
223 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
224 if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
225 export CMAKE_USE_DIR="${BUILD_DIR}"
227 python_foreach_impl cmake-utils_src_compile "${@}"
229 cmake-utils_src_compile "${@}"
233 # @FUNCTION: ros-catkin_src_test_internal
235 # Decorator around cmake-utils_src_test to ensure tests are built before running them.
236 ros-catkin_src_test_internal() {
237 cd "${BUILD_DIR}" || die
238 # Regenerate env for tests, PYTHONPATH is not set properly otherwise...
239 if [ -f catkin_generated/generate_cached_setup.py ] ; then
240 einfo "Regenerating setup_cached.sh for tests"
241 ${PYTHON:-python} catkin_generated/generate_cached_setup.py || die
243 # Using cmake-utils_src_make with nonfatal does not work and breaks e.g.
245 if nonfatal emake tests -n &> /dev/null ; then
246 cmake-utils_src_make tests
248 cmake-utils_src_test "${@}"
251 # @FUNCTION: ros-catkin_src_test
253 # Run the tests of a catkin-based package.
254 ros-catkin_src_test() {
255 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
256 python_foreach_impl ros-catkin_src_test_internal "${@}"
258 ros-catkin_src_test_internal "${@}"
262 # @FUNCTION: ros-catkin_src_install_with_python
264 # Decorator around cmake-utils_src_install to ensure python scripts are properly handled w.r.t. python-exec2.
265 ros-catkin_src_install_with_python() {
266 python_export PYTHON_SCRIPTDIR
267 if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
268 export CMAKE_USE_DIR="${BUILD_DIR}"
270 cmake-utils_src_install "${@}"
271 if [ ! -f "${T}/.catkin_python_symlinks_generated" -a -d "${D}/${PYTHON_SCRIPTDIR}" ]; then
273 for i in "${D}/${PYTHON_SCRIPTDIR}"/* ; do
274 dosym ../lib/python-exec/python-exec2 "/usr/bin/${i##*/}"
276 touch "${T}/.catkin_python_symlinks_generated" || die
280 # @FUNCTION: ros-catkin_src_install
282 # Installs a catkin-based package.
283 ros-catkin_src_install() {
284 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
285 python_foreach_impl ros-catkin_src_install_with_python "${@}"
287 cmake-utils_src_install "${@}"
291 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install