Skip to content

Commit 4a01f75

Browse files
committed
Add/update setup scripts setup.sh and env.sh and install them in orocos_toolchain/CMakeLists.txt
The setup scripts will set the required environment variables to run Orocos RTT and other toolchain packages. The actual env-hooks have been moved into the individual packages that need it: - orocos-toolchain/rtt#160 - orocos-toolchain/ocl#43 - orocos-toolchain/utilrb@8ac984f#diff-47236f28d8c7e670852c13dcc723ed57 - orocos-toolchain/typelib@d4779e6
1 parent 6bd7314 commit 4a01f75

File tree

3 files changed

+184
-31
lines changed

3 files changed

+184
-31
lines changed

env.sh

+37-29
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
1+
#!/bin/sh
2+
#
3+
# The purpose of this script is to setup the environment for the Orocos Toolchain
4+
# (like setup.sh) and execute a command.
5+
#
6+
# Usage: env.sh COMMANDS
7+
#
8+
# This file will be installed to CMAKE_INSTALL_PREFIX by cmake with the
9+
# @-references replaced by the value of the respective cmake variable.
10+
#
111

2-
RUBY_VERSION=`ruby --version | awk '{ print $2; }' | sed -e "s/\(.*\..*\)\..*/\1/"`
3-
RUBY_ARCH=`ruby --version | sed -e 's/.*\[\(.*\)\]/\1/'`
4-
export RUBYOPT=-rubygems
5-
export TYPELIB_USE_GCCXML=1
6-
7-
8-
if [ x$ROS_ROOT != x ]; then
9-
### ROS
10-
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}
11-
export GEM_HOME=`rosstack find orocos_toolchain`/.gems
12-
export PATH=`rosstack find orocos_toolchain`/install/bin:`rospack find orogen`/bin:`rosstack find orocos_toolchain`/.gems/bin:$PATH
13-
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:`rosstack find orocos_toolchain`/install/lib/pkgconfig
12+
if [ $# -eq 0 ] ; then
13+
if [ -z "$BASH_SOURCE" -a -z "$_" ]; then
14+
/bin/echo "Usage: env.sh COMMANDS" >&2
15+
exit 1
16+
fi
17+
fi
1418

15-
elif [ x${BASH} != x ]; then
16-
### Bash non-ROS
17-
cd `dirname ${BASH_SOURCE[0]}`
18-
envpath=$PWD
19-
cd - > /dev/null
20-
export RUBYLIB=$envpath/utilrb/lib:$envpath/orogen/lib:$envpath/install/lib/ruby/${RUBY_VERSION}/${RUBY_ARCH}:$envpath/install/lib/ruby/${RUBY_VERSION}
21-
export GEM_HOME=$envpath/.gems
22-
export PATH=$envpath/install/bin:$envpath/orogen/bin:$envpath/.gems/bin:$PATH
23-
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:$envpath/install/lib/pkgconfig
19+
# find OROCOS installation folder from CMAKE_INSTALL_PREFIX or $0
20+
case "@CMAKE_INSTALL_PREFIX@" in
21+
@*) ;;
22+
*) OROCOS_INSTALL_PREFIX="@CMAKE_INSTALL_PREFIX@" ;;
23+
esac
24+
if [ -z "$OROCOS_INSTALL_PREFIX" ]; then
25+
OROCOS_INSTALL_PREFIX=`dirname $0`
26+
OROCOS_INSTALL_PREFIX=`cd ${OROCOS_INSTALL_PREFIX}; pwd`
27+
fi
2428

25-
elif [ `basename $PWD` = orocos_toolchain ]; then
26-
### non-Bash, non-ROS
27-
export RUBYLIB=$PWD/utilrb/lib:$PWD/orogen/lib:$PWD/install/lib/ruby/${RUBY_VERSION}/${RUBY_ARCH}:$PWD/install/lib/ruby/${RUBY_VERSION}
28-
export GEM_HOME=$PWD/.gems
29-
export PATH=$PWD/install/bin:$PWD/orogen/bin:$PWD/.gems/bin:$PATH
30-
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:$PWD/install/lib/pkgconfig
29+
# source setup.sh
30+
if [ -f ${OROCOS_INSTALL_PREFIX}/setup.sh ]; then
31+
. ${OROCOS_INSTALL_PREFIX}/setup.sh
32+
elif [ -f ${OROCOS_INSTALL_PREFIX}/etc/orocos/setup.sh ]; then
33+
. ${OROCOS_INSTALL_PREFIX}/etc/orocos/setup.sh
34+
elif [ -f /etc/orocos/setup.sh ]; then
35+
. /etc/orocos/setup.sh
3136
else
32-
echo "Error: This script must be sourced from the 'orocos_toolchain' directory when not running in a ROS_ROOT nor bash environment."
33-
echo
37+
echo "env.sh: could not find Orocos setup.sh script" >&2
38+
[ $# -eq 0 ] || exit 1
3439
fi
40+
41+
# execute command
42+
[ $# -eq 0 ] || exec "$@"

orocos_toolchain/CMakeLists.txt

+57-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,59 @@
11
cmake_minimum_required(VERSION 2.8.3)
22
project(orocos_toolchain)
3-
find_package(catkin REQUIRED)
4-
catkin_metapackage()
3+
4+
find_package(catkin QUIET)
5+
if(catkin_FOUND)
6+
catkin_metapackage()
7+
8+
else()
9+
install(FILES
10+
package.xml
11+
DESTINATION share/${PROJECT_NAME}/
12+
)
13+
endif()
14+
15+
# need to find Orocos RTT to set OROCOS_TARGET and other cmake variables
16+
find_package(OROCOS-RTT REQUIRED)
17+
18+
set(OROCOS_SETUP_DESTINATION "etc/orocos" CACHE STRING "Destination folder for Orocos setup files (setup.sh, env.sh), relative to CMAKE_INSTALL_PREFIX")
19+
configure_file(../setup.sh ${CMAKE_CURRENT_BINARY_DIR}/setup.sh @ONLY)
20+
configure_file(../env.sh ${CMAKE_CURRENT_BINARY_DIR}/env.sh @ONLY)
21+
22+
if(OROCOS_SETUP_DESTINATION)
23+
install(FILES
24+
"${CMAKE_CURRENT_BINARY_DIR}/setup.sh"
25+
DESTINATION "${CMAKE_INSTALL_PREFIX}/${OROCOS_SETUP_DESTINATION}"
26+
)
27+
install(PROGRAMS
28+
"${CMAKE_CURRENT_BINARY_DIR}/env.sh"
29+
DESTINATION "${CMAKE_INSTALL_PREFIX}/${OROCOS_SETUP_DESTINATION}"
30+
)
31+
endif()
32+
33+
# Install setup files directly to CMAKE_INSTALL_PREFIX if we are not
34+
# installing to a default location, but do not override setup files
35+
# installed by catkin or when building a binary package using bloom.
36+
if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
37+
AND NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr"
38+
AND NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local"
39+
AND NOT CATKIN_BUILD_BINARY_PACKAGE)
40+
install(CODE "
41+
if(NOT EXISTS \"\${CMAKE_INSTALL_PREFIX}/setup.sh\")
42+
file(INSTALL
43+
\"${CMAKE_CURRENT_BINARY_DIR}/setup.sh\"
44+
DESTINATION \"\${CMAKE_INSTALL_PREFIX}\"
45+
)
46+
else()
47+
message(STATUS \"Keeping original: \${CMAKE_INSTALL_PREFIX}/setup.sh\")
48+
endif()
49+
if(NOT EXISTS \"\${CMAKE_INSTALL_PREFIX}/env.sh\")
50+
file(INSTALL
51+
\"${CMAKE_CURRENT_BINARY_DIR}/env.sh\"
52+
DESTINATION \"\${CMAKE_INSTALL_PREFIX}\"
53+
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
54+
)
55+
else()
56+
message(STATUS \"Keeping original: \${CMAKE_INSTALL_PREFIX}/env.sh\")
57+
endif()
58+
")
59+
endif()

setup.sh

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/sh
2+
#
3+
# The purpose of this script is to setup the environment for the Orocos Toolchain.
4+
#
5+
# Usage: . @CMAKE_INSTALL_PREFIX@/@OROCOS_SETUP_DESTINATION@/setup.sh
6+
#
7+
# This file will be installed to CMAKE_INSTALL_PREFIX by cmake with the
8+
# @-references replaced by the value of the respective cmake variable.
9+
#
10+
11+
# find OROCOS installation folder from CMAKE_INSTALL_PREFIX, BASH_SOURCE or $_
12+
case "@CMAKE_INSTALL_PREFIX@" in
13+
@*) ;;
14+
*) OROCOS_INSTALL_PREFIX="@CMAKE_INSTALL_PREFIX@" ;;
15+
esac
16+
if [ -z "$OROCOS_INSTALL_PREFIX" ]; then
17+
if [ -n "$BASH_SOURCE" ]; then
18+
OROCOS_INSTALL_PREFIX=`dirname ${BASH_SOURCE[0]}`
19+
OROCOS_INSTALL_PREFIX=`cd ${OROCOS_INSTALL_PREFIX}; pwd`
20+
elif [ -n "$_" ]; then
21+
OROCOS_INSTALL_PREFIX=`dirname $_`
22+
OROCOS_INSTALL_PREFIX=`cd ${OROCOS_INSTALL_PREFIX}; pwd`
23+
else
24+
echo "Could not determine the OROCOS installation prefix for your shell." >&2
25+
exit 1
26+
fi
27+
fi
28+
29+
# initialize OROCOS_TARGET if unset
30+
if [ -z "${OROCOS_TARGET}" ]; then
31+
case "@OROCOS_TARGET@" in
32+
@*) ;;
33+
*) OROCOS_TARGET="@OROCOS_TARGET@" ;;
34+
esac
35+
fi
36+
37+
# add bin/ to PATH
38+
if [ -d ${OROCOS_INSTALL_PREFIX}/bin ]; then
39+
if ! echo $PATH | grep -q "${OROCOS_INSTALL_PREFIX}/bin"; then
40+
PATH="${PATH}:${OROCOS_INSTALL_PREFIX}/bin"
41+
fi
42+
fi
43+
44+
# add OROCOS_INSTALL_PREFIX to CMAKE_PREFIX_PATH
45+
if [ -d ${OROCOS_INSTALL_PREFIX} ]; then
46+
if ! echo $CMAKE_PREFIX_PATH | grep -q "${OROCOS_INSTALL_PREFIX}"; then
47+
if [ -z "$CMAKE_PREFIX_PATH" ]; then
48+
CMAKE_PREFIX_PATH="${OROCOS_INSTALL_PREFIX}"
49+
else
50+
CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${OROCOS_INSTALL_PREFIX}"
51+
fi
52+
fi
53+
fi
54+
55+
# add lib/orocos to RTT_COMPONENT_PATH
56+
# Note: The rtt env-hook also sets the RTT_COMPONENT_PATH variable. We could
57+
# remove this redundant section.
58+
if [ -d ${OROCOS_INSTALL_PREFIX}/lib/orocos ]; then
59+
if ! echo $RTT_COMPONENT_PATH | grep -q "${OROCOS_INSTALL_PREFIX}/lib/orocos"; then
60+
if [ -z "$RTT_COMPONENT_PATH" ]; then
61+
RTT_COMPONENT_PATH="${OROCOS_INSTALL_PREFIX}/lib/orocos"
62+
else
63+
RTT_COMPONENT_PATH="${RTT_COMPONENT_PATH}:${OROCOS_INSTALL_PREFIX}/lib/orocos"
64+
fi
65+
fi
66+
fi
67+
68+
# add lib/pkgconfig to PKG_CONFIG_PATH
69+
if [ -d ${OROCOS_INSTALL_PREFIX}/lib/pkgconfig ]; then
70+
if ! echo $PKG_CONFIG_PATH | grep -q "${OROCOS_INSTALL_PREFIX}/lib/pkgconfig"; then
71+
if [ -z "$PKG_CONFIG_PATH" ]; then
72+
PKG_CONFIG_PATH="${OROCOS_INSTALL_PREFIX}/lib/pkgconfig"
73+
else
74+
PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${OROCOS_INSTALL_PREFIX}/lib/pkgconfig"
75+
fi
76+
fi
77+
fi
78+
79+
# find and source target-specific env-hooks in etc/orocos/profile.d
80+
for hook in ${OROCOS_INSTALL_PREFIX}/etc/orocos/profile.d/*.sh; do
81+
[ -f $hook ] && . ${hook}
82+
done
83+
84+
# export environment variables
85+
export OROCOS_INSTALL_PREFIX
86+
export OROCOS_TARGET
87+
export PATH
88+
export CMAKE_PREFIX_PATH
89+
export RTT_COMPONENT_PATH
90+
export PKG_CONFIG_PATH

0 commit comments

Comments
 (0)