blob: 902b9ea232d74469cd5a8f05a452af054f65b19d [file] [log] [blame]
Sameer Agarwal3d87b722013-02-02 00:49:31 -08001.. _chapter-building:
2
Sameer Agarwal3a2158d2013-10-03 07:12:14 -07003============
4Installation
5============
Sameer Agarwal3d87b722013-02-02 00:49:31 -08006
Sameer Agarwal97e17952013-05-26 11:48:09 -07007Stable Ceres Solver releases are available for download at
8`code.google.com <http://code.google.com/p/ceres-solver/>`_. For the
9more adventurous, the git repository is hosted on `Gerrit
10<https://ceres-solver-review.googlesource.com/>`_.
Sameer Agarwal3d87b722013-02-02 00:49:31 -080011
12.. _section-dependencies:
13
14Dependencies
15============
16
17Ceres relies on a number of open source libraries, some of which are
18optional. For details on customizing the build process, see
19:ref:`section-customizing` .
20
211. `CMake <http://www.cmake.org>`_ is a cross platform build
22system. Ceres needs a relatively recent version of CMake (version
232.8.0 or better).
24
252. `eigen3 <http://eigen.tuxfamily.org/index.php?title=Main_Page>`_ is
26used for doing all the low level matrix and linear algebra operations.
27
Pablo Specialeac0d4162013-03-20 18:32:14 -0700283. `google-glog <http://code.google.com/p/google-glog>`_ is
Sameer Agarwal3d87b722013-02-02 00:49:31 -080029used for error checking and logging. Ceres needs glog version 0.3.1 or
30later. Version 0.3 (which ships with Fedora 16) has a namespace bug
Alex Stewartfc8ede22013-10-08 19:49:42 +010031which prevents Ceres from building. Ceres contains a stripped-down,
32minimal version of ``glog`` called ``miniglog``, which can be enabled
33with the ``MINIGLOG`` build option. If enabled, it replaces the
34requirement for ``glog``. However, in general it is recommended that
35you use the full ``glog``.
Sameer Agarwal3d87b722013-02-02 00:49:31 -080036
374. `gflags <http://code.google.com/p/gflags>`_ is a library for
38processing command line flags. It is used by some of the examples and
39tests. While it is not strictly necessary to build the library, we
40strongly recommend building the library with gflags.
41
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800425. `SuiteSparse
43<http://www.cise.ufl.edu/research/sparse/SuiteSparse/>`_ is used for
44sparse matrix analysis, ordering and factorization. In particular
Sameer Agarwal97e17952013-05-26 11:48:09 -070045Ceres uses the AMD, CAMD, COLAMD and CHOLMOD libraries. This is an optional
Sameer Agarwal3d87b722013-02-02 00:49:31 -080046dependency.
47
486. `CXSparse <http://www.cise.ufl.edu/research/sparse/CXSparse/>`_ is
Sameer Agarwal08c891f2013-02-04 20:18:58 -080049a sparse matrix library similar in scope to ``SuiteSparse`` but with
50no dependencies on ``LAPACK`` and ``BLAS``. This makes for a simpler
51build process and a smaller binary. The simplicity comes at a cost --
52for all but the most trivial matrices, ``SuiteSparse`` is
Alex Stewartfc8ede22013-10-08 19:49:42 +010053significantly faster than ``CXSparse``. This is an optional dependency.
Sameer Agarwal08c891f2013-02-04 20:18:58 -080054
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800557. `BLAS <http://www.netlib.org/blas/>`_ and `LAPACK
56<http://www.netlib.org/lapack/>`_ routines are needed by
Alex Stewartfc8ede22013-10-08 19:49:42 +010057SuiteSparse, and optionally used by Ceres directly for some operations.
58We recommend `ATLAS <http://math-atlas.sourceforge.net/>`_,
59which includes BLAS and LAPACK routines. It is also possible to use
60`OpenBLAS <https://github.com/xianyi/OpenBLAS>`_ . However, one needs
61to be careful to `turn off the threading
Sameer Agarwal0a07fbf2013-07-10 11:57:35 -070062<https://github.com/xianyi/OpenBLAS/wiki/faq#wiki-multi-threaded>`_
63inside ``OpenBLAS`` as it conflicts with use of threads in Ceres.
Sameer Agarwal3d87b722013-02-02 00:49:31 -080064
Sameer Agarwal3d87b722013-02-02 00:49:31 -080065.. _section-linux:
66
67Building on Linux
68=================
Sameer Agarwal08c891f2013-02-04 20:18:58 -080069We will use `Ubuntu <http://www.ubuntu.com>`_ as our example
70platform. Start by installing all the dependencies.
Sameer Agarwal3d87b722013-02-02 00:49:31 -080071
Alex Stewart0b07d3e2013-10-04 16:17:06 +010072.. NOTE::
Sameer Agarwalc7ebfb82013-10-09 22:13:01 -070073
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 Stewart0b07d3e2013-10-04 16:17:06 +010080
Sameer Agarwal08c891f2013-02-04 20:18:58 -080081.. code-block:: bash
Sameer Agarwal3d87b722013-02-02 00:49:31 -080082
Sameer Agarwal08c891f2013-02-04 20:18:58 -080083 # CMake
Sameer Agarwal8f7e8962013-06-03 13:07:39 -070084 sudo apt-get install cmake
Sameer Agarwal08c891f2013-02-04 20:18:58 -080085 # gflags
Sameer Agarwal3d87b722013-02-02 00:49:31 -080086 tar -xvzf gflags-2.0.tar.gz
87 cd gflags-2.0
88 ./configure --prefix=/usr/local
89 make
90 sudo make install.
Sameer Agarwal08c891f2013-02-04 20:18:58 -080091 # google-glog must be configured to use the previously installed gflags
Sameer Agarwal3d87b722013-02-02 00:49:31 -080092 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 Agarwal5d7c1952013-05-07 12:47:51 -070097 # BLAS & LAPACK
Sameer Agarwal0a07fbf2013-07-10 11:57:35 -070098 sudo apt-get install libatlas-base-dev
Sameer Agarwal08c891f2013-02-04 20:18:58 -080099 # Eigen3
100 sudo apt-get install libeigen3-dev
Alex Stewart0b07d3e2013-10-04 16:17:06 +0100101 # 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 Agarwal08c891f2013-02-04 20:18:58 -0800105 sudo apt-get install libsuitesparse-dev
Alex Stewart0b07d3e2013-10-04 16:17:06 +0100106 # - 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 Agarwal3d87b722013-02-02 00:49:31 -0800109
Sameer Agarwal97e17952013-05-26 11:48:09 -0700110We are now ready to build and test Ceres.
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800111
112.. code-block:: bash
113
Sameer Agarwal1a041c32013-11-12 14:17:52 -0800114 tar zxf ceres-solver-1.8.0.tar.gz
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800115 mkdir ceres-bin
116 cd ceres-bin
Sameer Agarwal1a041c32013-11-12 14:17:52 -0800117 cmake ../ceres-solver-1.8.0
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800118 make -j3
119 make test
120
121You can also try running the command line bundling application with one of the
122included problems, which comes from the University of Washington's BAL
123dataset [Agarwal]_.
124
125.. code-block:: bash
126
Sameer Agarwal1a041c32013-11-12 14:17:52 -0800127 bin/simple_bundle_adjuster ../ceres-solver-1.8.0/data/problem-16-22106-pre.txt
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800128
129This runs Ceres for a maximum of 10 iterations using the
130``DENSE_SCHUR`` linear solver. The output should look something like
131this.
132
133.. code-block:: bash
134
Richard Bowenb555b482014-03-27 15:51:28 -0700135 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 Agarwal3d87b722013-02-02 00:49:31 -0800142
Richard Bowenb555b482014-03-27 15:51:28 -0700143Ceres Solver Report
144-------------------
145 Original Reduced
146Parameter blocks 22122 22122
147Parameters 66462 66462
148Residual blocks 83718 83718
149Residual 167436 167436
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800150
Richard Bowenb555b482014-03-27 15:51:28 -0700151Minimizer TRUST_REGION
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800152
Richard Bowenb555b482014-03-27 15:51:28 -0700153Dense linear algebra library EIGEN
154Trust region strategy LEVENBERG_MARQUARDT
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800155
Richard Bowenb555b482014-03-27 15:51:28 -0700156 Given Used
157Linear solver DENSE_SCHUR DENSE_SCHUR
158Threads 1 1
159Linear solver threads 1 1
160Linear solver ordering AUTOMATIC 22106, 16
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800161
Richard Bowenb555b482014-03-27 15:51:28 -0700162Cost:
163Initial 4.185660e+06
164Final 1.803390e+04
165Change 4.167626e+06
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800166
Richard Bowenb555b482014-03-27 15:51:28 -0700167Minimizer iterations 6
168Successful steps 6
169Unsuccessful steps 0
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800170
Richard Bowenb555b482014-03-27 15:51:28 -0700171Time (in seconds):
172Preprocessor 0.173
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800173
Richard Bowenb555b482014-03-27 15:51:28 -0700174 Residual evaluation 0.115
175 Jacobian evaluation 0.498
176 Linear solver 0.517
177Minimizer 1.242
178
179Postprocessor 0.003
180Total 1.437
181
182Termination: CONVERGENCE (Function tolerance reached. |cost_change|/cost: 1.769750e-09 <= 1.000000e-06)
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800183
184.. section-osx:
185
186Building on Mac OS X
187====================
188
189On OS X, we recommend using the `homebrew
Sameer Agarwal97e17952013-05-26 11:48:09 -0700190<http://mxcl.github.com/homebrew/>`_ package manager to install the
191dependencies. There is no need to install ``BLAS`` or ``LAPACK``
192separately as OS X ships with optimized ``BLAS`` and ``LAPACK``
193routines as part of the `vecLib
Sameer Agarwal5d7c1952013-05-07 12:47:51 -0700194<https://developer.apple.com/library/mac/#documentation/Performance/Conceptual/vecLib/Reference/reference.html>`_
195framework.
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800196
Alex Stewartf5f21b52013-10-10 19:22:31 +0100197.. 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 Agarwal08c891f2013-02-04 20:18:58 -0800203.. code-block:: bash
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800204
Sameer Agarwal08c891f2013-02-04 20:18:58 -0800205 # CMake
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800206 brew install cmake
Sameer Agarwal08c891f2013-02-04 20:18:58 -0800207 # google-glog and gflags
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800208 brew install glog
Sameer Agarwal5d7c1952013-05-07 12:47:51 -0700209 # Eigen3
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800210 brew install eigen
Sameer Agarwal08c891f2013-02-04 20:18:58 -0800211 # SuiteSparse and CXSparse
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800212 brew install suite-sparse
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800213
214
215We are now ready to build and test Ceres.
216
217.. code-block:: bash
218
Sameer Agarwal1a041c32013-11-12 14:17:52 -0800219 tar zxf ceres-solver-1.8.0.tar.gz
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800220 mkdir ceres-bin
221 cd ceres-bin
Sameer Agarwal1a041c32013-11-12 14:17:52 -0800222 cmake ../ceres-solver-1.8.0
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800223 make -j3
224 make test
225
226
227Like the Linux build, you should now be able to run
228``bin/simple_bundle_adjuster``.
229
230.. _section-windows:
231
232Building on Windows with Visual Studio
233======================================
234
235On Windows, we support building with Visual Studio 2010 or newer. Note
236that the Windows port is less featureful and less tested than the
Sameer Agarwalebbb9842013-05-26 12:40:12 -0700237Linux or Mac OS X versions due to the unavailability of SuiteSparse
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800238and ``CXSparse``. Building is also more involved since there is no
239automated 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 Agarwal08c891f2013-02-04 20:18:58 -0800246 no need to build anything; just unpack the source tarball.
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800247
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 Agarwal08c891f2013-02-04 20:18:58 -0800264#. Try running ``Configure``. It won't work. It'll show a bunch of options.
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800265 You'll need to set:
266
Alex Stewart78cc2c42013-10-11 15:50:10 +0100267 #. ``EIGEN_INCLUDE_DIR``
268 #. ``GLOG_INCLUDE_DIR``
269 #. ``GLOG_LIBRARY``
270 #. ``GFLAGS_INCLUDE_DIR``
271 #. ``GFLAGS_LIBRARY``
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800272
Alex Stewart78cc2c42013-10-11 15:50:10 +0100273 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 Agarwal3d87b722013-02-02 00:49:31 -0800276
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
284To run the tests, select the ``RUN_TESTS`` target and hit **Build
285RUN_TESTS** from the build menu.
286
Sameer Agarwal8ba41e82013-10-09 11:35:40 -0700287Like the Linux build, you should now be able to run
288``bin/simple_bundle_adjuster``.
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800289
290Notes:
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
306Building on Android
307===================
308
309
310Download the ``Android NDK``. Run ``ndk-build`` from inside the
311``jni`` directory. Use the ``libceres.a`` that gets created.
312
313.. _section-customizing:
314
315Customizing the build
316=====================
317
318It is possible to reduce the libraries needed to build Ceres and
Alex Stewart0b07d3e2013-10-04 16:17:06 +0100319customize the build process by setting the appropriate options in
320``CMake``. These options can either be set in the ``CMake`` GUI,
321or via ``-D<OPTION>=<ON/OFF>`` when running ``CMake`` from the
322command line. In general, you should only modify these options from
323their defaults if you know what you are doing.
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800324
Alex Stewart78cc2c42013-10-11 15:50:10 +0100325.. 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
343Options controlling Ceres configuration
Sameer Agarwal7f336af2013-10-17 23:38:57 -0700344---------------------------------------
Alex Stewart78cc2c42013-10-11 15:50:10 +0100345
Sameer Agarwal8ba41e82013-10-09 11:35:40 -0700346#. ``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 Stewartfc8ede22013-10-08 19:49:42 +0100350
Alex Stewart0b07d3e2013-10-04 16:17:06 +0100351#. ``SUITESPARSE [Default: ON]``: By default, Ceres will link to
Sameer Agarwal8ba41e82013-10-09 11:35:40 -0700352 ``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 Agarwal3d87b722013-02-02 00:49:31 -0800355
Sameer Agarwal8ba41e82013-10-09 11:35:40 -0700356#. ``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 Agarwal3d87b722013-02-02 00:49:31 -0800359
Alex Stewart0b07d3e2013-10-04 16:17:06 +0100360#. ``GFLAGS [Default: ON]``: Turn this ``OFF`` to build Ceres without
Sameer Agarwal3d87b722013-02-02 00:49:31 -0800361 ``gflags``. This will also prevent some of the example code from
362 building.
363
Sameer Agarwal8ba41e82013-10-09 11:35:40 -0700364#. ``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 Stewartfc8ede22013-10-08 19:49:42 +0100369
Sameer Agarwal8ba41e82013-10-09 11:35:40 -0700370#. ``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 Agarwal3d87b722013-02-02 00:49:31 -0800374
Alex Stewart0b07d3e2013-10-04 16:17:06 +0100375#. ``OPENMP [Default: ON]``: On certain platforms like Android,
Sameer Agarwal8ba41e82013-10-09 11:35:40 -0700376 multi-threading with ``OpenMP`` is not supported. Turn this ``OFF``
377 to disable multithreading.
Pablo Speciale6ae34752013-03-24 22:30:52 -0700378
Sameer Agarwal8ba41e82013-10-09 11:35:40 -0700379#. ``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 Stewart0b07d3e2013-10-04 16:17:06 +0100382
Sameer Agarwal8ba41e82013-10-09 11:35:40 -0700383#. ``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 Speciale6ae34752013-03-24 22:30:52 -0700387
Alex Stewartf51f5632013-10-22 14:35:02 +0100388#. ``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 Stewart78cc2c42013-10-11 15:50:10 +0100392
393Options controlling Ceres dependency locations
Sameer Agarwal7f336af2013-10-17 23:38:57 -0700394----------------------------------------------
Alex Stewart78cc2c42013-10-11 15:50:10 +0100395
Sameer Agarwal7f336af2013-10-17 23:38:57 -0700396Ceres uses the ``CMake``
Alex Stewart78cc2c42013-10-11 15:50:10 +0100397`find_package <http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:find_package>`_
398function 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"
402install locations for various OSs for each dependency. However, particularly
403for Windows, they may fail to find the library, in this case you will have to
404manually specify its installed location. The ``Find<DEPENDENCY_NAME>.cmake``
405scripts 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 Speciale6ae34752013-03-24 22:30:52 -0700433.. _section-using-ceres:
434
435Using Ceres with CMake
436======================
437
Sameer Agarwal564a83f2013-03-26 11:11:43 -0700438Once the library is installed with ``make install``, it is possible to
439use CMake with `FIND_PACKAGE()
440<http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_package>`_
441in order to compile **user code** against Ceres. For example, for
442`examples/helloworld.cc
Pablo Speciale6ae34752013-03-24 22:30:52 -0700443<https://ceres-solver.googlesource.com/ceres-solver/+/master/examples/helloworld.cc>`_
444the 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 Stewart78cc2c42013-10-11 15:50:10 +0100453 INCLUDE_DIRECTORIES(${CERES_INCLUDE_DIRS})
Pablo Speciale6ae34752013-03-24 22:30:52 -0700454
455 # helloworld
456 ADD_EXECUTABLE(helloworld helloworld.cc)
457 TARGET_LINK_LIBRARIES(helloworld ${CERES_LIBRARIES})
458
459Specify Ceres version
460---------------------
461
Sameer Agarwal564a83f2013-03-26 11:11:43 -0700462Additionally, when CMake has found Ceres it can check the package
463version, if it has been specified in the `FIND_PACKAGE()
464<http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_package>`_
465call. For example:
Pablo Speciale6ae34752013-03-24 22:30:52 -0700466
467.. code-block:: cmake
468
469 FIND_PACKAGE(Ceres 1.2.3 REQUIRED)
470
471The version is an optional argument.
472
473Local installations
474-------------------
475
476If Ceres was installed in a non-standard path by specifying
Sameer Agarwal564a83f2013-03-26 11:11:43 -0700477-DCMAKE_INSTALL_PREFIX="/some/where/local", then the user should add
478the **PATHS** option to the ``FIND_PACKAGE()`` command. e.g.,
Pablo Speciale6ae34752013-03-24 22:30:52 -0700479
480.. code-block:: cmake
481
482 FIND_PACKAGE(Ceres REQUIRED PATHS "/some/where/local/")
483
Sameer Agarwal8ba41e82013-10-09 11:35:40 -0700484Note that this can be used to have multiple versions of Ceres
485installed.