1 #!/bin/sh 2 # 3 # Ceres Solver - A fast non-linear least squares minimizer 4 # Copyright 2012 Google Inc. All rights reserved. 5 # http://code.google.com/p/ceres-solver/ 6 # 7 # Redistribution and use in source and binary forms, with or without 8 # modification, are permitted provided that the following conditions are met: 9 # 10 # * Redistributions of source code must retain the above copyright notice, 11 # this list of conditions and the following disclaimer. 12 # * Redistributions in binary form must reproduce the above copyright notice, 13 # this list of conditions and the following disclaimer in the documentation 14 # and/or other materials provided with the distribution. 15 # * Neither the name of Google Inc. nor the names of its contributors may be 16 # used to endorse or promote products derived from this software without 17 # specific prior written permission. 18 # 19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 # POSSIBILITY OF SUCH DAMAGE. 30 # 31 # Author: keir (at] google.com 32 # settinger (at] google.com 33 # 34 # Ceres build script for Android. To build the ceres.so libraray for Android, 35 # cd into an empty directory and run the script. Usage: 36 # 37 # build_android.sh \ 38 # <path to Android NDK> \ 39 # <path to Eigen> \ 40 # <path to Ceres source> 41 # 42 # make 43 # 44 # This script exists only to make it easier to get Ceres building on Android; 45 # as one can see from the code below, it is only a matter of extracting a 46 # standalone NDK toolchain from the NDK, and getting the right arguments to 47 # CMake to get it to work. 48 # 49 # Android NDK version r5 or higher is required. Jellybean does not work out of 50 # the box, since the android-cmake toolchain is not yet updated to for it. 51 # 52 # Note: You may wish to run 'ccmake .', the CMake curses GUI, in order to tweak 53 # the build parameters that are set by default. There are a few settings to 54 # consider changing: 55 # 56 # SCHUR_SPECIALIZATIONS: 57 # 58 # Consider if enabling the schur specializations is a big enough win for the 59 # problem you are solving, since compiling the schur specializations 60 # considerably increases the binary size. Disable them by running 'ccmake .', 61 # finding the SCHUR_SPECIALIZATIONS variable, hitting enter (toggling to "off"), 62 # pressing 'c' to generate, then 'g' to generate and exit, followed by 'make'. 63 # 64 # EXECUTABLE_OUTPUT_PATH 65 # LIBRARY_OUTPUT_PATH 66 # LIBRARY_OUTPUT_PATH_ROOT: 67 # 68 # In normal CMake builds, where you do an out of source build, the source 69 # directory is untouched when building. However, by default the Android CMake 70 # toolchain selects locations under your *source* tree for the final library 71 # and binary destinations. For example, if your Ceres git tree is under 72 # ceres-solver.git/ and the build directory you are using is 73 # ceres-android-bin/, the resulting binaries will live in ceres-solver.git/ 74 # (but not the intermediate .o files!) By changing the variables 75 # EXECUTABLE_OUTPUT_PATH, LIBRARY_OUTPUT_PATH, and LIBRARY_OUTPUT_PATH_ROOT to 76 # something under e.g. ceres-android-bin/ then true out-of-ource builds work. 77 78 if [ $# -ne 3 ] ; then 79 echo "usage: build_android.sh \\" 80 echo " <path to Android NDK> \\" 81 echo " <path to Eigen> \\" 82 echo " <path to Ceres source>" 83 exit 1 84 fi 85 86 if [ -f "CMakeLists.txt" ] ; then 87 echo "ERROR: Can't run from inside the source tree." 88 echo " Make a new directory that's not under" 89 echo " the main Ceres source tree." 90 exit 1 91 fi 92 93 # For some reason, using the NDK in-place doesn't work even though the 94 # android-cmake toolchain appears to support it. 95 # 96 # TODO(keir): Figure out the issue with the stand-alone NDK and don't create 97 # the extra stand-alone toolchain. Also test with other NDK versions and add 98 # explicit checks to ensure a compatible version is used. 99 ANDROID_NDK=$1 100 MAKE_ANDROID_TOOLCHAIN=$ANDROID_NDK/build/tools/make-standalone-toolchain.sh 101 if [ ! -f $MAKE_ANDROID_TOOLCHAIN ] ; then 102 echo "ERROR: First argument doesn't appear to be the NDK root; missing:" 103 echo " $MAKE_ANDROID_TOOLCHAIN" 104 exit 1 105 fi 106 107 EIGEN_DIR=$2 108 if [ ! -f $EIGEN_DIR/eigen3.pc.in ] ; then 109 echo "ERROR: Second argument doesn't appear to be Eigen3; missing:" 110 echo " $EIGEN_DIR/eigen3.pc.in" 111 exit 1 112 fi 113 114 CERES_SOURCE_ROOT=$3 115 if [ ! -f "$CERES_SOURCE_ROOT/internal/ceres/CMakeLists.txt" ] ; then 116 echo "ERROR: Third argument doesn't appear to be the Ceres source directory." 117 exit 1 118 fi 119 echo "Using Ceres source directory: $CERES_SOURCE_ROOT" 120 121 # Make a standalone Android NDK toolchain if needed. 122 export ANDROID_STANDALONE_TOOLCHAIN="`pwd`/toolchain" 123 if [ ! -d "$ANDROID_STANDALONE_TOOLCHAIN" ] ; then 124 echo "Extracting the Android GCC standalone toolchain to:" 125 echo " $ANDROID_STANDALONE_TOOLCHAIN..." 126 $ANDROID_NDK/build/tools/make-standalone-toolchain.sh \ 127 --platform=android-8 \ 128 --install-dir=$ANDROID_STANDALONE_TOOLCHAIN 129 else 130 echo "Found NDK standalone toolchain; skipping creation." 131 fi 132 133 # Get the Android CMake NDK toolchain file if needed. 134 if [ ! -d "android-cmake" ] ; then 135 hg clone https://code.google.com/p/android-cmake/ 136 else 137 echo "Found Android-CMake toolchain; skipping download." 138 fi 139 140 ANDROID_CMAKE_TOOLCHAIN=android-cmake/toolchain/android.toolchain.cmake 141 if [ ! -f $ANDROID_CMAKE_TOOLCHAIN ] ; then 142 echo "ERROR: It seems the toolchain file is missing:" 143 echo " $ANDROID_CMAKE_TOOLCHAIN" 144 exit 1 145 fi 146 147 cmake $CERES_SOURCE_ROOT \ 148 -DCMAKE_TOOLCHAIN_FILE=$ANDROID_CMAKE_TOOLCHAIN \ 149 -DCMAKE_BUILD_TYPE=Release \ 150 -DEIGEN_INCLUDE=$EIGEN_DIR \ 151 -DBUILD_ANDROID=ON \ 152 -DSUITESPARSE=OFF \ 153 -DGFLAGS=OFF \ 154 -DCXSPARSE=OFF 155