Skip to content

Instantly share code, notes, and snippets.

@ahoarau
Last active August 9, 2021 20:53
Show Gist options
  • Save ahoarau/dd521343494d9ec3ffb25da3f61f346d to your computer and use it in GitHub Desktop.
Save ahoarau/dd521343494d9ec3ffb25da3f61f346d to your computer and use it in GitHub Desktop.
ROS Melodic on macOS Catalina
#!/bin/bash
# Software License Agreement (BSD)
#
# Author Mike Purvis <mpurvis@clearpathrobotics.com>
# Corrected by Fuzzy Logic Robotics, Inc., All rights reserved.
# Copyright (c) 2014-2016, Clearpath Robotics, Inc., All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that
# the following conditions are met:
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the
# following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
# following disclaimer in the documentation and/or other materials provided with the distribution.
# * Neither the name of Clearpath Robotics nor the names of its contributors may be used to endorse or
# promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
ROS_DISTRO=${ROS_DISTRO:-melodic}
ROS_CONFIGURATION=${ROS_CONFIGURATION:-desktop_full}
ROS_EXTRA_PACKAGES=${ROS_EXTRA_PACKAGES:-}
ROS_INSTALL_DIR=${ROS_INSTALL_DIR:-/opt/ros/${ROS_DISTRO}}
set -x
do_install()
{
set -e
# Homebrew
if ! hash brew 2>/dev/null; then
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
brew doctor
fi
brew update
# XQuartz
if ! hash xquartz 2>/dev/null; then
brew cask install xquartz
echo "Log out and in to finalize XQuartz setup."
exit 0
fi
# Check for pip packages in the system Python directory.
if [ $(ls /Library/Python/2.7/site-packages/ | wc -l) -gt 1 ]; then
echo "These instructions are about to install Python from Homebrew. However, there are already"
echo "pip packages installed against the system python, in the following path:"
echo
echo " /Library/Python/2.7/site-packages/"
echo
echo "If you have problems, please uninstall these packages:"
echo
echo " for i in \$( pip freeze ); do sudo -H pip uninstall -y \$i; done"
echo
echo "Then delete the build directory and start over again from scratch."
fi
# Check for root-owned stuff in /usr/local
if [ $(find /usr/local/* -maxdepth 3 -type d -user root | wc -l) -gt 1 ]; then
echo "Looks like you have some stuff owned by the root user in /usr/local. The installation can"
echo "continue, but if there are pip packages which were installed using sudo, this will be a"
echo "problem if rosdep tries to update them. If you have issues installing dependencies, consider"
echo "nuking your Homebrew installation and starting from scratch:"
echo
echo " https://gist.github.com/mxcl/1173223"
echo
echo "Alternatively, you could try chowning the contents of /usr/local to yourself:"
echo
echo " sudo chown -R $USER:admin /usr/local/*"
fi
# Brewed Python
if [ ! "$(which python2)" = "/usr/local/bin/python2" ]; then
brew install python@2
mkdir -p ~/Library/Python/2.7/lib/python/site-packages
echo "$(brew --prefix)/lib/python2.7/site-packages" >> ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth
fi
# This tap gives us formulae for Gazebo and its dependencies, including SDF.
brew tap osrf/simulation
# ROS infrastructure tools
brew install libyaml || true
pip install -U setuptools rosdep rosinstall_generator wstool rosinstall catkin_tools bloom empy sphinx pycurl osrf_pycommon termcolor
# Rosdep has an issue detecting that qt5 is correctly installed, so preinstall it. This is a keg-only formula,
# so add its location to the prefix path in order for workspace packages to be able to find it.
brew install qt5 pyqt5 sip || true
export CMAKE_PREFIX_PATH=$(brew --prefix qt5)
# This hack is required to make qt_gui_cpp compile correctly. See https://github.com/mikepurvis/ros-install-osx/pull/84#issuecomment-338209466
export PATH="/usr/local/opt/qt5/bin:$PATH"
pushd /usr/local/share/sip
if [ ! -e PyQt5 ]; then
ln -fvs Qt5 PyQt5
fi
popd
# get openssl and gpgme working for rosbag_storage
brew install openssl
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/opt/openssl/lib/pkgconfig"
# Mock out python and pip so that we get the brewed versions when rosdep and other programs call them.
# Mock out pip so that we get the brewed pip2 when rosdep calls it to make an installation.
export PATH=$(pwd)/shim:$PATH
# Initialize and update rosdep
if [ ! -d /etc/ros/rosdep/ ]; then
echo "This sudo prompt is to initialize rosdep (creates the /etc/ros/rosdep path)."
sudo rosdep init
fi
if [ ! -f /etc/ros/rosdep/sources.list.d/10-ros-install-osx.list ]; then
echo "This sudo prompt adds the the brewed python rosdep yaml to /etc/ros/rosdep/sources.list.d/10-ros-install-osx.list"
sudo sh -c "echo 'yaml file://$(pwd)/rosdeps.yaml osx' > /etc/ros/rosdep/sources.list.d/10-ros-install-osx.list"
fi
rosdep update
# Remove previous workspace if present, create and enter new one.
WS=${ROS_DISTRO}_${ROS_CONFIGURATION}_ws
#if [ -d "$WS" ]; then
#rm -rf "$WS"
#fi
mkdir -p $WS/src
cd $WS
# Standard source install
rosinstall_generator ${ROS_CONFIGURATION} ${ROS_EXTRA_PACKAGES} --rosdistro ${ROS_DISTRO} --deps --tar > ${WS}.rosinstall
rm -f src/.rosinstall
wstool init src
pushd src
# Avoid downloading opencv3; we already installed it from homebrew.
wstool merge -k ../${WS}.rosinstall -y
# swap out rospy for kinetic version 1.12.6. This fixes "RuntimeError:
# concurrent poll() invocation" errors.
wstool merge -k ../../patches/rospy_patch.rosinstall -y
wstool update -j8
# conflicts with normal numpy
if [ -d /usr/local/bin/f2py ]; then
rm '/usr/local/bin/f2py'
fi
if brew ls --versions numpy > /dev/null; then
brew link numpy
fi
# make sure rosdep doesn't stop on opencv
if brew ls --versions opencv@3 > /dev/null; then
brew unlink opencv@3
brew install opencv
brew link opencv
fi
# Package dependencies.
rosdep install --from-paths . --ignore-src --rosdistro ${ROS_DISTRO} -y -r --as-root pip:no
popd
# install specific versions of certain brew packages
# boost 1.69.0
brew unlink boost-python
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/16274ef9d6acdb629139b331a0c37d0964e61a14/Formula/boost-python.rb
brew link boost-python
brew unlink boost
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/16274ef9d6acdb629139b331a0c37d0964e61a14/Formula/boost.rb
brew link boost
# sip 4.19.8_12 - still supports python2
brew unlink sip
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/6d2b011fa8f28ef5a0b52f24eb687276823a22fa/Formula/sip.rb
brew link sip
# pyqt 5.10.1_1 - still supports python2
brew unlink pyqt
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/1f389d65e21ad067be6811900f5361301b44839f/Formula/pyqt.rb
brew link pyqt
# install gazebo9 from source. Fixes a lot of problems with protobuf compatibility
if [ -z "$(brew info gazebo9 | grep 'Built from source')" ]; then
echo "Gazebo not built from source, reinstalling it from source"
brew reinstall -s gazebo9
fi
# Get homebrew's opencv3 from a bottle so that we don't have to build it.
brew unlink opencv
brew install opencv@3
brew link opencv@3 --force
# old version of numpy
brew unlink numpy
brew install numpy@1.16
brew link numpy@1.16 --force
# patches
# fix roscpp trying to link against unused? boost component
patch -N -d src/ros_comm/roscpp/ < ../patches/roscpp.diff || true
patch -N -d src/ros_comm/message_filters/ < ../patches/message_filters.diff || true
patch -N -d src/ros_comm/message_filters/ < ../patches/message_filters.diff || true
# fix tf and tf2 trying to link against unused? boost component
patch -N -d src/geometry/tf/ < ../patches/tf.diff || true
patch -N -d src/geometry2/tf2/ < ../patches/tf2.diff || true
# rosbag_strorage encryption
patch -N -d src/ros_comm/rosbag_storage/ < ../patches/rosbag_storage.diff || true
if [ ! -d /usr/local/include/openssl ]; then
ln -s /usr/local/opt/openssl/include/* /usr/local/include/
fi
# fix boost components in camera_calibration_parsers
patch -N -d src/image_common/camera_calibration_parsers/ < ../patches/camera_calibration_parsers.diff || true
# fix boost components in camera_calibration_parsers
patch -N -d src/vision_opencv/cv_bridge/ < ../patches/cv_bridge.diff || true
# add pango to image_view
patch -N -d src/image_pipeline/image_view/ < ../patches/image_view.diff || true
# fix find flann library in pcl so pcl_ros can build
# (https://stackoverflow.com/questions/53776238/building-point-cloud-library-pcl-on-macos-x-mojave-error-ld-library-not-foun)
patch -N -d /usr/local/share/pcl-1.9/Modules/ < ../patches/FindFLANN.diff || true
# patch rviz for yaml-cpp linker issue
patch -N -d src/rviz/ https://patch-diff.githubusercontent.com/raw/ros-visualization/rviz/pull/1445.diff || true
# Clean out or create the install directory.
if [ -d ${ROS_INSTALL_DIR} ]; then
rm -rf ${ROS_INSTALL_DIR}/*
else
echo "This sudo prompt is to create and chown ${ROS_INSTALL_DIR}."
sudo mkdir -p ${ROS_INSTALL_DIR}
sudo chown $USER ${ROS_INSTALL_DIR}
sudo chown $USER ${ROS_INSTALL_DIR}/../
fi
# fix assimp missing link
ln -sf /usr/local/lib/libassimp.5.dylib /usr/local/lib/libassimp.dylib.5
# Force link on pyqt
brew unlink pyqt
brew link pyqt
# Parallel build.
catkin config --install \
--install-space ${ROS_INSTALL_DIR} \
--cmake-args \
-DCMAKE_CXX_STANDARD=14 \
-DCATKIN_ENABLE_TESTING=0 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_FIND_FRAMEWORK=LAST \
-DPYTHON_EXECUTABLE=$(which python2) \
-DPYTHON_LIBRARY=$(python2 -c "import sys; print sys.prefix")/lib/libpython2.7.dylib \
-DPYTHON_INCLUDE_DIR=$(python2 -c "import sys; print sys.prefix")/include/python2.7
catkin build
echo "Installation successful, please source the ROS workspace:"
echo
echo " source ${ROS_INSTALL_DIR}/setup.bash"
echo
# Check for SIP if on OSX/macOS 10.11 (El Capitan) or later
if [[ `sw_vers -productVersion` > "10.10" ]]
then
if `csrutil status | grep -q enabled`
then
echo "You have System Integrity Protection enabled."
echo
echo "This prevents DYLD_LIBRARY_PATH from being exported to subshells"
echo "Please add: export DYLD_LIBRARY_PATH=\$DYLD_LIBRARY_PATH:/opt/ros/\$ROS_DISTRO/lib"
echo "To the start of /opt/ros/$ROS_DISTRO/bin/rosrun to work around the issue."
fi
fi
}
do_install
@pmoscode
Copy link

pmoscode commented Jun 1, 2020

Sadly no. I also never tried it again. Used Ubuntu on different laptop instead...

@nishantmi
Copy link

Hi! Has anyone got this working?

@jorgemiar
Copy link

Anyone managed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment