diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc28c5a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +install/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f04501c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,34 @@ +language: c++ +sudo: false + +addons: + apt: + packages: + - build-essential + - git + - cmake + - libboost-all-dev + - libxml-xpath-perl + - omniorb + - omniidl + - omniorb-idl + - omniorb-nameserver + - libomniorb4-dev + +matrix: + include: + - os: linux + dist: trusty + - os: osx + osx_image: xcode7.3 + - os: osx + osx_image: xcode8.2 + +before_install: + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew reinstall boost cmake readline omniorb gnu-getopt ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew link --force gnu-getopt ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew link --force readline ; fi + +script: + - ./install.sh --verbose --prefix $HOME/install --enable-corba --enable-mqueue diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..96a168f --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,166 @@ +# The OROCOS Toolchain Installation Guide + +This document explains how the [Orocos](http://www.orocos.org/) toolchain can be installed and configured. + +## Table of Contents + + +- [Table of Contents](#table-of-contents) +- [Introduction](#introduction) + - [Supported platforms (targets)](#supported-platforms-targets) + - [The versioning scheme](#the-versioning-scheme) + - [Dependencies on other libraries](#dependencies-on-other-libraries) +- [Binary packages](#binary-packages) + - [Ubuntu and Debian](#ubuntu-and-debian) +- [Install from source](#install-from-source) + - [Build tools and dependencies](#build-tools-and-dependencies) + - [Debian/Ubuntu](#debianubuntu) + - [Other Linux distributions](#other-linux-distributions) + - [MacOS X](#macos-x) + - [Windows](#windows) + - [Quick start](#quick-start) + - [Download the sources](#download-the-sources) + - [Download source archive](#download-source-archive) + - [Clone from GitHub](#clone-from-github) + - [3. Build and Install](#3-build-and-install) +- [Getting Started](#getting-started) +- [Cross Compiling Orocos](#cross-compiling-orocos) + + + +## Introduction + +This sections explains the supported Orocos targets and the Orocos versioning scheme. + +### Supported platforms (targets) + +Orocos was designed with portability in mind. Currently, we support RTAI/LXRT (http://www.rtai.org), GNU/Linux userspace, Xenomai (http://www.xenomai.org), Mac OS X (http://www.apple.com) and native Windows using Microsoft Visual Studio. So, you can first write your software as a normal Linux/Mac OS X program, using the framework for testing and debugging purposes in plain userspace (Linux/Mac OS X) and recompile later to a real-time target or MS Windows. + +### The versioning scheme + +A particular version is represented by three numbers separated by dots. For example: + +2.8.1 : Release 2, Feature update 8, bug-fix revision 1. + +### Dependencies on other libraries + +Before you install Orocos, verify that you have the following software installed on your platform: + +| Program / Library | Minimum Version | Description | +|---------------------------------|-------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| CMake | 2.8.3 (all platforms) | See resources on cmake.org for pre-compiled packages in case your distribution does not support this version | +| Boost C++ Library | 1.33.0 (1.40.0 recommended!) | Boost.org from version 1.33.0 on has a very efficient (time/space) lock-free smart pointer implementation which is used by Orocos. 1.36.0 has boost::intrusive which we require on Windows with MSVS. 1.40.0 has a shared_ptr implementation we require when building Service objects. | +| Boost C++ Test Library | 1.33.0 (During build only) | Boost.org test library ('unit_test_framework') is required if you build the RTT from source and ENABLE_TESTS=ON (default). The RTT libraries don't depend on this library, it is only used for building our unit tests. | +| Boost C++ Thread Library | 1.33.0 (Mac OS-X only) | Boost.org thread library is required on Mac OS-X. | +| Boost C++ Serialization Library | 1.37.0 | Boost.org serialization library is required for the type system and the MQueue transport. | +| GNU gcc / g++ Compilers | 3.4.0 (Linux/Cygwin/Mac OS X) | gcc.gnu.org Orocos builds with the GCC 4.x series as well. | +| MSVS Compilers | 2005 | One can download the MS VisualStudio 2008 Express edition for free. | +| Xerces C++ Parser | 2.1 (Optional) | Xerces website Versions 2.1 until 3.1 are known to work. If not found, an internal XML parser is used. | +| ACE & TAO | TAO 1.3 (Optional) | ACE & TAO website When you start your components in a networked environment, TAO can be used to set up communication between components. CORBA is used as a 'background' transport and is hidden for normal users. | +| Omniorb | 4 (Optional) | Omniorb website Omniorb is more robust and faster than TAO, but has less features. CORBA is used as a 'background' transport and is hidden for normal users. | + +All these packages are provided by most Linux distributions. In Mac OS X, you can install them easily using fink or macports. Take also a look on the Orocos.org RTT download page for the latest information. + +## Binary packages + +### Ubuntu and Debian + +The [Robot Operating System (ROS)](http://www.ros.org/) project provides binary packages for Ubuntu and Debian Jessie. See [REP 3 - Target Platforms](http://www.ros.org/reps/rep-0003.html) for a list of supported platforms. The dependencies of the Orocos core packages to other ROS packages are minimal. This is the recommended way to get started with the toolchain for Ubuntu and Debian users. + +Check out the [ROS Installation instructions](http://wiki.ros.org/ROS/Installation) for detailed instructions on how to install a ROS base system. Afterwards, the Orocos Toolchain can be installed with the command + +``` +sudo apt-get install ros--orocos-toolchain +``` + +## Install from source + +### Build tools and dependencies + +#### Debian/Ubuntu + +Most dependencies mentioned above can be installed using the APT package management system: + +``` +sudo apt-get install build-essential git cmake libboost-all-dev libxml-xpath-perl +``` + +*Optional:* In case you want to build RTT with CORBA support, you also need to install the OmniORB (recommended) or TAO development packages: + +``` +sudo apt-get install omniorb omniidl omniorb-idl omniorb-nameserver libomniorb4-dev +``` + +#### Other Linux distributions +*TODO* + +#### MacOS X +*TODO* + +#### Windows +*TODO* + +### Quick start + +The [orocos_toolchain](https://github.com/orocos-toolchain/orocos_toolchain) repository contains a shell script which implements all of the following steps and is the recommended way to install the Orocos toolchain from source: + +For Linux: +``` +mkdir -p ~/orocos-toolchain +cd ~/orocos-toolchain +wget https://raw.githubusercontent.com/orocos-toolchain/orocos_toolchain/master/install.sh +./install.sh --help +``` + +If you want to download or clone the sources manually and have full control over the build process, feel free to go o + +### Download the sources + +#### Download source archive + +The latest released version of the toolchain can be downloaded from here: +http://www.orocos.org/orocos/toolchain + +Extract the archive into a source directory, e.g. `~/orocos-toolchain`: +``` +mkdir -p ~/orocos-toolchain && cd ~/orocos-toolchain +wget http://www.orocos.org/stable/toolchain/v2.x.x/orocos-toolchain-2.x.x-src.tar.bz2 +tar xvjf orocos-toolchain-2.x.x-src.tar.bz2 +cd orocos-toolchain-* +``` + +Note that the archive files provided by GitHub at https://github.com/orocos-toolchain/orocos_toolchain/releases will not work as the repository contains submodules, which are unfortunately not included in the files. + +#### Clone from GitHub + +If you want to use the latest development version or actively contribute to Orocos, it is recommended to clone the toolchain directly from GitHub: + +``` +mkdir -p ~/orocos-toolchain && cd ~/orocos-toolchain +git clone --recursive https://github.com/orocos-toolchain/orocos_toolchain.git +cd orocos-toolchain +``` + +In order to select a specific major and minor version of the toolchain, you can specify the branch to be cloned explicitly with the `-b` option, e.g.: + +``` +mkdir -p ~/orocos-toolchain && cd ~/orocos-toolchain +git clone --recursive https://github.com/orocos-toolchain/orocos_toolchain.git -b toolchain-2.9 +cd orocos-toolchain +``` + +The `--recursive` argument is required because the toolchain GIT repository uses submodules to manage the links to the individual source repositories. + +### 3. Build and Install + +All toolchain packages rely on cmake as the underlying build tool, but every package has to be configured, build and installed in isolation. +Advanced users can invoke cmake and make directly or use [catkin](http://wiki.ros.org/catkin) or [catkin_tools](https://catkin-tools.readthedocs.io/en/latest/) as a build tool. +Otherwise it is recommended to use the `install.sh` script provided in the toolchain repository, which iterates over all toolchain packages in the right order and invokes cmake, make and make install within the `build/` directory for each of them. + +## Getting Started + +*to be copied from http://www.orocos.org/stable/documentation/rtt/v2.x/doc-xml/orocos-installation.html* + +## Cross Compiling Orocos + +*to be copied from http://www.orocos.org/stable/documentation/rtt/v2.x/doc-xml/orocos-installation.html* diff --git a/README.md b/README.md new file mode 100644 index 0000000..2d62578 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# The OROCOS Toolchain + +The Open RObot COntrol Software ([Orocos](http://www.orocos.org/)) Toolchain is a bundle of multiple packages, which need to be build and installed separately. + +- [Orocos Real-Time Toolkit (rtt)](https://github.com/orocos-toolchain/rtt) - a component framework that allows us to write real-time components in C++ +- [Orocos Log4cpp (log4cpp)](https://github.com/orocos-toolchain/log4cpp) - + a patched version of the [Log4cpp](http://log4cpp.sourceforge.net/) library for flexible logging to files, syslog, IDSA and other destinations +- [Orocos Component Library (ocl)](https://github.com/orocos-toolchain/ocl) - the necessary components to start an application and interact with it at run-time + +Until version 2.8 [orogen](http://www.rock-robotics.org/stable/documentation/orogen/) and [typegen](http://www.rock-robotics.org/stable/documentation/orogen/), tools to generate ready-to-compile-and-run code from existing headers or component description files based on the Ruby language, have been an integral part of the Orocos Toolchain. For later versions we refer to the installation instructions of the [Rock - the Robot Construction Kit](http://www.rock-robotics.org/stable/index.html) project. + +You might also want to have a look at the following sister projects, which are out of the scope of this manual: +- [Orocos Kinematics Dynamics Library (KDL)](http://www.orocos.org/kdl) - an application independent framework for modeling and computation of kinematic chains +- [Orocos Bayesian Filtering Library (BFL)](http://www.orocos.org/bfl) - an application independent framework for inference in Dynamic Bayesian Networks, i.e., recursive information processing and estimation algorithms based on Bayes' rule +- [Reduced Finite State Machine (rFSM)](https://orocos.github.io/rFSM/README.html) - a small and powerful statechart implementation in Lua + +## Get Started? +Check out [INSTALL.md](INSTALL.md). diff --git a/env.sh b/env.sh old mode 100644 new mode 100755 index ecfd8c1..1cb9a55 --- a/env.sh +++ b/env.sh @@ -1,34 +1,42 @@ +#!/bin/sh +# +# The purpose of this script is to setup the environment for the Orocos Toolchain +# (like setup.sh) and execute a command. +# +# Usage: env.sh COMMANDS +# +# This file will be installed to CMAKE_INSTALL_PREFIX by cmake with the +# @-references replaced by the value of the respective cmake variable. +# -RUBY_VERSION=`ruby --version | awk '{ print $2; }' | sed -e "s/\(.*\..*\)\..*/\1/"` -RUBY_ARCH=`ruby --version | sed -e 's/.*\[\(.*\)\]/\1/'` -export RUBYOPT=-rubygems -export TYPELIB_USE_GCCXML=1 - - -if [ x$ROS_ROOT != x ]; then -### ROS -export RUBYLIB=`rospack find utilrb`/lib:`rospack find orogen`/lib:`rosstack find orocos_toolchain`/install/lib/ruby/${RUBY_VERSION}/${RUBY_ARCH}:`rosstack find orocos_toolchain`/install/lib/ruby/${RUBY_VERSION} -export GEM_HOME=`rosstack find orocos_toolchain`/.gems -export PATH=`rosstack find orocos_toolchain`/install/bin:`rospack find orogen`/bin:`rosstack find orocos_toolchain`/.gems/bin:$PATH -export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:`rosstack find orocos_toolchain`/install/lib/pkgconfig +if [ $# -eq 0 ] ; then + if [ -z "$BASH_SOURCE" -a -z "$_" ]; then + /bin/echo "Usage: env.sh COMMANDS" >&2 + exit 1 + fi +fi -elif [ x${BASH} != x ]; then -### Bash non-ROS -cd `dirname ${BASH_SOURCE[0]}` -envpath=$PWD -cd - > /dev/null -export RUBYLIB=$envpath/utilrb/lib:$envpath/orogen/lib:$envpath/install/lib/ruby/${RUBY_VERSION}/${RUBY_ARCH}:$envpath/install/lib/ruby/${RUBY_VERSION} -export GEM_HOME=$envpath/.gems -export PATH=$envpath/install/bin:$envpath/orogen/bin:$envpath/.gems/bin:$PATH -export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:$envpath/install/lib/pkgconfig +# find OROCOS installation folder from CMAKE_INSTALL_PREFIX or $0 +case "@CMAKE_INSTALL_PREFIX@" in + @*) ;; + *) OROCOS_INSTALL_PREFIX="@CMAKE_INSTALL_PREFIX@" ;; +esac +if [ -z "$OROCOS_INSTALL_PREFIX" ]; then + OROCOS_INSTALL_PREFIX=`dirname $0` + OROCOS_INSTALL_PREFIX=`cd ${OROCOS_INSTALL_PREFIX}; pwd` +fi -elif [ `basename $PWD` = orocos_toolchain ]; then -### non-Bash, non-ROS -export RUBYLIB=$PWD/utilrb/lib:$PWD/orogen/lib:$PWD/install/lib/ruby/${RUBY_VERSION}/${RUBY_ARCH}:$PWD/install/lib/ruby/${RUBY_VERSION} -export GEM_HOME=$PWD/.gems -export PATH=$PWD/install/bin:$PWD/orogen/bin:$PWD/.gems/bin:$PATH -export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:$PWD/install/lib/pkgconfig +# source setup.sh +if [ -f ${OROCOS_INSTALL_PREFIX}/setup.sh ]; then + . ${OROCOS_INSTALL_PREFIX}/setup.sh +elif [ -f ${OROCOS_INSTALL_PREFIX}/etc/orocos/setup.sh ]; then + . ${OROCOS_INSTALL_PREFIX}/etc/orocos/setup.sh +elif [ -f /etc/orocos/setup.sh ]; then + . /etc/orocos/setup.sh else - echo "Error: This script must be sourced from the 'orocos_toolchain' directory when not running in a ROS_ROOT nor bash environment." - echo + echo "env.sh: could not find Orocos setup.sh script" >&2 + [ $# -eq 0 ] || exit 1 fi + +# execute command +[ $# -eq 0 ] || exec "$@" diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..4d86903 --- /dev/null +++ b/install.sh @@ -0,0 +1,479 @@ +#!/bin/bash + +set -e # abort on error +#cd $(dirname $0) + +# ############################################################################## +# Default options +# ############################################################################## +DEFAULT_PREFIX=/usr/local +: ${PREFIX:=$DEFAULT_PREFIX} +if [ -e .git ]; then + # build in-source + DEFAULT_SOURCES=`readlink -fm . 2>/dev/null || readlink . || echo $PWD` +else + # build out of source + DEFAULT_SOURCES=`readlink -fm src/orocos-toolchain 2>/dev/null || readlink src/orocos-toolchain || echo src/orocos-toolchain` +fi +: ${SOURCES:=$DEFAULT_SOURCES} +DEFAULT_GIT_BASE_URL=https://github.com/orocos-toolchain/ +: ${GIT_BASE_URL:=$DEFAULT_GIT_BASE_URL} +DEFAULT_GIT_BRANCH= +: ${GIT_BRANCH:=$DEFAULT_GIT_BRANCH} +DEFAULT_CMAKE_BUILD_TYPE=Release +: ${CMAKE_BUILD_TYPE:=$DEFAULT_CMAKE_BUILD_TYPE} +CMAKE_ARGS=( ) +MAKE_ARGS=( ) + +VERBOSE= +YES= +CLEAN= + +# assumption: Git remote URL = ${GIT_BASE_URL}${PACKAGES[i]}.git +PACKAGES=( + log4cpp + rtt + ocl + #utilrb + #typelib + #rtt_typelib + #orogen + orocos_toolchain +) + + +FEATURES=( corba mqueue tests ) +FEATURES_ENABLED=( ) +FEATURES_DISABLED=( ) +: ${CORBA_IMPLEMENTATION:=OMNIORB} +: ${OROCOS_TARGET:=} + +# ############################################################################## +# Functions +# ############################################################################## +function help() +{ + cat << EOF >&2 +Usage: ${0##*/} [options] + +This installation script will assist you with the process of + + * cloning the Orocos toolchain source repositories using git + * configuring Orocos and + * building and installing Orocos. + + -h,--help Show this help + -v,--verbose Be more verbose + + Git options: + + --branch, -b Clone/checkout branch of all source repositories + (default: upstream HEAD) + --url, -u Git base url (default: ${DEFAULT_GIT_BASE_URL}) + + Build and configuration options: + + --prefix The installation prefix (default: ${DEFAULT_PREFIX}) + --source, -s The source directory (default: ${DEFAULT_SOURCES}) + --clean, -c Clean build folder before rebuilding + -d, --debug[=CMAKE_BUILD_TYPE] + Build in Debug mode. The argument is optional and + overwrites the default CMAKE_BUILD_TYPE Debug. + The default build type without the --debug option + is ${DEFAULT_CMAKE_BUILD_TYPE}. + --target, -t The OROCOS target platform, one of [gnulinux, lxrt, + xenomai, ecos, macosx, win32]. If not specified, + Orocos will figure this out itself. + + --enable- Enable feature or plugin (see below) + --disable- Disable feature or plugin (see below) + + -D= Set cmake variable + --cmake-args Arbitrary arguments which are passes to cmake. + Collects all of following arguments until a "--" is + read. + --make-args Arbitrary arguments which are passes to make. + Collects all of following arguments until a "--" is + read. + -j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg. + + Known features (for --(enable|disable)- options): + * corba: The CORBA transport plugin + * mqueue: The POSIX message queue transport plugin + * tests: Enable tests + +EOF +} + +# missing_dependencies=( ) +# function do_check_dependencies() +# { +# # cmake +# cmake=`which cmake >/dev/null 2>/dev/null` +# if [ -z "$cmake" ]; then +# do_install_system_package cmake +# else +# cmake_version=`${cmake} --version` +# cmake_version=${cmake_version#cmake version } +# echo "[${SCRIPT_NAME}] Found cmake version ${cmake_version} in ${cmake}." >&2 +# fi +# +# # boost +# if ! ${cmake} --find-package -DNAME=Boost -DCOMPILER=GNU -DLANGUAGE=CXX -DMODE=EXIST >/dev/null 2>&1; then +# do_install_system_package boost +# else +# echo "[${SCRIPT_NAME}] Found Boost." >&2 +# fi +# +# # warn about missing dependencies +# if [ -n "${missing_dependencies}" ]; then +# echo "The following system dependencies could not be found:" >&2 +# for dep in "${missing_dependencies[@]}"; do +# echo " - ${dep}" >&2 +# done +# echo >&2 +# echo -n "Continue anyway [Y/n]? " >&2 +# read -n1 response +# echo >&2 +# if [[ "$response" = "n" || "$response" = "N" ]]; then exit 1; fi +# fi +# } +# +# function do_install_system_package() +# { +# # skip installation if --no-deps was given in the command line +# if [ "$NO_DEPS" = true ]; then +# missing_dependencies+=( $1 ) +# return +# fi +# +# # forward to the correct system tool depending on the OS +# if [[ "$LINUX_DISTRO" == "Ubuntu" || +# "$LINUX_DISTRO" == "Debian" ]]; then +# do_install_system_package_debian "$@" +# return +# fi +# +# missing_dependencies+=( $1 ) +# } +# +# function do_install_system_package_debian() +# { +# debian_packages= +# case "$1" in +# boost) +# debian_packages=libboost-all-dev ;; +# cmake) +# debian_packages=cmake ;; +# esac +# +# for pkg in ${debian_packages}; do +# # check if the package is already installed +# if [ `/usr/bin/dpkg-query -W -f='${Status}' $pkg` = "install ok installed" ]; then +# continue +# fi +# # check if the package is already installed +# do_run apt-get install $YES $pkg +# done +# } + +function do_clone_sources() +{ + # create source directory + do_run mkdir -p ${SOURCES} + + # clone orocos_toolchain repository to ${SOURCES} + do_clone_package_source_or_check_branch orocos_toolchain "${SOURCES}" ${GIT_BRANCH} + + # clone all other package repositories to ${SOURCES}/package + for pkg in "${PACKAGES[@]}"; do + if [ "$pkg" = "orocos_toolchain" ]; then continue; fi + do_clone_package_source_or_check_branch $pkg "${SOURCES}/$pkg" ${GIT_BRANCH} + done +} + +function do_clone_package_source_or_check_branch() +{ + pkg="$1" + dir="$2" + git_branch="$3" + + # compose branch option + git_branch_option= + if [ -n "${git_branch}" ]; then + git_branch_option="-b ${git_branch}" + fi + + if [[ ! -f "${dir}/CMakeLists.txt" && ! -f "${dir}/.gitmodules" ]]; then + [ -n "$VERBOSE" ] && echo "[$SCRIPT_NAME] Cloning $pkg to ${dir}." >&2 + do_run git clone --recursive ${git_branch_option} "${GIT_BASE_URL}${pkg}.git" "${dir}" + else + [ -n "$VERBOSE" ] && echo "[$SCRIPT_NAME] Found ${pkg} in ${dir}." >&2 + + if [ -e "${dir}/.git" ]; then + current_git_branch=`cd "${dir}" && git rev-parse --abbrev-ref HEAD` + if [[ -n "$current_git_branch" && -n "$git_branch" + && "$current_git_branch" != "$git_branch" ]]; then + [ -n "$VERBOSE" ] && echo "[$SCRIPT_NAME] Checking out branch '${git_branch}' of the source repository for package $pkg..." >&2 + ( + do_run cd "${dir}" && do_run git checkout ${git_branch} + ) + fi + fi + fi +} + +function do_build_and_install() +{ + # clean build folder + if [ "$CLEAN" = true ]; then + do_run rm -rf build/ + fi + + # set CMAKE_BUILD_TYPE + if [ -n "$CMAKE_BUILD_TYPE" ]; then + CMAKE_ARGS=( -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} "${CMAKE_ARGS[@]}" ) + fi + + # set OROCOS_TARGET + if [ -n "$OROCOS_TARGET" ]; then + CMAKE_ARGS+=( -DOROCOS_TARGET="${OROCOS_TARGET}" ) + fi + + # add additional cmake options for enabled features + FEATURE_CMAKE_ARGS=( ) + for feature in "${FEATURES[@]}"; do + case "$feature" in + corba) + if is_feature_enabled $feature; then + FEATURE_CMAKE_ARGS+=( -DENABLE_CORBA=ON ) + if [ "${CMAKE_ARGS[$@]}" != "*-DCORBA_IMPLEMENTATION=*" ]; then + FEATURE_CMAKE_ARGS+=( -DCORBA_IMPLEMENTATION=${CORBA_IMPLEMENTATION} ) + fi + elif is_feature_disabled $feature; then + FEATURE_CMAKE_ARGS+=( -DENABLE_CORBA=OFF ) + fi ;; + mqueue) + if is_feature_enabled $feature; then + FEATURE_CMAKE_ARGS+=( -DENABLE_MQ=ON ) + elif is_feature_disabled $feature; then + FEATURE_CMAKE_ARGS+=( -DENABLE_MQ=OFF ) + fi ;; + tests) + if is_feature_enabled $feature; then + FEATURE_CMAKE_ARGS+=( -DENABLE_TESTS=ON ) + elif is_feature_disabled $feature; then + FEATURE_CMAKE_ARGS+=( -DENABLE_TESTS=OFF ) + fi ;; + esac + done + + # enable verbosity in make + if [ -n "$VERBOSE" ]; then + MAKE_ARGS+=( VERBOSE=1 ) + fi + + # build and install packages + for pkg in "${PACKAGES[@]}"; do + if [ ! -d "${SOURCES}/$pkg" ]; then continue; fi + + echo "*******************************************************************************" >&2 + echo "** Building package $pkg" >&2 + echo "*******************************************************************************" >&2 + do_run mkdir -p build/$pkg && do_run pushd build/$pkg >/dev/null + do_run cmake "${SOURCES}/$pkg" \ + -DCMAKE_INSTALL_PREFIX="${PREFIX}" \ + "${FEATURE_CMAKE_ARGS[@]}" "${CMAKE_ARGS[@]}" + do_run make ${JOBS} "${MAKE_ARGS[@]}" + do_run make install + do_run popd + echo >&2 + done +} + +function do_run() +{ + if [ -n "${VERBOSE}" ]; then + echo "[${SCRIPT_NAME}] Executing \`$@\`" >&2 + fi + "$@" + return $? +} + +function is_feature_enabled() +{ + for x in "${FEATURES_ENABLED[@]}"; do + if [ "$x" = "$1" ]; then return 0; fi + done + return 1 +} + +function is_feature_disabled() +{ + for x in "${FEATURES_DISABLED[@]}"; do + if [ "$x" = "$1" ]; then return 0; fi + done + return 1 +} + +# ############################################################################## +# Detect platform settings +# ############################################################################## +PLATFORM=`uname -s || true` +if [ "$PLATFORM" = "Linux" ]; then + LINUX_DISTRO=`lsb_release -si || true` + LINUX_CODENAME=`lsb_release -sc || true` +fi + +# ############################################################################## +# Parse command line options +# ############################################################################## +SCRIPT_NAME="${0##*/}" + +# copy command line options to OPTIONS array and parse --make-args, --cmake-args, +# -D... and --enable-* and --disable-* options because getopt cannot handle them +declare -a OPTIONS +while [ $# -gt 0 ]; do + case "$1" in + -D*) + CMAKE_ARGS+=( "$1" ) + shift ;; + --make-args) + shift + while [ $# -gt 0 ]; do + if [ "$1" == "--" ]; then + shift + break + fi + MAKE_ARGS+=( "$1" ) + shift + done ;; + --cmake-args) + shift + while [ $# -gt 0 ]; do + if [ "$1" == "--" ]; then + shift + break + fi + CMAKE_ARGS+=( "$1" ) + shift + done ;; + --enable-*) + FEATURES_ENABLED+=( "${1#--enable-}" ) + shift ;; + --disable-*) + FEATURES_DISABLED+=( "${1#--disable-}" ) + shift ;; + *) + OPTIONS+=( "$1" ) + shift ;; + esac +done + +# parse remaining command line options +TEMP=`getopt \ + --options -hvyb:u:s:cd::t:j:: \ + --long help,verbose,branch:,url:,no-deps,yes,prefix:,source:,clean,debug::,target:,jobs:: \ + -n "${SCRIPT_NAME}" -- "${OPTIONS[@]}"` +if [ $? -ne 0 ]; then exit $?; fi +eval set -- "$TEMP" + +while true; do + case "$1" in + -h|--help) + help + exit 0 ;; + -v|--verbose) + VERBOSE=-v + shift ;; + -y|--yes) + YES=-y + shift ;; + -b|--branch) + GIT_BRANCH="$2" + shift 2 ;; + -u|--url) + GIT_BASE_URL="$2" + if [ "${GIT_URL}" = "${GIT_BASE_URL%/}" ]; then + GIT_BASE_URL="${GIT_BASE_URL}/" + fi + shift 2 ;; + --no-deps) + NO_DEPS=true + shift ;; + --prefix) + PREFIX=`readlink -fm "$2" 2>/dev/null || readlink "$2" || echo "$2"` + shift 2 ;; + -s|--source) + SOURCES=`readlink -fm "$2" 2>/dev/null || readlink "$2" || echo "$2"` + shift 2 ;; + -c|--clean) + CLEAN=true + shift ;; + -d|--debug) + CMAKE_BUILD_TYPE="$2" + : ${CMAKE_BUILD_TYPE:=Debug} + shift 2 ;; + -t|--target) + OROCOS_TARGET="$2" + shift 2 ;; + -j|--jobs) + JOBS="-j$2" + shift 2 ;; + --) + shift; break ;; + *) + echo "Unknown option: $1" >&2 + exit 1 ;; + esac +done + +if [ -n "$VERBOSE" ]; then + [ -n "${PLATFORM}" ] && echo "[$SCRIPT_NAME] Detected platform: ${PLATFORM}" >&2 + [ -n "${LINUX_DISTRO}${LINUX_CODENAME}" ] && echo "[$SCRIPT_NAME] Detected distribution: ${LINUX_DISTRO} ${LINUX_CODENAME}" >&2 + [ -n "${SOURCES}" ] && echo "[$SCRIPT_NAME] Building from sources in ${SOURCES}" >&2 + [ -n "${OROCOS_TARGET}" ] && echo "[$SCRIPT_NAME] Building for OROCOS target \"${OROCOS_TARGET}\"" >&2 + [ -n "${CMAKE_BUILD_TYPE}" ] && echo "[$SCRIPT_NAME] Building with CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}" >&2 + [ -n "${PREFIX}" ] && echo "[$SCRIPT_NAME] Installing to ${PREFIX}" >&2 + [ -n "${FEATURES_ENABLED}" ] && echo "[$SCRIPT_NAME] Enabled OROCOS features: ${FEATURES_ENABLED[@]}" >&2 + [ -n "${FEATURES_DISABLED}" ] && echo "[$SCRIPT_NAME] Disabled OROCOS features: ${FEATURES_DISABLED[@]}" >&2 + [ -n "${JOBS}" ] && echo "[$SCRIPT_NAME] Make job options: ${JOBS}" >&2 + echo >&2 +fi + +# ############################################################################## +# Main +# ############################################################################## +#do_check_dependencies +do_clone_sources +do_build_and_install + +# ############################################################################## +# Success message +# ############################################################################## +echo "*******************************************************************************" >&2 +echo "** DONE!" >&2 +echo "*******************************************************************************" >&2 +echo "Successfully built and installed the following packages:" >&2 +for pkg in "${PACKAGES[@]}"; do + echo " - ${pkg}" >&2 +done +echo >&2 + +if [ -f "${PREFIX}/setup.sh" ]; then + cat <&2 +You should source the setup.sh script in the installation folder to setup your environment +before you continue: + + . ${PREFIX}/setup.sh + +END +elif [ -f "${PREFIX}/etc/orocos/setup.sh" ]; then + cat <&2 +You should source the setup.sh script in etc/orocos/setup.sh to setup your environment +before you continue: + + . ${PREFIX}/etc/orocos/setup.sh + +END +fi diff --git a/orocos_toolchain/CMakeLists.txt b/orocos_toolchain/CMakeLists.txt index 6f762bf..d08741b 100644 --- a/orocos_toolchain/CMakeLists.txt +++ b/orocos_toolchain/CMakeLists.txt @@ -1,4 +1,59 @@ cmake_minimum_required(VERSION 2.8.3) project(orocos_toolchain) -find_package(catkin REQUIRED) -catkin_metapackage() + +find_package(catkin QUIET) +if(catkin_FOUND) + catkin_metapackage() + +else() + install(FILES + package.xml + DESTINATION share/${PROJECT_NAME}/ + ) +endif() + +# need to find Orocos RTT to set OROCOS_TARGET and other cmake variables +find_package(OROCOS-RTT REQUIRED) + +set(OROCOS_SETUP_DESTINATION "etc/orocos" CACHE STRING "Destination folder for Orocos setup files (setup.sh, env.sh), relative to CMAKE_INSTALL_PREFIX") +configure_file(../setup.sh ${CMAKE_CURRENT_BINARY_DIR}/setup.sh @ONLY) +configure_file(../env.sh ${CMAKE_CURRENT_BINARY_DIR}/env.sh @ONLY) + +if(OROCOS_SETUP_DESTINATION) + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/setup.sh" + DESTINATION "${CMAKE_INSTALL_PREFIX}/${OROCOS_SETUP_DESTINATION}" + ) + install(PROGRAMS + "${CMAKE_CURRENT_BINARY_DIR}/env.sh" + DESTINATION "${CMAKE_INSTALL_PREFIX}/${OROCOS_SETUP_DESTINATION}" + ) +endif() + +# Install setup files directly to CMAKE_INSTALL_PREFIX if we are not +# installing to a default location, but do not override setup files +# installed by catkin or when building a binary package using bloom. +if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT + AND NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr" + AND NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" + AND NOT CATKIN_BUILD_BINARY_PACKAGE) + install(CODE " + if(NOT EXISTS \"\${CMAKE_INSTALL_PREFIX}/setup.sh\") + file(INSTALL + \"${CMAKE_CURRENT_BINARY_DIR}/setup.sh\" + DESTINATION \"\${CMAKE_INSTALL_PREFIX}\" + ) + else() + message(STATUS \"Keeping original: \${CMAKE_INSTALL_PREFIX}/setup.sh\") + endif() + if(NOT EXISTS \"\${CMAKE_INSTALL_PREFIX}/env.sh\") + file(INSTALL + \"${CMAKE_CURRENT_BINARY_DIR}/env.sh\" + DESTINATION \"\${CMAKE_INSTALL_PREFIX}\" + FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE + ) + else() + message(STATUS \"Keeping original: \${CMAKE_INSTALL_PREFIX}/env.sh\") + endif() + ") +endif() diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..3112c6d --- /dev/null +++ b/setup.sh @@ -0,0 +1,90 @@ +#!/bin/sh +# +# The purpose of this script is to setup the environment for the Orocos Toolchain. +# +# Usage: . @CMAKE_INSTALL_PREFIX@/@OROCOS_SETUP_DESTINATION@/setup.sh +# +# This file will be installed to CMAKE_INSTALL_PREFIX by cmake with the +# @-references replaced by the value of the respective cmake variable. +# + +# find OROCOS installation folder from CMAKE_INSTALL_PREFIX, BASH_SOURCE or $_ +case "@CMAKE_INSTALL_PREFIX@" in + @*) ;; + *) OROCOS_INSTALL_PREFIX="@CMAKE_INSTALL_PREFIX@" ;; +esac +if [ -z "$OROCOS_INSTALL_PREFIX" ]; then + if [ -n "$BASH_SOURCE" ]; then + OROCOS_INSTALL_PREFIX=`dirname ${BASH_SOURCE[0]}` + OROCOS_INSTALL_PREFIX=`cd ${OROCOS_INSTALL_PREFIX}; pwd` + elif [ -n "$_" ]; then + OROCOS_INSTALL_PREFIX=`dirname $_` + OROCOS_INSTALL_PREFIX=`cd ${OROCOS_INSTALL_PREFIX}; pwd` + else + echo "Could not determine the OROCOS installation prefix for your shell." >&2 + exit 1 + fi +fi + +# initialize OROCOS_TARGET if unset +if [ -z "${OROCOS_TARGET}" ]; then + case "@OROCOS_TARGET@" in + @*) ;; + *) OROCOS_TARGET="@OROCOS_TARGET@" ;; + esac +fi + +# add bin/ to PATH +if [ -d ${OROCOS_INSTALL_PREFIX}/bin ]; then + if ! echo $PATH | grep -q "${OROCOS_INSTALL_PREFIX}/bin"; then + PATH="${PATH}:${OROCOS_INSTALL_PREFIX}/bin" + fi +fi + +# add OROCOS_INSTALL_PREFIX to CMAKE_PREFIX_PATH +if [ -d ${OROCOS_INSTALL_PREFIX} ]; then + if ! echo $CMAKE_PREFIX_PATH | grep -q "${OROCOS_INSTALL_PREFIX}"; then + if [ -z "$CMAKE_PREFIX_PATH" ]; then + CMAKE_PREFIX_PATH="${OROCOS_INSTALL_PREFIX}" + else + CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${OROCOS_INSTALL_PREFIX}" + fi + fi +fi + +# add lib/orocos to RTT_COMPONENT_PATH +# Note: The rtt env-hook also sets the RTT_COMPONENT_PATH variable. We could +# remove this redundant section. +if [ -d ${OROCOS_INSTALL_PREFIX}/lib/orocos ]; then + if ! echo $RTT_COMPONENT_PATH | grep -q "${OROCOS_INSTALL_PREFIX}/lib/orocos"; then + if [ -z "$RTT_COMPONENT_PATH" ]; then + RTT_COMPONENT_PATH="${OROCOS_INSTALL_PREFIX}/lib/orocos" + else + RTT_COMPONENT_PATH="${RTT_COMPONENT_PATH}:${OROCOS_INSTALL_PREFIX}/lib/orocos" + fi + fi +fi + +# add lib/pkgconfig to PKG_CONFIG_PATH +if [ -d ${OROCOS_INSTALL_PREFIX}/lib/pkgconfig ]; then + if ! echo $PKG_CONFIG_PATH | grep -q "${OROCOS_INSTALL_PREFIX}/lib/pkgconfig"; then + if [ -z "$PKG_CONFIG_PATH" ]; then + PKG_CONFIG_PATH="${OROCOS_INSTALL_PREFIX}/lib/pkgconfig" + else + PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${OROCOS_INSTALL_PREFIX}/lib/pkgconfig" + fi + fi +fi + +# find and source target-specific env-hooks in etc/orocos/profile.d +for hook in ${OROCOS_INSTALL_PREFIX}/etc/orocos/profile.d/*.sh; do + [ -f $hook ] && . ${hook} +done + +# export environment variables +export OROCOS_INSTALL_PREFIX +export OROCOS_TARGET +export PATH +export CMAKE_PREFIX_PATH +export RTT_COMPONENT_PATH +export PKG_CONFIG_PATH