Skip to content

Instantly share code, notes, and snippets.

@jonbinney
Last active December 25, 2015 17:59
Show Gist options
  • Save jonbinney/7017257 to your computer and use it in GitHub Desktop.
Save jonbinney/7017257 to your computer and use it in GitHub Desktop.
BASH script for downloading ceres-solver
#!/bin/bash
# based on https://raw.github.com/ethz-asl/ceres/master/make.sh
set -e
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
INSTALL_DIR=$CURRENT_DIR/install
SRC_DIR=$CURRENT_DIR/src
# create directory for deps
mkdir -p $INSTALL_DIR
mkdir -p $SRC_DIR
CERES_URL="https://ceres-solver.googlesource.com/ceres-solver"
CERES_DIR=$SRC_DIR/ceres
CERES_TAG=468a23f2111e3fea45c900082e644a45dae743b7 #version 1.7 with fixed parameter removal bug
GLOG_URL="http://google-glog.googlecode.com/svn/trunk/ "
GLOG_DIR=$SRC_DIR/glog
GFLAGS_URL="http://gflags.googlecode.com/svn/trunk/"
GFLAGS_DIR=$SRC_DIR/gflags
PROTOBUF_URL="http://protobuf.googlecode.com/svn/trunk/"
PROTOBUF_DIR=$SRC_DIR/protobuf
###############################################################################
# GFLAGS
###############################################################################
if [ ! -d "$GFLAGS_DIR" ]; then
svn co $GFLAGS_URL $GFLAGS_DIR
echo "### building Google flags ###"
cd $GFLAGS_DIR && ./configure --with-pic --prefix=$INSTALL_DIR && make -j8 -l4 install && cd $CURRENT_DIR
fi
###############################################################################
# GLOG
###############################################################################
if [ ! -d "$GLOG_DIR" ]; then
svn co $GLOG_URL $GLOG_DIR
echo "### building Google log ###"
cd $GLOG_DIR && ./configure --with-pic --with-gflags=$CURRENT_DIR/$GFLAGS_PATH --prefix=$INSTALL_DIR && make -j8 -l8 install && cd $CURRENT_DIR #I couldn't link ceres against a non PIC version
fi
###############################################################################
# Protobuf
###############################################################################
if [ ! -d "$PROTOBUF_DIR" ]; then
svn co $PROTOBUF_URL $PROTOBUF_DIR
echo "### building Google Protocol Buffers ###"
cd $PROTOBUF_DIR && ./autogen.sh && ./configure --prefix=$INSTALL_DIR && make -j8 -l8 install && cd $CURRENT_DIR
fi
###############################################################################
# Ceres
###############################################################################
echo "### building Google ceres ###"
# clone or update the sources
if [ ! -d "$CERES_DIR" ]; then
git clone $CERES_URL $CERES_DIR
cd $CERES_DIR && git checkout $CERES_TAG && cd $CURRENT_DIR
else
cd $CERES_DIR && git fetch && cd $CURRENT_DIR
cd $CERES_DIR && git checkout $CERES_TAG && cd $CURRENT_DIR
fi
echo "### Patched ceres cmake ###"
#remove -Werror from cmake lists as clang outputs warnings for unused include paths
sed -i 's/-Werror/-Wall/g' $CERES_DIR/CMakeLists.txt
mkdir -p $CURRENT_DIR/build && cd $CURRENT_DIR/build
# so that ceres knows where to find headers and libs from glog/gflags/protobuf
export CMAKE_PREFIX_PATH=$INSTALL_DIR
rm -rf build
mkdir -p build
cd build
cmake -DCMAKE_CXX_FLAGS=-fPIC $CERES_DIR -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR && make -j8 -l4 install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment