Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 1 | .. _chapter-building: |
| 2 | |
Sameer Agarwal | 3a2158d | 2013-10-03 07:12:14 -0700 | [diff] [blame] | 3 | ============ |
| 4 | Installation |
| 5 | ============ |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 6 | |
Sameer Agarwal | 97e1795 | 2013-05-26 11:48:09 -0700 | [diff] [blame] | 7 | Stable Ceres Solver releases are available for download at |
| 8 | `code.google.com <http://code.google.com/p/ceres-solver/>`_. For the |
| 9 | more adventurous, the git repository is hosted on `Gerrit |
| 10 | <https://ceres-solver-review.googlesource.com/>`_. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 11 | |
| 12 | .. _section-dependencies: |
| 13 | |
| 14 | Dependencies |
| 15 | ============ |
| 16 | |
| 17 | Ceres relies on a number of open source libraries, some of which are |
| 18 | optional. For details on customizing the build process, see |
| 19 | :ref:`section-customizing` . |
| 20 | |
| 21 | 1. `CMake <http://www.cmake.org>`_ is a cross platform build |
| 22 | system. Ceres needs a relatively recent version of CMake (version |
| 23 | 2.8.0 or better). |
| 24 | |
| 25 | 2. `eigen3 <http://eigen.tuxfamily.org/index.php?title=Main_Page>`_ is |
| 26 | used for doing all the low level matrix and linear algebra operations. |
| 27 | |
Pablo Speciale | ac0d416 | 2013-03-20 18:32:14 -0700 | [diff] [blame] | 28 | 3. `google-glog <http://code.google.com/p/google-glog>`_ is |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 29 | used for error checking and logging. Ceres needs glog version 0.3.1 or |
| 30 | later. Version 0.3 (which ships with Fedora 16) has a namespace bug |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 31 | which prevents Ceres from building. Ceres contains a stripped-down, |
| 32 | minimal version of ``glog`` called ``miniglog``, which can be enabled |
| 33 | with the ``MINIGLOG`` build option. If enabled, it replaces the |
| 34 | requirement for ``glog``. However, in general it is recommended that |
| 35 | you use the full ``glog``. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 36 | |
| 37 | 4. `gflags <http://code.google.com/p/gflags>`_ is a library for |
| 38 | processing command line flags. It is used by some of the examples and |
| 39 | tests. While it is not strictly necessary to build the library, we |
| 40 | strongly recommend building the library with gflags. |
| 41 | |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 42 | 5. `SuiteSparse |
| 43 | <http://www.cise.ufl.edu/research/sparse/SuiteSparse/>`_ is used for |
| 44 | sparse matrix analysis, ordering and factorization. In particular |
Sameer Agarwal | 97e1795 | 2013-05-26 11:48:09 -0700 | [diff] [blame] | 45 | Ceres uses the AMD, CAMD, COLAMD and CHOLMOD libraries. This is an optional |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 46 | dependency. |
| 47 | |
| 48 | 6. `CXSparse <http://www.cise.ufl.edu/research/sparse/CXSparse/>`_ is |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 49 | a sparse matrix library similar in scope to ``SuiteSparse`` but with |
| 50 | no dependencies on ``LAPACK`` and ``BLAS``. This makes for a simpler |
| 51 | build process and a smaller binary. The simplicity comes at a cost -- |
| 52 | for all but the most trivial matrices, ``SuiteSparse`` is |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 53 | significantly faster than ``CXSparse``. This is an optional dependency. |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 54 | |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 55 | 7. `BLAS <http://www.netlib.org/blas/>`_ and `LAPACK |
| 56 | <http://www.netlib.org/lapack/>`_ routines are needed by |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 57 | SuiteSparse, and optionally used by Ceres directly for some operations. |
| 58 | We recommend `ATLAS <http://math-atlas.sourceforge.net/>`_, |
| 59 | which includes BLAS and LAPACK routines. It is also possible to use |
| 60 | `OpenBLAS <https://github.com/xianyi/OpenBLAS>`_ . However, one needs |
| 61 | to be careful to `turn off the threading |
Sameer Agarwal | 0a07fbf | 2013-07-10 11:57:35 -0700 | [diff] [blame] | 62 | <https://github.com/xianyi/OpenBLAS/wiki/faq#wiki-multi-threaded>`_ |
| 63 | inside ``OpenBLAS`` as it conflicts with use of threads in Ceres. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 64 | |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 65 | .. _section-linux: |
| 66 | |
| 67 | Building on Linux |
| 68 | ================= |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 69 | We will use `Ubuntu <http://www.ubuntu.com>`_ as our example |
| 70 | platform. Start by installing all the dependencies. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 71 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 72 | .. NOTE:: |
Sameer Agarwal | c7ebfb8 | 2013-10-09 22:13:01 -0700 | [diff] [blame] | 73 | |
| 74 | Up to at least Ubuntu 13.10, the SuiteSparse package in the official |
| 75 | package repository (built from SuiteSparse v3.4.0) **cannot** be used |
| 76 | to build Ceres as a *shared* library. Thus if you want to build |
| 77 | Ceres as a shared library using SuiteSparse, you must perform a |
| 78 | source install of SuiteSparse. It is recommended that you use the |
| 79 | current version of SuiteSparse (4.2.1 at the time of writing). |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 80 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 81 | .. code-block:: bash |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 82 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 83 | # CMake |
Sameer Agarwal | 8f7e896 | 2013-06-03 13:07:39 -0700 | [diff] [blame] | 84 | sudo apt-get install cmake |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 85 | # gflags |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 86 | tar -xvzf gflags-2.0.tar.gz |
| 87 | cd gflags-2.0 |
| 88 | ./configure --prefix=/usr/local |
| 89 | make |
| 90 | sudo make install. |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 91 | # google-glog must be configured to use the previously installed gflags |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 92 | tar -xvzf glog-0.3.2.tar.gz |
| 93 | cd glog-0.3.2 |
| 94 | ./configure --with-gflags=/usr/local/ |
| 95 | make |
| 96 | sudo make install |
Sameer Agarwal | 5d7c195 | 2013-05-07 12:47:51 -0700 | [diff] [blame] | 97 | # BLAS & LAPACK |
Sameer Agarwal | 0a07fbf | 2013-07-10 11:57:35 -0700 | [diff] [blame] | 98 | sudo apt-get install libatlas-base-dev |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 99 | # Eigen3 |
| 100 | sudo apt-get install libeigen3-dev |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 101 | # SuiteSparse and CXSparse (optional) |
| 102 | # - If you want to build Ceres as a *static* library (the default) |
| 103 | # you can use the SuiteSparse package in the main Ubuntu package |
| 104 | # repository: |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 105 | sudo apt-get install libsuitesparse-dev |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 106 | # - However, if you want to build Ceres as a *shared* library, you must |
| 107 | # perform a source install of SuiteSparse (and uninstall the Ubuntu |
| 108 | # package if it is currently installed. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 109 | |
Sameer Agarwal | 97e1795 | 2013-05-26 11:48:09 -0700 | [diff] [blame] | 110 | We are now ready to build and test Ceres. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 111 | |
| 112 | .. code-block:: bash |
| 113 | |
Sameer Agarwal | 1a041c3 | 2013-11-12 14:17:52 -0800 | [diff] [blame] | 114 | tar zxf ceres-solver-1.8.0.tar.gz |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 115 | mkdir ceres-bin |
| 116 | cd ceres-bin |
Sameer Agarwal | 1a041c3 | 2013-11-12 14:17:52 -0800 | [diff] [blame] | 117 | cmake ../ceres-solver-1.8.0 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 118 | make -j3 |
| 119 | make test |
| 120 | |
| 121 | You can also try running the command line bundling application with one of the |
| 122 | included problems, which comes from the University of Washington's BAL |
| 123 | dataset [Agarwal]_. |
| 124 | |
| 125 | .. code-block:: bash |
| 126 | |
Sameer Agarwal | 1a041c3 | 2013-11-12 14:17:52 -0800 | [diff] [blame] | 127 | bin/simple_bundle_adjuster ../ceres-solver-1.8.0/data/problem-16-22106-pre.txt |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 128 | |
| 129 | This runs Ceres for a maximum of 10 iterations using the |
| 130 | ``DENSE_SCHUR`` linear solver. The output should look something like |
| 131 | this. |
| 132 | |
| 133 | .. code-block:: bash |
| 134 | |
Richard Bowen | b555b48 | 2014-03-27 15:51:28 -0700 | [diff] [blame^] | 135 | 0: f: 4.185660e+06 d: 0.00e+00 g: 1.09e+08 h: 0.00e+00 rho: 0.00e+00 mu: 1.00e+04 li: 0 it: 8.73e-02 tt: 2.61e-01 |
| 136 | 1: f: 1.062590e+05 d: 4.08e+06 g: 8.99e+06 h: 5.36e+02 rho: 9.82e-01 mu: 3.00e+04 li: 1 it: 1.85e-01 tt: 4.46e-01 |
| 137 | 2: f: 4.992817e+04 d: 5.63e+04 g: 8.32e+06 h: 3.19e+02 rho: 6.52e-01 mu: 3.09e+04 li: 1 it: 1.74e-01 tt: 6.20e-01 |
| 138 | 3: f: 1.899774e+04 d: 3.09e+04 g: 1.60e+06 h: 1.24e+02 rho: 9.77e-01 mu: 9.26e+04 li: 1 it: 1.74e-01 tt: 7.94e-01 |
| 139 | 4: f: 1.808729e+04 d: 9.10e+02 g: 3.97e+05 h: 6.39e+01 rho: 9.51e-01 mu: 2.78e+05 li: 1 it: 1.73e-01 tt: 9.67e-01 |
| 140 | 5: f: 1.803399e+04 d: 5.33e+01 g: 1.48e+04 h: 1.23e+01 rho: 9.99e-01 mu: 8.33e+05 li: 1 it: 1.75e-01 tt: 1.14e+00 |
| 141 | 6: f: 1.803390e+04 d: 9.02e-02 g: 6.35e+01 h: 8.00e-01 rho: 1.00e+00 mu: 2.50e+06 li: 1 it: 1.75e-01 tt: 1.32e+00 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 142 | |
Richard Bowen | b555b48 | 2014-03-27 15:51:28 -0700 | [diff] [blame^] | 143 | Ceres Solver Report |
| 144 | ------------------- |
| 145 | Original Reduced |
| 146 | Parameter blocks 22122 22122 |
| 147 | Parameters 66462 66462 |
| 148 | Residual blocks 83718 83718 |
| 149 | Residual 167436 167436 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 150 | |
Richard Bowen | b555b48 | 2014-03-27 15:51:28 -0700 | [diff] [blame^] | 151 | Minimizer TRUST_REGION |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 152 | |
Richard Bowen | b555b48 | 2014-03-27 15:51:28 -0700 | [diff] [blame^] | 153 | Dense linear algebra library EIGEN |
| 154 | Trust region strategy LEVENBERG_MARQUARDT |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 155 | |
Richard Bowen | b555b48 | 2014-03-27 15:51:28 -0700 | [diff] [blame^] | 156 | Given Used |
| 157 | Linear solver DENSE_SCHUR DENSE_SCHUR |
| 158 | Threads 1 1 |
| 159 | Linear solver threads 1 1 |
| 160 | Linear solver ordering AUTOMATIC 22106, 16 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 161 | |
Richard Bowen | b555b48 | 2014-03-27 15:51:28 -0700 | [diff] [blame^] | 162 | Cost: |
| 163 | Initial 4.185660e+06 |
| 164 | Final 1.803390e+04 |
| 165 | Change 4.167626e+06 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 166 | |
Richard Bowen | b555b48 | 2014-03-27 15:51:28 -0700 | [diff] [blame^] | 167 | Minimizer iterations 6 |
| 168 | Successful steps 6 |
| 169 | Unsuccessful steps 0 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 170 | |
Richard Bowen | b555b48 | 2014-03-27 15:51:28 -0700 | [diff] [blame^] | 171 | Time (in seconds): |
| 172 | Preprocessor 0.173 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 173 | |
Richard Bowen | b555b48 | 2014-03-27 15:51:28 -0700 | [diff] [blame^] | 174 | Residual evaluation 0.115 |
| 175 | Jacobian evaluation 0.498 |
| 176 | Linear solver 0.517 |
| 177 | Minimizer 1.242 |
| 178 | |
| 179 | Postprocessor 0.003 |
| 180 | Total 1.437 |
| 181 | |
| 182 | Termination: CONVERGENCE (Function tolerance reached. |cost_change|/cost: 1.769750e-09 <= 1.000000e-06) |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 183 | |
| 184 | .. section-osx: |
| 185 | |
| 186 | Building on Mac OS X |
| 187 | ==================== |
| 188 | |
| 189 | On OS X, we recommend using the `homebrew |
Sameer Agarwal | 97e1795 | 2013-05-26 11:48:09 -0700 | [diff] [blame] | 190 | <http://mxcl.github.com/homebrew/>`_ package manager to install the |
| 191 | dependencies. There is no need to install ``BLAS`` or ``LAPACK`` |
| 192 | separately as OS X ships with optimized ``BLAS`` and ``LAPACK`` |
| 193 | routines as part of the `vecLib |
Sameer Agarwal | 5d7c195 | 2013-05-07 12:47:51 -0700 | [diff] [blame] | 194 | <https://developer.apple.com/library/mac/#documentation/Performance/Conceptual/vecLib/Reference/reference.html>`_ |
| 195 | framework. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 196 | |
Alex Stewart | f5f21b5 | 2013-10-10 19:22:31 +0100 | [diff] [blame] | 197 | .. NOTE:: |
| 198 | |
| 199 | Ceres will not compile using Xcode 4.5.x (Clang version 4.1) due to a bug in that version of |
| 200 | Clang. If you are running Xcode 4.5.x, please update to Xcode >= 4.6.x before attempting to |
| 201 | build Ceres. |
| 202 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 203 | .. code-block:: bash |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 204 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 205 | # CMake |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 206 | brew install cmake |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 207 | # google-glog and gflags |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 208 | brew install glog |
Sameer Agarwal | 5d7c195 | 2013-05-07 12:47:51 -0700 | [diff] [blame] | 209 | # Eigen3 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 210 | brew install eigen |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 211 | # SuiteSparse and CXSparse |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 212 | brew install suite-sparse |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 213 | |
| 214 | |
| 215 | We are now ready to build and test Ceres. |
| 216 | |
| 217 | .. code-block:: bash |
| 218 | |
Sameer Agarwal | 1a041c3 | 2013-11-12 14:17:52 -0800 | [diff] [blame] | 219 | tar zxf ceres-solver-1.8.0.tar.gz |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 220 | mkdir ceres-bin |
| 221 | cd ceres-bin |
Sameer Agarwal | 1a041c3 | 2013-11-12 14:17:52 -0800 | [diff] [blame] | 222 | cmake ../ceres-solver-1.8.0 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 223 | make -j3 |
| 224 | make test |
| 225 | |
| 226 | |
| 227 | Like the Linux build, you should now be able to run |
| 228 | ``bin/simple_bundle_adjuster``. |
| 229 | |
| 230 | .. _section-windows: |
| 231 | |
| 232 | Building on Windows with Visual Studio |
| 233 | ====================================== |
| 234 | |
| 235 | On Windows, we support building with Visual Studio 2010 or newer. Note |
| 236 | that the Windows port is less featureful and less tested than the |
Sameer Agarwal | ebbb984 | 2013-05-26 12:40:12 -0700 | [diff] [blame] | 237 | Linux or Mac OS X versions due to the unavailability of SuiteSparse |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 238 | and ``CXSparse``. Building is also more involved since there is no |
| 239 | automated way to install the dependencies. |
| 240 | |
| 241 | #. Make a toplevel directory for deps & build & src somewhere: ``ceres/`` |
| 242 | #. Get dependencies; unpack them as subdirectories in ``ceres/`` |
| 243 | (``ceres/eigen``, ``ceres/glog``, etc) |
| 244 | |
| 245 | #. ``Eigen`` 3.1 (needed on Windows; 3.0.x will not work). There is |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 246 | no need to build anything; just unpack the source tarball. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 247 | |
| 248 | #. ``google-glog`` Open up the Visual Studio solution and build it. |
| 249 | #. ``gflags`` Open up the Visual Studio solution and build it. |
| 250 | |
| 251 | #. Unpack the Ceres tarball into ``ceres``. For the tarball, you |
| 252 | should get a directory inside ``ceres`` similar to |
| 253 | ``ceres-solver-1.3.0``. Alternately, checkout Ceres via ``git`` to |
| 254 | get ``ceres-solver.git`` inside ``ceres``. |
| 255 | |
| 256 | #. Install ``CMake``, |
| 257 | |
| 258 | #. Make a dir ``ceres/ceres-bin`` (for an out-of-tree build) |
| 259 | |
| 260 | #. Run ``CMake``; select the ``ceres-solver-X.Y.Z`` or |
| 261 | ``ceres-solver.git`` directory for the CMake file. Then select the |
| 262 | ``ceres-bin`` for the build dir. |
| 263 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 264 | #. Try running ``Configure``. It won't work. It'll show a bunch of options. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 265 | You'll need to set: |
| 266 | |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 267 | #. ``EIGEN_INCLUDE_DIR`` |
| 268 | #. ``GLOG_INCLUDE_DIR`` |
| 269 | #. ``GLOG_LIBRARY`` |
| 270 | #. ``GFLAGS_INCLUDE_DIR`` |
| 271 | #. ``GFLAGS_LIBRARY`` |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 272 | |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 273 | to the appropriate place where you unpacked/built them. If any of the |
| 274 | variables are not visible in the ``CMake`` GUI, toggle to the |
| 275 | *Advanced View* with ``<t>``. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 276 | |
| 277 | #. You may have to tweak some more settings to generate a MSVC |
| 278 | project. After each adjustment, try pressing Configure & Generate |
| 279 | until it generates successfully. |
| 280 | |
| 281 | #. Open the solution and build it in MSVC |
| 282 | |
| 283 | |
| 284 | To run the tests, select the ``RUN_TESTS`` target and hit **Build |
| 285 | RUN_TESTS** from the build menu. |
| 286 | |
Sameer Agarwal | 8ba41e8 | 2013-10-09 11:35:40 -0700 | [diff] [blame] | 287 | Like the Linux build, you should now be able to run |
| 288 | ``bin/simple_bundle_adjuster``. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 289 | |
| 290 | Notes: |
| 291 | |
| 292 | #. The default build is Debug; consider switching it to release mode. |
| 293 | #. Currently ``system_test`` is not working properly. |
| 294 | #. Building Ceres as a DLL is not supported; patches welcome. |
| 295 | #. CMake puts the resulting test binaries in ``ceres-bin/examples/Debug`` |
| 296 | by default. |
| 297 | #. The solvers supported on Windows are ``DENSE_QR``, ``DENSE_SCHUR``, |
| 298 | ``CGNR``, and ``ITERATIVE_SCHUR``. |
| 299 | #. We're looking for someone to work with upstream ``SuiteSparse`` to |
| 300 | port their build system to something sane like ``CMake``, and get a |
| 301 | supported Windows port. |
| 302 | |
| 303 | |
| 304 | .. _section-android: |
| 305 | |
| 306 | Building on Android |
| 307 | =================== |
| 308 | |
| 309 | |
| 310 | Download the ``Android NDK``. Run ``ndk-build`` from inside the |
| 311 | ``jni`` directory. Use the ``libceres.a`` that gets created. |
| 312 | |
| 313 | .. _section-customizing: |
| 314 | |
| 315 | Customizing the build |
| 316 | ===================== |
| 317 | |
| 318 | It is possible to reduce the libraries needed to build Ceres and |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 319 | customize the build process by setting the appropriate options in |
| 320 | ``CMake``. These options can either be set in the ``CMake`` GUI, |
| 321 | or via ``-D<OPTION>=<ON/OFF>`` when running ``CMake`` from the |
| 322 | command line. In general, you should only modify these options from |
| 323 | their defaults if you know what you are doing. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 324 | |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 325 | .. NOTE:: |
| 326 | |
| 327 | If you are setting variables via ``-D<VARIABLE>=<VALUE>`` when calling |
| 328 | ``CMake``, it is important to understand that this forcibly **overwrites** the |
| 329 | variable ``<VARIABLE>`` in the ``CMake`` cache at the start of *every configure*. |
| 330 | |
| 331 | This can lead to confusion if you are invoking the ``CMake`` |
| 332 | `curses <http://www.gnu.org/software/ncurses/ncurses.html>`_ terminal GUI |
| 333 | (via ``ccmake``, e.g. ```ccmake -D<VARIABLE>=<VALUE> <PATH_TO_SRC>``). |
| 334 | In this case, even if you change the value of ``<VARIABLE>`` in the ``CMake`` |
| 335 | GUI, your changes will be **overwritten** with the value passed via |
| 336 | ``-D<VARIABLE>=<VALUE>`` (if one exists) at the start of each configure. |
| 337 | |
| 338 | As such, it is generally easier not to pass values to ``CMake`` via ``-D`` |
| 339 | and instead interactively experiment with their values in the ``CMake`` GUI. |
| 340 | If they are not present in the *Standard View*, toggle to the *Advanced View* |
| 341 | with ``<t>``. |
| 342 | |
| 343 | Options controlling Ceres configuration |
Sameer Agarwal | 7f336af | 2013-10-17 23:38:57 -0700 | [diff] [blame] | 344 | --------------------------------------- |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 345 | |
Sameer Agarwal | 8ba41e8 | 2013-10-09 11:35:40 -0700 | [diff] [blame] | 346 | #. ``LAPACK [Default: ON]``: By default Ceres will use ``LAPACK`` (& |
| 347 | ``BLAS``) if they are found. Turn this ``OFF`` to build Ceres |
| 348 | without ``LAPACK``. Turning this ``OFF`` also disables |
| 349 | ``SUITESPARSE`` as it depends on ``LAPACK``. |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 350 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 351 | #. ``SUITESPARSE [Default: ON]``: By default, Ceres will link to |
Sameer Agarwal | 8ba41e8 | 2013-10-09 11:35:40 -0700 | [diff] [blame] | 352 | ``SuiteSparse`` if it and all of its dependencies are present. Turn |
| 353 | this ``OFF`` to build Ceres without ``SuiteSparse``. Note that |
| 354 | ``LAPACK`` must be ``ON`` in order to build with ``SuiteSparse``. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 355 | |
Sameer Agarwal | 8ba41e8 | 2013-10-09 11:35:40 -0700 | [diff] [blame] | 356 | #. ``CXSPARSE [Default: ON]``: By default, Ceres will link to |
| 357 | ``CXSparse`` if all its dependencies are present. Turn this ``OFF`` |
| 358 | to build Ceres without ``CXSparse``. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 359 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 360 | #. ``GFLAGS [Default: ON]``: Turn this ``OFF`` to build Ceres without |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 361 | ``gflags``. This will also prevent some of the example code from |
| 362 | building. |
| 363 | |
Sameer Agarwal | 8ba41e8 | 2013-10-09 11:35:40 -0700 | [diff] [blame] | 364 | #. ``MINIGLOG [Default: OFF]``: Ceres includes a stripped-down, |
| 365 | minimal implementation of ``glog`` which can optionally be used as |
| 366 | a substitute for ``glog``, thus removing ``glog`` as a required |
| 367 | dependency. Turn this ``ON`` to use this minimal ``glog`` |
| 368 | implementation. |
Alex Stewart | fc8ede2 | 2013-10-08 19:49:42 +0100 | [diff] [blame] | 369 | |
Sameer Agarwal | 8ba41e8 | 2013-10-09 11:35:40 -0700 | [diff] [blame] | 370 | #. ``SCHUR_SPECIALIZATIONS [Default: ON]``: If you are concerned about |
| 371 | binary size/compilation time over some small (10-20%) performance |
| 372 | gains in the ``SPARSE_SCHUR`` solver, you can disable some of the |
| 373 | template specializations by turning this ``OFF``. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 374 | |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 375 | #. ``OPENMP [Default: ON]``: On certain platforms like Android, |
Sameer Agarwal | 8ba41e8 | 2013-10-09 11:35:40 -0700 | [diff] [blame] | 376 | multi-threading with ``OpenMP`` is not supported. Turn this ``OFF`` |
| 377 | to disable multithreading. |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 378 | |
Sameer Agarwal | 8ba41e8 | 2013-10-09 11:35:40 -0700 | [diff] [blame] | 379 | #. ``BUILD_SHARED_LIBS [Default: OFF]``: By default Ceres is built as |
| 380 | a static library, turn this ``ON`` to instead build Ceres as a |
| 381 | shared library. |
Alex Stewart | 0b07d3e | 2013-10-04 16:17:06 +0100 | [diff] [blame] | 382 | |
Sameer Agarwal | 8ba41e8 | 2013-10-09 11:35:40 -0700 | [diff] [blame] | 383 | #. ``BUILD_DOCUMENTATION [Default: OFF]``: Use this to enable building |
| 384 | the documentation, requires `Sphinx <http://sphinx-doc.org/>`_. In |
| 385 | addition, ``make ceres_docs`` can be used to build only the |
| 386 | documentation. |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 387 | |
Alex Stewart | f51f563 | 2013-10-22 14:35:02 +0100 | [diff] [blame] | 388 | #. ``MSVC_USE_STATIC_CRT [Default: OFF]`` *Windows Only*: By default |
| 389 | Ceres will use the Visual Studio default, *shared* C-Run Time (CRT) library. |
| 390 | Turn this ``ON`` to use the *static* C-Run Time library instead. |
| 391 | |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 392 | |
| 393 | Options controlling Ceres dependency locations |
Sameer Agarwal | 7f336af | 2013-10-17 23:38:57 -0700 | [diff] [blame] | 394 | ---------------------------------------------- |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 395 | |
Sameer Agarwal | 7f336af | 2013-10-17 23:38:57 -0700 | [diff] [blame] | 396 | Ceres uses the ``CMake`` |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 397 | `find_package <http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:find_package>`_ |
| 398 | function to find all of its dependencies using |
| 399 | ``Find<DEPENDENCY_NAME>.cmake`` scripts which are either included in Ceres |
| 400 | (for most dependencies) or are shipped as standard with ``CMake`` |
| 401 | (for ``LAPACK`` & ``BLAS``). These scripts will search all of the "standard" |
| 402 | install locations for various OSs for each dependency. However, particularly |
| 403 | for Windows, they may fail to find the library, in this case you will have to |
| 404 | manually specify its installed location. The ``Find<DEPENDENCY_NAME>.cmake`` |
| 405 | scripts shipped with Ceres support two ways for you to do this: |
| 406 | |
| 407 | #. Set the *hints* variables specifying the *directories* to search in |
| 408 | preference, but in addition, to the search directories in the |
| 409 | ``Find<DEPENDENCY_NAME>.cmake`` script: |
| 410 | |
| 411 | - ``<DEPENDENCY_NAME (CAPS)>_INCLUDE_DIR_HINTS`` |
| 412 | - ``<DEPENDENCY_NAME (CAPS)>_LIBRARY_DIR_HINTS`` |
| 413 | |
| 414 | These variables should be set via ``-D<VAR>=<VALUE>`` |
| 415 | ``CMake`` arguments as they are not visible in the GUI. |
| 416 | |
| 417 | #. Set the variables specifying the *explicit* include directory |
| 418 | and library file to use: |
| 419 | |
| 420 | - ``<DEPENDENCY_NAME (CAPS)>_INCLUDE_DIR`` |
| 421 | - ``<DEPENDENCY_NAME (CAPS)>_LIBRARY`` |
| 422 | |
| 423 | This bypasses *all* searching in the |
| 424 | ``Find<DEPENDENCY_NAME>.cmake`` script, but validation is still |
| 425 | performed. |
| 426 | |
| 427 | These variables are available to set in the ``CMake`` GUI. They |
| 428 | are visible in the *Standard View* if the library has not been |
| 429 | found (but the current Ceres configuration requires it), but |
| 430 | are always visible in the *Advanced View*. They can also be |
| 431 | set directly via ``-D<VAR>=<VALUE>`` arguments to ``CMake``. |
| 432 | |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 433 | .. _section-using-ceres: |
| 434 | |
| 435 | Using Ceres with CMake |
| 436 | ====================== |
| 437 | |
Sameer Agarwal | 564a83f | 2013-03-26 11:11:43 -0700 | [diff] [blame] | 438 | Once the library is installed with ``make install``, it is possible to |
| 439 | use CMake with `FIND_PACKAGE() |
| 440 | <http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_package>`_ |
| 441 | in order to compile **user code** against Ceres. For example, for |
| 442 | `examples/helloworld.cc |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 443 | <https://ceres-solver.googlesource.com/ceres-solver/+/master/examples/helloworld.cc>`_ |
| 444 | the following CMakeList.txt can be used: |
| 445 | |
| 446 | .. code-block:: cmake |
| 447 | |
| 448 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) |
| 449 | |
| 450 | PROJECT(helloworld) |
| 451 | |
| 452 | FIND_PACKAGE(Ceres REQUIRED) |
Alex Stewart | 78cc2c4 | 2013-10-11 15:50:10 +0100 | [diff] [blame] | 453 | INCLUDE_DIRECTORIES(${CERES_INCLUDE_DIRS}) |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 454 | |
| 455 | # helloworld |
| 456 | ADD_EXECUTABLE(helloworld helloworld.cc) |
| 457 | TARGET_LINK_LIBRARIES(helloworld ${CERES_LIBRARIES}) |
| 458 | |
| 459 | Specify Ceres version |
| 460 | --------------------- |
| 461 | |
Sameer Agarwal | 564a83f | 2013-03-26 11:11:43 -0700 | [diff] [blame] | 462 | Additionally, when CMake has found Ceres it can check the package |
| 463 | version, if it has been specified in the `FIND_PACKAGE() |
| 464 | <http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_package>`_ |
| 465 | call. For example: |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 466 | |
| 467 | .. code-block:: cmake |
| 468 | |
| 469 | FIND_PACKAGE(Ceres 1.2.3 REQUIRED) |
| 470 | |
| 471 | The version is an optional argument. |
| 472 | |
| 473 | Local installations |
| 474 | ------------------- |
| 475 | |
| 476 | If Ceres was installed in a non-standard path by specifying |
Sameer Agarwal | 564a83f | 2013-03-26 11:11:43 -0700 | [diff] [blame] | 477 | -DCMAKE_INSTALL_PREFIX="/some/where/local", then the user should add |
| 478 | the **PATHS** option to the ``FIND_PACKAGE()`` command. e.g., |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 479 | |
| 480 | .. code-block:: cmake |
| 481 | |
| 482 | FIND_PACKAGE(Ceres REQUIRED PATHS "/some/where/local/") |
| 483 | |
Sameer Agarwal | 8ba41e8 | 2013-10-09 11:35:40 -0700 | [diff] [blame] | 484 | Note that this can be used to have multiple versions of Ceres |
| 485 | installed. |