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 python-utils-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"
64 dev-util/catkin${CATKIN_PYTHON_USEDEP}
65 dev-python/empy${CATKIN_PYTHON_USEDEP}
69 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
70 RDEPEND="${RDEPEND} dev-lang/python-exec:2 ${PYTHON_DEPS}"
71 DEPEND="${DEPEND} ${PYTHON_DEPS}"
74 # @ECLASS-VARIABLE: CATKIN_HAS_MESSAGES
76 # Set it to a non-empty value before inherit to tell the eclass the package has messages to build.
77 # Messages will be built based on ROS_MESSAGES USE_EXPANDed variable.
79 # @ECLASS-VARIABLE: CATKIN_MESSAGES_TRANSITIVE_DEPS
81 # Some messages have dependencies on other messages.
82 # In that case, CATKIN_MESSAGES_TRANSITIVE_DEPS should contain a space-separated list of atoms
83 # representing those dependencies. The eclass uses it to ensure proper dependencies on these packages.
84 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
85 IUSE="${IUSE} +ros_messages_python +ros_messages_cxx ros_messages_eus ros_messages_lisp ros_messages_nodejs"
87 ros_messages_cxx? ( dev-ros/gencpp:=${CATKIN_PYTHON_USEDEP} )
88 ros_messages_eus? ( dev-ros/geneus:=${CATKIN_PYTHON_USEDEP} )
89 ros_messages_python? ( dev-ros/genpy:=${CATKIN_PYTHON_USEDEP} )
90 ros_messages_lisp? ( dev-ros/genlisp:=${CATKIN_PYTHON_USEDEP} )
91 ros_messages_nodejs? ( dev-ros/gennodejs:=${CATKIN_PYTHON_USEDEP} )
92 dev-ros/message_runtime
94 DEPEND="${DEPEND} ${RDEPEND}
95 dev-ros/message_generation
96 dev-ros/genmsg${CATKIN_PYTHON_USEDEP}
98 if [ -n "${CATKIN_MESSAGES_TRANSITIVE_DEPS}" ] ; then
99 for i in ${CATKIN_MESSAGES_TRANSITIVE_DEPS} ; do
100 ds="${i}[ros_messages_python(-)?,ros_messages_cxx(-)?,ros_messages_lisp(-)?,ros_messages_eus(-)?,ros_messages_nodejs(-)?] ros_messages_python? ( ${i}[${PYTHON_USEDEP}] )"
101 RDEPEND="${RDEPEND} ${ds}"
102 DEPEND="${DEPEND} ${ds}"
107 # @ECLASS-VARIABLE: CATKIN_MESSAGES_CXX_USEDEP
109 # Use it as cat/pkg[${CATKIN_MESSAGES_CXX_USEDEP}] to indicate a dependency on the C++ messages of cat/pkg.
110 CATKIN_MESSAGES_CXX_USEDEP="ros_messages_cxx(-)"
112 # @ECLASS-VARIABLE: CATKIN_MESSAGES_PYTHON_USEDEP
114 # Use it as cat/pkg[${CATKIN_MESSAGES_PYTHON_USEDEP}] to indicate a dependency on the Python messages of cat/pkg.
115 CATKIN_MESSAGES_PYTHON_USEDEP="ros_messages_python(-),${PYTHON_USEDEP}"
117 # @ECLASS-VARIABLE: CATKIN_MESSAGES_LISP_USEDEP
119 # Use it as cat/pkg[${CATKIN_MESSAGES_LISP_USEDEP}] to indicate a dependency on the Common-Lisp messages of cat/pkg.
120 CATKIN_MESSAGES_LISP_USEDEP="ros_messages_lisp(-)"
122 # @ECLASS-VARIABLE: CATKIN_MESSAGES_EUS_USEDEP
124 # Use it as cat/pkg[${CATKIN_MESSAGES_EUS_USEDEP}] to indicate a dependency on the EusLisp messages of cat/pkg.
125 CATKIN_MESSAGES_EUS_USEDEP="ros_messages_eus(-)"
127 # @ECLASS-VARIABLE: CATKIN_MESSAGES_NODEJS_USEDEP
129 # Use it as cat/pkg[${CATKIN_MESSAGES_NODEJS_USEDEP}] to indicate a dependency on the nodejs messages of cat/pkg.
130 CATKIN_MESSAGES_NODEJS_USEDEP="ros_messages_nodejs(-)"
132 if [ "${PV#9999}" != "${PV}" ] ; then
135 S=${WORKDIR}/${P}/${ROS_SUBDIR}
137 SRC_URI="${ROS_REPO_URI}/archive/${VER_PREFIX}${PV%_*}${VER_SUFFIX}.tar.gz -> ${ROS_REPO_URI##*/}-${PV}.tar.gz"
138 S=${WORKDIR}/${VER_PREFIX}${ROS_REPO_URI##*/}-${PV}${VER_SUFFIX}/${ROS_SUBDIR}
141 HOMEPAGE="http://wiki.ros.org/${PN}"
143 # @FUNCTION: ros-catkin_src_prepare
145 # Calls cmake-utils_src_prepare (so that PATCHES array is handled there) and initialises the workspace
146 # by installing a recursive CMakeLists.txt to handle bundles.
147 ros-catkin_src_prepare() {
148 # If no multibuild, just use cmake IN_SOURCE support
149 [ -n "${CATKIN_IN_SOURCE_BUILD}" ] && [ -z "${CATKIN_DO_PYTHON_MULTIBUILD}" ] && export CMAKE_IN_SOURCE_BUILD=yes
151 cmake-utils_src_prepare
153 if [ ! -f "${S}/CMakeLists.txt" ] ; then
154 catkin_init_workspace || die
157 # If python multibuild, copy the sources
158 [ -n "${CATKIN_IN_SOURCE_BUILD}" ] && [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] && python_copy_sources
160 # Most packages require C++11 these days. Do it here, in src_prepare so that
161 # ebuilds can override it in src_configure.
162 append-cxxflags '-std=c++11'
165 # @FUNCTION: ros-catkin_src_configure_internal
167 # Internal decoration of cmake-utils_src_configure to handle multiple python installs.
168 ros-catkin_src_configure_internal() {
169 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
170 local sitedir="$(python_get_sitedir)"
173 -DPYTHON_EXECUTABLE="${PYTHON}"
174 -DPYTHON_INSTALL_DIR="${sitedir#${EPREFIX}/usr/}"
176 python_export PYTHON_SCRIPTDIR
177 if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
178 export CMAKE_USE_DIR="${BUILD_DIR}"
181 cmake-utils_src_configure "${@}"
184 # @VARIABLE: mycatkincmakeargs
187 # Optional cmake defines as a bash array. Should be defined before calling
190 # @FUNCTION: ros-catkin_src_configure
192 # Configures a catkin-based package.
193 ros-catkin_src_configure() {
194 export CATKIN_PREFIX_PATH="${EPREFIX}/usr"
195 export ROS_ROOT="${EPREFIX}/usr/share/ros"
196 if [ -n "${CATKIN_HAS_MESSAGES}" ] ; then
198 use ros_messages_cxx || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gencpp"
199 use ros_messages_eus || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:geneus"
200 use ros_messages_lisp || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genlisp"
201 use ros_messages_python || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:genpy"
202 use ros_messages_nodejs || ROS_LANG_DISABLE="${ROS_LANG_DISABLE}:gennodejs"
203 export ROS_LANG_DISABLE
206 "$(cmake-utils_use test CATKIN_ENABLE_TESTING)"
207 "-DCATKIN_BUILD_BINARY_PACKAGE=ON"
208 "-DCATKIN_PREFIX_PATH=${SYSROOT:-${EROOT}}/usr"
209 "${mycatkincmakeargs[@]}"
211 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
212 python_foreach_impl ros-catkin_src_configure_internal "${@}"
214 ros-catkin_src_configure_internal "${@}"
218 # @FUNCTION: ros-catkin_src_compile
220 # Builds a catkin-based package.
221 ros-catkin_src_compile() {
222 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
223 if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
224 export CMAKE_USE_DIR="${BUILD_DIR}"
226 python_foreach_impl cmake-utils_src_compile "${@}"
228 cmake-utils_src_compile "${@}"
232 # @FUNCTION: ros-catkin_src_test_internal
234 # Decorator around cmake-utils_src_test to ensure tests are built before running them.
235 ros-catkin_src_test_internal() {
236 cd "${BUILD_DIR}" || die
237 # Regenerate env for tests, PYTHONPATH is not set properly otherwise...
238 if [ -f catkin_generated/generate_cached_setup.py ] ; then
239 einfo "Regenerating setup_cached.sh for tests"
240 ${PYTHON:-python} catkin_generated/generate_cached_setup.py || die
242 # Using cmake-utils_src_make with nonfatal does not work and breaks e.g.
244 if nonfatal emake tests -n &> /dev/null ; then
245 cmake-utils_src_make tests
247 cmake-utils_src_test "${@}"
250 # @FUNCTION: ros-catkin_src_test
252 # Run the tests of a catkin-based package.
253 ros-catkin_src_test() {
254 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
255 python_foreach_impl ros-catkin_src_test_internal "${@}"
257 ros-catkin_src_test_internal "${@}"
261 # @FUNCTION: ros-catkin_src_install_with_python
263 # Decorator around cmake-utils_src_install to ensure python scripts are properly handled w.r.t. python-exec2.
264 ros-catkin_src_install_with_python() {
265 python_export PYTHON_SCRIPTDIR
266 if [ -n "${CATKIN_IN_SOURCE_BUILD}" ] ; then
267 export CMAKE_USE_DIR="${BUILD_DIR}"
269 cmake-utils_src_install "${@}"
270 if [ ! -f "${T}/.catkin_python_symlinks_generated" -a -d "${D}/${PYTHON_SCRIPTDIR}" ]; then
272 for i in "${D}/${PYTHON_SCRIPTDIR}"/* ; do
273 dosym ../lib/python-exec/python-exec2 "/usr/bin/${i##*/}"
275 touch "${T}/.catkin_python_symlinks_generated" || die
279 # @FUNCTION: ros-catkin_src_install
281 # Installs a catkin-based package.
282 ros-catkin_src_install() {
283 if [ -n "${CATKIN_DO_PYTHON_MULTIBUILD}" ] ; then
284 python_foreach_impl ros-catkin_src_install_with_python "${@}"
286 cmake-utils_src_install "${@}"
290 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install