Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 1 | .. _chapter-building: |
| 2 | |
Sameer Agarwal | 480f9b8 | 2013-03-03 20:15:22 -0800 | [diff] [blame] | 3 | ===================== |
| 4 | Building Ceres Solver |
| 5 | ===================== |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 6 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 7 | Ceres source code and documentation are hosted at `code.google.com |
| 8 | <http://code.google.com/p/ceres-solver/>`_. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 9 | |
| 10 | .. _section-dependencies: |
| 11 | |
| 12 | Dependencies |
| 13 | ============ |
| 14 | |
| 15 | Ceres relies on a number of open source libraries, some of which are |
| 16 | optional. For details on customizing the build process, see |
| 17 | :ref:`section-customizing` . |
| 18 | |
| 19 | 1. `CMake <http://www.cmake.org>`_ is a cross platform build |
| 20 | system. Ceres needs a relatively recent version of CMake (version |
| 21 | 2.8.0 or better). |
| 22 | |
| 23 | 2. `eigen3 <http://eigen.tuxfamily.org/index.php?title=Main_Page>`_ is |
| 24 | used for doing all the low level matrix and linear algebra operations. |
| 25 | |
Pablo Speciale | ac0d416 | 2013-03-20 18:32:14 -0700 | [diff] [blame] | 26 | 3. `google-glog <http://code.google.com/p/google-glog>`_ is |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 27 | used for error checking and logging. Ceres needs glog version 0.3.1 or |
| 28 | later. Version 0.3 (which ships with Fedora 16) has a namespace bug |
| 29 | which prevents Ceres from building. |
| 30 | |
| 31 | 4. `gflags <http://code.google.com/p/gflags>`_ is a library for |
| 32 | processing command line flags. It is used by some of the examples and |
| 33 | tests. While it is not strictly necessary to build the library, we |
| 34 | strongly recommend building the library with gflags. |
| 35 | |
| 36 | |
| 37 | 5. `SuiteSparse |
| 38 | <http://www.cise.ufl.edu/research/sparse/SuiteSparse/>`_ is used for |
| 39 | sparse matrix analysis, ordering and factorization. In particular |
| 40 | Ceres uses the AMD, COLAMD and CHOLMOD libraries. This is an optional |
| 41 | dependency. |
| 42 | |
| 43 | 6. `CXSparse <http://www.cise.ufl.edu/research/sparse/CXSparse/>`_ is |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 44 | a sparse matrix library similar in scope to ``SuiteSparse`` but with |
| 45 | no dependencies on ``LAPACK`` and ``BLAS``. This makes for a simpler |
| 46 | build process and a smaller binary. The simplicity comes at a cost -- |
| 47 | for all but the most trivial matrices, ``SuiteSparse`` is |
| 48 | significantly faster than ``CXSparse``. |
| 49 | |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 50 | |
| 51 | 7. `BLAS <http://www.netlib.org/blas/>`_ and `LAPACK |
| 52 | <http://www.netlib.org/lapack/>`_ routines are needed by |
| 53 | SuiteSparse. We recommend either `GotoBlas2 |
| 54 | <http://www.tacc.utexas.edu/tacc- projects/gotoblas2>`_ or `ATLAS |
| 55 | <http://math- atlas.sourceforge.net/>`_ , both of which ship with BLAS |
| 56 | and LAPACK routines. |
| 57 | |
| 58 | 8. `protobuf <http://code.google.com/p/protobuf/>`_ is used for |
| 59 | serializing and deserializing linear least squares problems to |
| 60 | disk. This is useful for debugging and testing. It is an optional |
| 61 | depdendency and without it some of the tests will be disabled. |
| 62 | |
| 63 | .. _section-linux: |
| 64 | |
| 65 | Building on Linux |
| 66 | ================= |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 67 | We will use `Ubuntu <http://www.ubuntu.com>`_ as our example |
| 68 | platform. Start by installing all the dependencies. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 69 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 70 | .. code-block:: bash |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 71 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 72 | # CMake |
| 73 | sudo apt-hey install cmake |
| 74 | # gflags |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 75 | tar -xvzf gflags-2.0.tar.gz |
| 76 | cd gflags-2.0 |
| 77 | ./configure --prefix=/usr/local |
| 78 | make |
| 79 | sudo make install. |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 80 | # google-glog must be configured to use the previously installed gflags |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 81 | tar -xvzf glog-0.3.2.tar.gz |
| 82 | cd glog-0.3.2 |
| 83 | ./configure --with-gflags=/usr/local/ |
| 84 | make |
| 85 | sudo make install |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 86 | # Eigen3 |
| 87 | sudo apt-get install libeigen3-dev |
| 88 | # SuiteSparse and CXSparse |
| 89 | sudo apt-get install libsuitesparse-dev |
| 90 | # protobuf |
| 91 | sudo apt-get install libprotobuf-dev |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 92 | |
| 93 | We are now ready to build and test Ceres. Note that ``CMake`` requires |
| 94 | the exact path to the ``libglog.a`` and ``libgflag.a``. |
| 95 | |
| 96 | .. code-block:: bash |
| 97 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 98 | tar zxf ceres-solver-1.5.0.tar.gz |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 99 | mkdir ceres-bin |
| 100 | cd ceres-bin |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 101 | cmake ../ceres-solver-1.5.0 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 102 | make -j3 |
| 103 | make test |
| 104 | |
| 105 | You can also try running the command line bundling application with one of the |
| 106 | included problems, which comes from the University of Washington's BAL |
| 107 | dataset [Agarwal]_. |
| 108 | |
| 109 | .. code-block:: bash |
| 110 | |
| 111 | bin/simple_bundle_adjuster \ |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 112 | ../ceres-solver-1.5.0/data/problem-16-22106-pre.txt \ |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 113 | |
| 114 | This runs Ceres for a maximum of 10 iterations using the |
| 115 | ``DENSE_SCHUR`` linear solver. The output should look something like |
| 116 | this. |
| 117 | |
| 118 | .. code-block:: bash |
| 119 | |
| 120 | 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: 1.16e-01 tt: 3.39e-01 |
| 121 | 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: 3.90e-01 tt: 7.29e-01 |
| 122 | 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: 3.52e-01 tt: 1.08e+00 |
| 123 | 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: 3.60e-01 tt: 1.44e+00 |
| 124 | 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: 3.62e-01 tt: 1.80e+00 |
| 125 | 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: 3.54e-01 tt: 2.16e+00 |
| 126 | 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: 3.59e-01 tt: 2.52e+00 |
| 127 | |
| 128 | Ceres Solver Report |
| 129 | ------------------- |
| 130 | Original Reduced |
| 131 | Parameter blocks 22122 22122 |
| 132 | Parameters 66462 66462 |
| 133 | Residual blocks 83718 83718 |
| 134 | Residual 167436 167436 |
| 135 | Trust Region Strategy LEVENBERG_MARQUARDT |
| 136 | |
| 137 | Given Used |
| 138 | Linear solver DENSE_SCHUR DENSE_SCHUR |
| 139 | Preconditioner N/A N/A |
| 140 | Threads: 1 1 |
| 141 | Linear solver threads 1 1 |
| 142 | Linear solver ordering AUTOMATIC 22106,16 |
| 143 | |
| 144 | Cost: |
| 145 | Initial 4.185660e+06 |
| 146 | Final 1.803390e+04 |
| 147 | Change 4.167626e+06 |
| 148 | |
| 149 | Number of iterations: |
| 150 | Successful 6 |
| 151 | Unsuccessful 0 |
| 152 | Total 6 |
| 153 | |
| 154 | Time (in seconds): |
| 155 | Preprocessor 2.229e-01 |
| 156 | |
| 157 | Evaluator::Residuals 7.438e-02 |
| 158 | Evaluator::Jacobians 6.790e-01 |
| 159 | Linear Solver 1.681e+00 |
| 160 | Minimizer 2.547e+00 |
| 161 | |
| 162 | Postprocessor 1.920e-02 |
| 163 | Total 2.823e+00 |
| 164 | |
| 165 | Termination: FUNCTION_TOLERANCE |
| 166 | |
| 167 | .. section-osx: |
| 168 | |
| 169 | Building on Mac OS X |
| 170 | ==================== |
| 171 | |
| 172 | On OS X, we recommend using the `homebrew |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 173 | <http://mxcl.github.com/homebrew/>`_ package manager. Start by |
| 174 | installing all the dependencies. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 175 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 176 | .. code-block:: bash |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 177 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 178 | # CMake |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 179 | brew install cmake |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 180 | # google-glog and gflags |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 181 | brew install glog |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 182 | # Eigen2 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 183 | brew install eigen |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 184 | # SuiteSparse and CXSparse |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 185 | brew install suite-sparse |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 186 | # protobuf |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 187 | brew install protobuf |
| 188 | |
| 189 | |
| 190 | We are now ready to build and test Ceres. |
| 191 | |
| 192 | .. code-block:: bash |
| 193 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 194 | tar zxf ceres-solver-1.5.0.tar.gz |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 195 | mkdir ceres-bin |
| 196 | cd ceres-bin |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 197 | cmake ../ceres-solver-1.5.0 |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 198 | make -j3 |
| 199 | make test |
| 200 | |
| 201 | |
| 202 | Like the Linux build, you should now be able to run |
| 203 | ``bin/simple_bundle_adjuster``. |
| 204 | |
| 205 | .. _section-windows: |
| 206 | |
| 207 | Building on Windows with Visual Studio |
| 208 | ====================================== |
| 209 | |
| 210 | On Windows, we support building with Visual Studio 2010 or newer. Note |
| 211 | that the Windows port is less featureful and less tested than the |
| 212 | Linux or Mac OS X versions due to the unavaliability of SuiteSparse |
| 213 | and ``CXSparse``. Building is also more involved since there is no |
| 214 | automated way to install the dependencies. |
| 215 | |
| 216 | #. Make a toplevel directory for deps & build & src somewhere: ``ceres/`` |
| 217 | #. Get dependencies; unpack them as subdirectories in ``ceres/`` |
| 218 | (``ceres/eigen``, ``ceres/glog``, etc) |
| 219 | |
| 220 | #. ``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] | 221 | no need to build anything; just unpack the source tarball. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 222 | |
| 223 | #. ``google-glog`` Open up the Visual Studio solution and build it. |
| 224 | #. ``gflags`` Open up the Visual Studio solution and build it. |
| 225 | |
| 226 | #. Unpack the Ceres tarball into ``ceres``. For the tarball, you |
| 227 | should get a directory inside ``ceres`` similar to |
| 228 | ``ceres-solver-1.3.0``. Alternately, checkout Ceres via ``git`` to |
| 229 | get ``ceres-solver.git`` inside ``ceres``. |
| 230 | |
| 231 | #. Install ``CMake``, |
| 232 | |
| 233 | #. Make a dir ``ceres/ceres-bin`` (for an out-of-tree build) |
| 234 | |
| 235 | #. Run ``CMake``; select the ``ceres-solver-X.Y.Z`` or |
| 236 | ``ceres-solver.git`` directory for the CMake file. Then select the |
| 237 | ``ceres-bin`` for the build dir. |
| 238 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 239 | #. 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] | 240 | You'll need to set: |
| 241 | |
| 242 | #. ``GLOG_INCLUDE`` |
| 243 | #. ``GLOG_LIB`` |
| 244 | #. ``GFLAGS_LIB`` |
| 245 | #. ``GFLAGS_INCLUDE`` |
| 246 | |
| 247 | to the appropriate place where you unpacked/built them. |
| 248 | |
| 249 | #. You may have to tweak some more settings to generate a MSVC |
| 250 | project. After each adjustment, try pressing Configure & Generate |
| 251 | until it generates successfully. |
| 252 | |
| 253 | #. Open the solution and build it in MSVC |
| 254 | |
| 255 | |
| 256 | To run the tests, select the ``RUN_TESTS`` target and hit **Build |
| 257 | RUN_TESTS** from the build menu. |
| 258 | |
| 259 | Like the Linux build, you should now be able to run ``bin/simple_bundle_adjuster``. |
| 260 | |
| 261 | Notes: |
| 262 | |
| 263 | #. The default build is Debug; consider switching it to release mode. |
| 264 | #. Currently ``system_test`` is not working properly. |
| 265 | #. Building Ceres as a DLL is not supported; patches welcome. |
| 266 | #. CMake puts the resulting test binaries in ``ceres-bin/examples/Debug`` |
| 267 | by default. |
| 268 | #. The solvers supported on Windows are ``DENSE_QR``, ``DENSE_SCHUR``, |
| 269 | ``CGNR``, and ``ITERATIVE_SCHUR``. |
| 270 | #. We're looking for someone to work with upstream ``SuiteSparse`` to |
| 271 | port their build system to something sane like ``CMake``, and get a |
| 272 | supported Windows port. |
| 273 | |
| 274 | |
| 275 | .. _section-android: |
| 276 | |
| 277 | Building on Android |
| 278 | =================== |
| 279 | |
| 280 | |
| 281 | Download the ``Android NDK``. Run ``ndk-build`` from inside the |
| 282 | ``jni`` directory. Use the ``libceres.a`` that gets created. |
| 283 | |
| 284 | .. _section-customizing: |
| 285 | |
| 286 | Customizing the build |
| 287 | ===================== |
| 288 | |
| 289 | It is possible to reduce the libraries needed to build Ceres and |
| 290 | customize the build process by passing appropriate flags to |
| 291 | ``CMake``. Use these flags only if you really know what you are doing. |
| 292 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 293 | #. ``-DPROTOBUF=OFF``: ``protobuf`` is a large and complicated |
| 294 | dependency. If you do not care for the tests that depend on it and |
| 295 | the logging support it enables, you can use this flag to turn it |
| 296 | off. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 297 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 298 | #. ``-DSUITESPARSE=OFF``: By default, Ceres will link to |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 299 | ``SuiteSparse`` if all its dependencies are present. Use this flag |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 300 | to build Ceres without ``SuiteSparse``. This will also disable |
Sameer Agarwal | 564a83f | 2013-03-26 11:11:43 -0700 | [diff] [blame^] | 301 | dependency checking for ``LAPACK`` and ``BLAS``. This will reduce |
| 302 | Ceres' dependencies down to ``Eigen``, ``gflags`` and |
| 303 | ``google-glog``. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 304 | |
Sameer Agarwal | 564a83f | 2013-03-26 11:11:43 -0700 | [diff] [blame^] | 305 | #. ``-DCXSPARSE=OFF``: By default, Ceres will link to ``CXSparse`` if |
| 306 | all its dependencies are present. Use this flag to builds Ceres |
| 307 | without ``CXSparse``. This will reduce Ceres' dependencies down to |
| 308 | ``Eigen``, ``gflags`` and ``google-glog``. |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 309 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 310 | #. ``-DGFLAGS=OFF``: Use this flag to build Ceres without |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 311 | ``gflags``. This will also prevent some of the example code from |
| 312 | building. |
| 313 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 314 | #. ``-DSCHUR_SPECIALIZATIONS=OFF``: If you are concerned about binary |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 315 | size/compilation time over some small (10-20%) performance gains in |
| 316 | the ``SPARSE_SCHUR`` solver, you can disable some of the template |
| 317 | specializations by using this flag. |
| 318 | |
Sameer Agarwal | 8140f0f | 2013-03-12 09:45:08 -0700 | [diff] [blame] | 319 | #. ``-DLINE_SEARCH_MINIMIZER=OFF``: The line search based minimizer is |
| 320 | mostly suitable for large scale optimization problems, or when sparse |
| 321 | linear algebra libraries are not available. You can further save on |
| 322 | some compile time and binary size by using this flag. |
| 323 | |
Sameer Agarwal | 08c891f | 2013-02-04 20:18:58 -0800 | [diff] [blame] | 324 | #. ``-DOPENMP=OFF``: On certain platforms like Android, |
| 325 | multi-threading with ``OpenMP`` is not supported. Use this flag to |
Sameer Agarwal | 3d87b72 | 2013-02-02 00:49:31 -0800 | [diff] [blame] | 326 | disable multithreading. |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 327 | |
| 328 | #. ``-DBUILD_DOCUMENTATION=ON``: Use this flag to enable building the |
Sameer Agarwal | 564a83f | 2013-03-26 11:11:43 -0700 | [diff] [blame^] | 329 | documentation. In addition, ``make ceres_docs`` can be used to |
| 330 | build only the documentation. |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 331 | |
| 332 | .. _section-using-ceres: |
| 333 | |
| 334 | Using Ceres with CMake |
| 335 | ====================== |
| 336 | |
Sameer Agarwal | 564a83f | 2013-03-26 11:11:43 -0700 | [diff] [blame^] | 337 | Once the library is installed with ``make install``, it is possible to |
| 338 | use CMake with `FIND_PACKAGE() |
| 339 | <http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_package>`_ |
| 340 | in order to compile **user code** against Ceres. For example, for |
| 341 | `examples/helloworld.cc |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 342 | <https://ceres-solver.googlesource.com/ceres-solver/+/master/examples/helloworld.cc>`_ |
| 343 | the following CMakeList.txt can be used: |
| 344 | |
| 345 | .. code-block:: cmake |
| 346 | |
| 347 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) |
| 348 | |
| 349 | PROJECT(helloworld) |
| 350 | |
| 351 | FIND_PACKAGE(Ceres REQUIRED) |
| 352 | INCLUDE_DIRECTORIES(${CERES_INCLUDES}) |
| 353 | |
| 354 | # helloworld |
| 355 | ADD_EXECUTABLE(helloworld helloworld.cc) |
| 356 | TARGET_LINK_LIBRARIES(helloworld ${CERES_LIBRARIES}) |
| 357 | |
| 358 | Specify Ceres version |
| 359 | --------------------- |
| 360 | |
Sameer Agarwal | 564a83f | 2013-03-26 11:11:43 -0700 | [diff] [blame^] | 361 | Additionally, when CMake has found Ceres it can check the package |
| 362 | version, if it has been specified in the `FIND_PACKAGE() |
| 363 | <http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_package>`_ |
| 364 | call. For example: |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 365 | |
| 366 | .. code-block:: cmake |
| 367 | |
| 368 | FIND_PACKAGE(Ceres 1.2.3 REQUIRED) |
| 369 | |
| 370 | The version is an optional argument. |
| 371 | |
| 372 | Local installations |
| 373 | ------------------- |
| 374 | |
| 375 | If Ceres was installed in a non-standard path by specifying |
Sameer Agarwal | 564a83f | 2013-03-26 11:11:43 -0700 | [diff] [blame^] | 376 | -DCMAKE_INSTALL_PREFIX="/some/where/local", then the user should add |
| 377 | the **PATHS** option to the ``FIND_PACKAGE()`` command. e.g., |
Pablo Speciale | 6ae3475 | 2013-03-24 22:30:52 -0700 | [diff] [blame] | 378 | |
| 379 | .. code-block:: cmake |
| 380 | |
| 381 | FIND_PACKAGE(Ceres REQUIRED PATHS "/some/where/local/") |
| 382 | |
| 383 | Note that this can be used to have multiple versions of Ceres installed. |
Pablo Speciale | 6bcb8d9 | 2013-03-25 16:40:26 -0700 | [diff] [blame] | 384 | |
| 385 | Compiling against static or shared library |
| 386 | ------------------------------------------ |
| 387 | |
| 388 | .. code-block:: cmake |
| 389 | |
| 390 | TARGET_LINK_LIBRARIES(helloworld ${CERES_LIBRARIES}) |
| 391 | |
| 392 | will result in a statically linked binary. Changing this line to |
| 393 | |
| 394 | .. code-block:: cmake |
| 395 | |
| 396 | TARGET_LINK_LIBRARIES(helloworld ${CERES_LIBRARIES_SHARED}) |
| 397 | |
| 398 | will result in a dynamically linked binary. |