| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052 | .. _chapter-installation:============Installation============Getting the source code=======================.. _section-source:You can start with the `latest stable release<http://ceres-solver.org/ceres-solver-1.12.0.tar.gz>`_ . Or if you wantthe latest version, you can clone the git repository.. code-block:: bash       git clone https://ceres-solver.googlesource.com/ceres-solver.. _section-dependencies:Dependencies============Ceres relies on a number of open source libraries, some of which areoptional. For details on customizing the build process, see:ref:`section-customizing` .- `Eigen <http://eigen.tuxfamily.org/index.php?title=Main_Page>`_  3.2.2 or later **strongly** recommended, 3.1.0 or later **required**.  .. NOTE ::    Ceres can also use Eigen as a sparse linear algebra    library. Please see the documentation for ``EIGENSPARSE`` for    more details.- `CMake <http://www.cmake.org>`_ 2.8.0 or later.  **Required on all platforms except for Android.**- `glog <https://github.com/google/glog>`_ 0.3.1 or  later. **Recommended**  ``glog`` is used extensively throughout Ceres for logging detailed  information about memory allocations and time consumed in various  parts of the solve, internal error conditions etc. The Ceres  developers use it extensively to observe and analyze Ceres's  performance. `glog <https://github.com/google/glog>`_ allows you to  control its behaviour from the command line. Starting with  ``-logtostderr`` you can add ``-v=N`` for increasing values of ``N``  to get more and more verbose and detailed information about Ceres  internals.  Unfortunately, the current version of `google-glog  <https://github.com/google/glog>`_ does not build using the Android  NDK. So, Ceres also ships with a minimal replacement of ``glog``  called ``miniglog`` that can be enabled with the ``MINIGLOG`` build  option.  So, in an attempt to reduce dependencies, it is tempting to use  `miniglog` on platforms other than Android. While there is nothing  preventing the user from doing so, we strongly recommend against  it. ``miniglog`` has worse performance than ``glog`` and is much  harder to control and use.  .. NOTE ::     If you are compiling ``glog`` from source, please note that     currently, the unit tests for ``glog`` (which are enabled by     default) do not compile against a default build of ``gflags`` 2.1     as the gflags namespace changed from ``google::`` to     ``gflags::``.  A patch to fix this is available from `here     <https://code.google.com/p/google-glog/issues/detail?id=194>`_.- `gflags <https://github.com/gflags/gflags>`_. Needed to build  examples and tests.- `SuiteSparse  <http://faculty.cse.tamu.edu/davis/suitesparse.html>`_. Needed for  solving large sparse linear systems. **Optional; strongly recomended  for large scale bundle adjustment**- `CXSparse <http://faculty.cse.tamu.edu/davis/suitesparse.html>`_.  Similar to ``SuiteSparse`` but simpler and slower. CXSparse has  no dependencies on ``LAPACK`` and ``BLAS``. This makes for a simpler  build process and a smaller binary. **Optional**- `BLAS <http://www.netlib.org/blas/>`_ and `LAPACK  <http://www.netlib.org/lapack/>`_ routines are needed by  ``SuiteSparse``, and optionally used by Ceres directly for some  operations.  On ``UNIX`` OSes other than Mac OS X we recommend `ATLAS  <http://math-atlas.sourceforge.net/>`_, which includes ``BLAS`` and  ``LAPACK`` routines. It is also possible to use `OpenBLAS  <https://github.com/xianyi/OpenBLAS>`_ . However, one needs to be  careful to `turn off the threading  <https://github.com/xianyi/OpenBLAS/wiki/faq#wiki-multi-threaded>`_  inside ``OpenBLAS`` as it conflicts with use of threads in Ceres.  Mac OS X ships with an optimized ``LAPACK`` and ``BLAS``  implementation as part of the ``Accelerate`` framework. The Ceres  build system will automatically detect and use it.  For Windows things are much more complicated. `LAPACK For  Windows <http://icl.cs.utk.edu/lapack-for-windows/lapack/>`_  has detailed instructions..  **Optional but required for** ``SuiteSparse``... _section-linux:Linux=====We will use `Ubuntu <http://www.ubuntu.com>`_ as our example linuxdistribution... NOTE:: Up to at least Ubuntu 14.04, the SuiteSparse package in the official package repository (built from SuiteSparse v3.4.0) **cannot** be used to build Ceres as a *shared* library.  Thus if you want to build Ceres as a shared library using SuiteSparse, you must perform a source install of SuiteSparse or use an external PPA (see `bug report here <https://bugs.launchpad.net/ubuntu/+source/suitesparse/+bug/1333214>`_). It is recommended that you use the current version of SuiteSparse (4.2.1 at the time of writing).Start by installing all the dependencies... code-block:: bash     # CMake     sudo apt-get install cmake     # google-glog + gflags     sudo apt-get install libgoogle-glog-dev     # BLAS & LAPACK     sudo apt-get install libatlas-base-dev     # Eigen3     sudo apt-get install libeigen3-dev     # SuiteSparse and CXSparse (optional)     # - If you want to build Ceres as a *static* library (the default)     #   you can use the SuiteSparse package in the main Ubuntu package     #   repository:     sudo apt-get install libsuitesparse-dev     # - However, if you want to build Ceres as a *shared* library, you must     #   add the following PPA:     sudo add-apt-repository ppa:bzindovic/suitesparse-bugfix-1319687     sudo apt-get update     sudo apt-get install libsuitesparse-devWe are now ready to build, test, and install Ceres... code-block:: bash tar zxf ceres-solver-1.12.0.tar.gz mkdir ceres-bin cd ceres-bin cmake ../ceres-solver-1.12.0 make -j3 make test # Optionally install Ceres, it can also be exported using CMake which # allows Ceres to be used without requiring installation, see the documentation # for the EXPORT_BUILD_DIR option for more information. make installYou can also try running the command line bundling application with one of theincluded problems, which comes from the University of Washington's BALdataset [Agarwal]_... code-block:: bash bin/simple_bundle_adjuster ../ceres-solver-1.12.0/data/problem-16-22106-pre.txtThis runs Ceres for a maximum of 10 iterations using the``DENSE_SCHUR`` linear solver. The output should look something likethis... code-block:: bash    iter      cost      cost_change  |gradient|   |step|    tr_ratio  tr_radius  ls_iter  iter_time  total_time       0  4.185660e+06    0.00e+00    1.09e+08   0.00e+00   0.00e+00  1.00e+04       0    7.59e-02    3.37e-01       1  1.062590e+05    4.08e+06    8.99e+06   5.36e+02   9.82e-01  3.00e+04       1    1.65e-01    5.03e-01       2  4.992817e+04    5.63e+04    8.32e+06   3.19e+02   6.52e-01  3.09e+04       1    1.45e-01    6.48e-01       3  1.899774e+04    3.09e+04    1.60e+06   1.24e+02   9.77e-01  9.26e+04       1    1.43e-01    7.92e-01       4  1.808729e+04    9.10e+02    3.97e+05   6.39e+01   9.51e-01  2.78e+05       1    1.45e-01    9.36e-01       5  1.803399e+04    5.33e+01    1.48e+04   1.23e+01   9.99e-01  8.33e+05       1    1.45e-01    1.08e+00       6  1.803390e+04    9.02e-02    6.35e+01   8.00e-01   1.00e+00  2.50e+06       1    1.50e-01    1.23e+00    Ceres Solver v1.12.0 Solve Report    ----------------------------------                                         Original                  Reduced    Parameter blocks                        22122                    22122    Parameters                              66462                    66462    Residual blocks                         83718                    83718    Residual                               167436                   167436    Minimizer                        TRUST_REGION    Dense linear algebra library            EIGEN    Trust region strategy     LEVENBERG_MARQUARDT                                            Given                     Used    Linear solver                     DENSE_SCHUR              DENSE_SCHUR    Threads                                     1                        1    Linear solver threads                       1                        1    Linear solver ordering              AUTOMATIC                22106, 16    Cost:    Initial                          4.185660e+06    Final                            1.803390e+04    Change                           4.167626e+06    Minimizer iterations                        6    Successful steps                            6    Unsuccessful steps                          0    Time (in seconds):    Preprocessor                            0.261      Residual evaluation                   0.082      Jacobian evaluation                   0.412      Linear solver                         0.442    Minimizer                               1.051    Postprocessor                           0.002    Total                                   1.357    Termination:                      CONVERGENCE (Function tolerance reached. |cost_change|/cost: 1.769766e-09 <= 1.000000e-06).. section-osx:Mac OS X========.. NOTE:: Ceres will not compile using Xcode 4.5.x (Clang version 4.1) due to a bug in that version of Clang.  If you are running Xcode 4.5.x, please update to Xcode >= 4.6.x before attempting to build Ceres.On OS X, you can either use `MacPorts <https://www.macports.org/>`_ or`Homebrew <http://mxcl.github.com/homebrew/>`_ to install Ceres Solver.If using `MacPorts <https://www.macports.org/>`_, then.. code-block:: bash   sudo port install ceres-solverwill install the latest version.If using `Homebrew <http://mxcl.github.com/homebrew/>`_ and assumingthat you have the ``homebrew/science`` [#f1]_ tap enabled, then.. code-block:: bash      brew install ceres-solverwill install the latest stable version along with all the requireddependencies and.. code-block:: bash      brew install ceres-solver --HEADwill install the latest version in the git repo.You can also install each of the dependencies by hand using `Homebrew<http://mxcl.github.com/homebrew/>`_. There is no need to install``BLAS`` or ``LAPACK`` separately as OS X ships with optimized``BLAS`` and ``LAPACK`` routines as part of the `vecLib<https://developer.apple.com/library/mac/#documentation/Performance/Conceptual/vecLib/Reference/reference.html>`_framework... code-block:: bash      # CMake      brew install cmake      # google-glog and gflags      brew install glog      # Eigen3      brew install eigen      # SuiteSparse and CXSparse      brew install suite-sparseWe are now ready to build, test, and install Ceres... code-block:: bash   tar zxf ceres-solver-1.12.0.tar.gz   mkdir ceres-bin   cd ceres-bin   cmake ../ceres-solver-1.12.0   make -j3   make test   # Optionally install Ceres, it can also be exported using CMake which   # allows Ceres to be used without requiring installation, see the   # documentation for the EXPORT_BUILD_DIR option for more information.   make installLike the Linux build, you should now be able to run``bin/simple_bundle_adjuster``... rubric:: Footnotes.. [#f1] Ceres and many of its dependencies are in `homebrew/science   <https://github.com/Homebrew/homebrew-science>`_ tap. So, if you   don't have this tap enabled, then you will need to enable it as   follows before executing any of the commands in this section.   .. code-block:: bash      brew tap homebrew/science.. _section-windows:Windows=======.. NOTE::  If you find the following CMake difficult to set up, then you may  be interested in a `Microsoft Visual Studio wrapper  <https://github.com/tbennun/ceres-windows>`_ for Ceres Solver by Tal  Ben-Nun.On Windows, we support building with Visual Studio 2010 or newer. Notethat the Windows port is less featureful and less tested than theLinux or Mac OS X versions due to the lack of an officially supportedway of building SuiteSparse and CXSparse.  There are however a numberof unofficial ways of building these libraries. Building on Windowsalso a bit more involved since there is no automated way to installdependencies... NOTE:: Using ``google-glog`` & ``miniglog`` with windows.h. The windows.h header if used with GDI (Graphics Device Interface) defines ``ERROR``, which conflicts with the definition of ``ERROR`` as a LogSeverity level in ``google-glog`` and ``miniglog``.  There are at least two possible fixes to this problem: #. Use ``google-glog`` and define ``GLOG_NO_ABBREVIATED_SEVERITIES``    when building Ceres and your own project, as documented `here    <http://google-glog.googlecode.com/svn/trunk/doc/glog.html>`__.    Note that this fix will not work for ``miniglog``, but use of    ``miniglog`` is strongly discouraged on any platform for which    ``google-glog`` is available (which includes Windows). #. If you do not require GDI, then define ``NOGDI`` **before**    including windows.h.  This solution should work for both    ``google-glog`` and ``miniglog`` and is documented for    ``google-glog`` `here    <https://code.google.com/p/google-glog/issues/detail?id=33>`__.#. Make a toplevel directory for deps & build & src somewhere: ``ceres/``#. Get dependencies; unpack them as subdirectories in ``ceres/``   (``ceres/eigen``, ``ceres/glog``, etc)   #. ``Eigen`` 3.1 (needed on Windows; 3.0.x will not work). There is      no need to build anything; just unpack the source tarball.   #. ``google-glog`` Open up the Visual Studio solution and build it.   #. ``gflags`` Open up the Visual Studio solution and build it.   #. (Experimental) ``SuiteSparse`` Previously SuiteSparse was not      available on Windows, recently it has become possible to build      it on Windows using the `suitesparse-metis-for-windows      <https://github.com/jlblancoc/suitesparse-metis-for-windows>`_      project.  If you wish to use ``SuiteSparse``, follow their      instructions for obtaining and building it.   #. (Experimental) ``CXSparse`` Previously CXSparse was not      available on Windows, there are now several ports that enable it      to be, including: `[1] <https://github.com/PetterS/CXSparse>`_      and `[2] <https://github.com/TheFrenchLeaf/CXSparse>`_.  If you      wish to use ``CXSparse``, follow their instructions for      obtaining and building it.#. Unpack the Ceres tarball into ``ceres``. For the tarball, you   should get a directory inside ``ceres`` similar to   ``ceres-solver-1.3.0``. Alternately, checkout Ceres via ``git`` to   get ``ceres-solver.git`` inside ``ceres``.#. Install ``CMake``,#. Make a dir ``ceres/ceres-bin`` (for an out-of-tree build)#. Run ``CMake``; select the ``ceres-solver-X.Y.Z`` or   ``ceres-solver.git`` directory for the CMake file. Then select the   ``ceres-bin`` for the build dir.#. Try running ``Configure``. It won't work. It'll show a bunch of options.   You'll need to set:   #. ``EIGEN_INCLUDE_DIR_HINTS``   #. ``GLOG_INCLUDE_DIR_HINTS``   #. ``GLOG_LIBRARY_DIR_HINTS``   #. ``GFLAGS_INCLUDE_DIR_HINTS``   #. ``GFLAGS_LIBRARY_DIR_HINTS``   #. (Optional) ``SUITESPARSE_INCLUDE_DIR_HINTS``   #. (Optional) ``SUITESPARSE_LIBRARY_DIR_HINTS``   #. (Optional) ``CXSPARSE_INCLUDE_DIR_HINTS``   #. (Optional) ``CXSPARSE_LIBRARY_DIR_HINTS``   to the appropriate directories where you unpacked/built them. If   any of the variables are not visible in the ``CMake`` GUI, create a   new entry for them.  We recommend using the   ``<NAME>_(INCLUDE/LIBRARY)_DIR_HINTS`` variables rather than   setting the ``<NAME>_INCLUDE_DIR`` & ``<NAME>_LIBRARY`` variables   directly to keep all of the validity checking, and to avoid having   to specify the library files manually.#. You may have to tweak some more settings to generate a MSVC   project.  After each adjustment, try pressing Configure & Generate   until it generates successfully.#. Open the solution and build it in MSVCTo run the tests, select the ``RUN_TESTS`` target and hit **BuildRUN_TESTS** from the build menu.Like the Linux build, you should now be able to run``bin/simple_bundle_adjuster``.Notes:#. The default build is Debug; consider switching it to release mode.#. Currently ``system_test`` is not working properly.#. CMake puts the resulting test binaries in ``ceres-bin/examples/Debug``   by default.#. The solvers supported on Windows are ``DENSE_QR``, ``DENSE_SCHUR``,   ``CGNR``, and ``ITERATIVE_SCHUR``.#. We're looking for someone to work with upstream ``SuiteSparse`` to   port their build system to something sane like ``CMake``, and get a   fully supported Windows port... _section-android:Android=======Download the ``Android NDK`` version ``r9d`` or later. Run``ndk-build`` from inside the ``jni`` directory. Use the``libceres.a`` that gets created... _section-ios:iOS===.. NOTE::   You need iOS version 7.0 or higher to build Ceres Solver.To build Ceres for iOS, we need to force ``CMake`` to find thetoolchains from the iOS SDK instead of using the standard ones. Forexample:.. code-block:: bash   cmake \   -DCMAKE_TOOLCHAIN_FILE=../ceres-solver/cmake/iOS.cmake \   -DEIGEN_INCLUDE_DIR=/path/to/eigen/header \   -DIOS_PLATFORM=<PLATFORM> \   <PATH_TO_CERES_SOURCE>``PLATFORM`` can be: ``OS``, ``SIMULATOR`` or ``SIMULATOR64``. You canbuild for ``OS`` (``armv7``, ``armv7s``, ``arm64``), ``SIMULATOR``(``i386``) or ``SIMULATOR64`` (``x86_64``) separately and use ``lipo``to merge them into one static library.  See ``cmake/iOS.cmake`` formore options.After building, you will get a ``libceres.a`` library, which you willneed to add to your Xcode project.The default CMake configuration builds a bare bones version of CeresSolver that only depends on Eigen (``MINIGLOG`` is compiled into Ceresif it is used), this should be sufficient for solving small tomoderate sized problems (No ``SPARSE_SCHUR``,``SPARSE_NORMAL_CHOLESKY`` linear solvers and no ``CLUSTER_JACOBI``and ``CLUSTER_TRIDIAGONAL`` preconditioners).If you decide to use ``LAPACK`` and ``BLAS``, then you also need toadd ``Accelerate.framework`` to your Xcode project's linkingdependency... _section-customizing:Customizing the build=====================It is possible to reduce the libraries needed to build Ceres andcustomize the build process by setting the appropriate options in``CMake``.  These options can either be set in the ``CMake`` GUI, orvia ``-D<OPTION>=<ON/OFF>`` when running ``CMake`` from the commandline.  In general, you should only modify these options from theirdefaults if you know what you are doing... NOTE:: If you are setting variables via ``-D<VARIABLE>=<VALUE>`` when calling ``CMake``, it is important to understand that this forcibly **overwrites** the variable ``<VARIABLE>`` in the ``CMake`` cache at the start of *every configure*. This can lead to confusion if you are invoking the ``CMake`` `curses <http://www.gnu.org/software/ncurses/ncurses.html>`_ terminal GUI (via ``ccmake``, e.g. ```ccmake -D<VARIABLE>=<VALUE> <PATH_TO_SRC>``).  In this case, even if you change the value of ``<VARIABLE>`` in the ``CMake`` GUI, your changes will be **overwritten** with the value passed via ``-D<VARIABLE>=<VALUE>`` (if one exists) at the start of each configure. As such, it is generally easier not to pass values to ``CMake`` via ``-D`` and instead interactively experiment with their values in the ``CMake`` GUI.  If they are not present in the *Standard View*, toggle to the *Advanced View* with ``<t>``.Options controlling Ceres configuration---------------------------------------#. ``LAPACK [Default: ON]``: By default Ceres will use ``LAPACK`` (&   ``BLAS``) if they are found.  Turn this ``OFF`` to build Ceres   without ``LAPACK``. Turning this ``OFF`` also disables   ``SUITESPARSE`` as it depends on ``LAPACK``.#. ``SUITESPARSE [Default: ON]``: By default, Ceres will link to   ``SuiteSparse`` if it and all of its dependencies are present. Turn   this ``OFF`` to build Ceres without ``SuiteSparse``. Note that   ``LAPACK`` must be ``ON`` in order to build with ``SuiteSparse``.#. ``CXSPARSE [Default: ON]``: By default, Ceres will link to   ``CXSparse`` if all its dependencies are present. Turn this ``OFF``   to build Ceres without ``CXSparse``.#. ``EIGENSPARSE [Default: OFF]``: By default, Ceres will not use   Eigen's sparse Cholesky factorization. The is because this part of   the code is licensed under the ``LGPL`` and since ``Eigen`` is a   header only library, including this code will result in an ``LGPL``   licensed version of Ceres.   .. NOTE::      For good performance, use Eigen version 3.2.2 or later.#. ``GFLAGS [Default: ON]``: Turn this ``OFF`` to build Ceres without   ``gflags``. This will also prevent some of the example code from   building.#. ``MINIGLOG [Default: OFF]``: Ceres includes a stripped-down,   minimal implementation of ``glog`` which can optionally be used as   a substitute for ``glog``, thus removing ``glog`` as a required   dependency. Turn this ``ON`` to use this minimal ``glog``   implementation.#. ``SCHUR_SPECIALIZATIONS [Default: ON]``: If you are concerned about   binary size/compilation time over some small (10-20%) performance   gains in the ``SPARSE_SCHUR`` solver, you can disable some of the   template specializations by turning this ``OFF``.#. ``OPENMP [Default: ON]``: On certain platforms like Android,   multi-threading with ``OpenMP`` is not supported. Turn this ``OFF``   to disable multi-threading.#. ``CXX11 [Default: OFF]`` *Non-MSVC compilers only*.   Although Ceres does not currently use C++11, it does use   ``shared_ptr`` (required) and ``unordered_map`` (if available);   both of which existed in the previous iterations of what became the   C++11 standard: TR1 & C++0x.  As such, Ceres can compile on   pre-C++11 compilers, using the TR1/C++0x versions of ``shared_ptr``   & ``unordered_map``.   Note that when using GCC & Clang, compiling against the TR1/C++0x   versions: ``CXX11=OFF`` (the default) *does not* require   ``-std=c++11`` when compiling Ceres, *nor* does it require that any   client code using Ceres use ``-std=c++11``.  However, this will   cause compile errors if any client code that uses Ceres also uses   C++11 (mismatched versions of ``shared_ptr`` & ``unordered_map``).   Enabling this option: ``CXX11=ON`` forces Ceres to use the C++11   versions of ``shared_ptr`` & ``unordered_map`` if they are   available, and thus imposes the requirement that all client code   using Ceres also compile with ``-std=c++11``.  This requirement is   handled automatically through CMake target properties on the   exported Ceres target for CMake >= 2.8.12 (when it was introduced).   Thus, any client code which uses CMake will automatically be   compiled with ``-std=c++11``.  **On CMake versions < 2.8.12, you   are responsible for ensuring that any code which uses Ceres is   compiled with** ``-std=c++11``.   On OS X 10.9+, Clang will use the C++11 versions of ``shared_ptr``   & ``unordered_map`` without ``-std=c++11`` and so this option does   not change the versions detected, although enabling it *will*   require that client code compile with ``-std=c++11``.   The following table summarises the effects of the ``CXX11`` option:   ===================  ==========  ================  ======================================   OS                   CXX11       Detected Version  Ceres & client code require ``-std=c++11``   ===================  ==========  ================  ======================================   Linux (GCC & Clang)  OFF         tr1               **No**   Linux (GCC & Clang)  ON          std               **Yes**   OS X 10.9+           OFF         std               **No**   OS X 10.9+           ON          std               **Yes**   ===================  ==========  ================  ======================================   The ``CXX11`` option does does not exist when using MSVC, as there   any new C++ features available are enabled by default, and there is   no analogue of ``-std=c++11``.  It will however be available on   MinGW & CygWin, which can support ``-std=c++11``.#. ``BUILD_SHARED_LIBS [Default: OFF]``: By default Ceres is built as   a static library, turn this ``ON`` to instead build Ceres as a   shared library.#. ``EXPORT_BUILD_DIR [Default: OFF]``: By default Ceres is configured   solely for installation, and so must be installed in order for   clients to use it.  Turn this ``ON`` to export Ceres' build   directory location into the `user's local CMake package registry   <http://www.cmake.org/cmake/help/v3.2/manual/cmake-packages.7.html#user-package-registry>`_   where it will be detected **without requiring installation** in a   client project using CMake when `find_package(Ceres)   <http://www.cmake.org/cmake/help/v3.2/command/find_package.html>`_   is invoked.#. ``BUILD_DOCUMENTATION [Default: OFF]``: Use this to enable building   the documentation, requires `Sphinx <http://sphinx-doc.org/>`_ and   the `sphinx-better-theme   <https://pypi.python.org/pypi/sphinx-better-theme>`_ package   available from the Python package index. In addition, ``make   ceres_docs`` can be used to build only the documentation.#. ``MSVC_USE_STATIC_CRT [Default: OFF]`` *Windows Only*: By default   Ceres will use the Visual Studio default, *shared* C-Run Time (CRT)   library.  Turn this ``ON`` to use the *static* C-Run Time library   instead.#. ``LIB_SUFFIX [Default: "64" on non-Debian/Arch based 64-bit Linux,   otherwise: ""]``: The suffix to append to the library install   directory, built from:   ``${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}``.   The filesystem hierarchy standard recommends that 64-bit systems   install native libraries to lib64 rather than lib.  Most Linux   distributions follow this convention, but Debian and Arch based   distros do not.  Note that the only generally sensible values for   ``LIB_SUFFIX`` are "" and "64".   Although by default Ceres will auto-detect non-Debian/Arch based   64-bit Linux distributions and default ``LIB_SUFFIX`` to "64", this   can always be overridden by manually specifying LIB_SUFFIX using:   ``-DLIB_SUFFIX=<VALUE>`` when invoking CMake.Options controlling Ceres dependency locations----------------------------------------------Ceres uses the ``CMake`` `find_package<http://www.cmake.org/cmake/help/v3.2/command/find_package.html>`_function to find all of its dependencies using``Find<DEPENDENCY_NAME>.cmake`` scripts which are either included inCeres (for most dependencies) or are shipped as standard with``CMake`` (for ``LAPACK`` & ``BLAS``).  These scripts will search allof the "standard" install locations for various OSs for eachdependency.  However, particularly for Windows, they may fail to findthe library, in this case you will have to manually specify itsinstalled location.  The ``Find<DEPENDENCY_NAME>.cmake`` scriptsshipped with Ceres support two ways for you to do this:#. Set the *hints* variables specifying the *directories* to search in   preference, but in addition, to the search directories in the   ``Find<DEPENDENCY_NAME>.cmake`` script:   - ``<DEPENDENCY_NAME (CAPS)>_INCLUDE_DIR_HINTS``   - ``<DEPENDENCY_NAME (CAPS)>_LIBRARY_DIR_HINTS``   These variables should be set via ``-D<VAR>=<VALUE>``   ``CMake`` arguments as they are not visible in the GUI.#. Set the variables specifying the *explicit* include directory   and library file to use:   - ``<DEPENDENCY_NAME (CAPS)>_INCLUDE_DIR``   - ``<DEPENDENCY_NAME (CAPS)>_LIBRARY``   This bypasses *all* searching in the   ``Find<DEPENDENCY_NAME>.cmake`` script, but validation is still   performed.   These variables are available to set in the ``CMake`` GUI. They are   visible in the *Standard View* if the library has not been found   (but the current Ceres configuration requires it), but are always   visible in the *Advanced View*.  They can also be set directly via   ``-D<VAR>=<VALUE>`` arguments to ``CMake``.Building using custom BLAS & LAPACK installs----------------------------------------------If the standard find package scripts for ``BLAS`` & ``LAPACK`` whichship with ``CMake`` fail to find the desired libraries on your system,try setting ``CMAKE_LIBRARY_PATH`` to the path(s) to the directoriescontaining the ``BLAS`` & ``LAPACK`` libraries when invoking ``CMake``to build Ceres via ``-D<VAR>=<VALUE>``.  This should result in thelibraries being found for any common variant of each.If you are building on an exotic system, or setting``CMAKE_LIBRARY_PATH`` does not work, or is not appropriate for someother reason, one option would be to write your own custom versions of``FindBLAS.cmake`` & ``FindLAPACK.cmake`` specific to yourenvironment.  In this case you must set ``CMAKE_MODULE_PATH`` to thedirectory containing these custom scripts when invoking ``CMake`` tobuild Ceres and they will be used in preference to the defaultversions.  However, in order for this to work, your scripts mustprovide the full set of variables provided by the default scripts.Also, if you are building Ceres with ``SuiteSparse``, the versions of``BLAS`` & ``LAPACK`` used by ``SuiteSparse`` and Ceres should be thesame... _section-using-ceres:Using Ceres with CMake======================In order to use Ceres in client code with CMake using `find_package()<http://www.cmake.org/cmake/help/v3.2/command/find_package.html>`_then either:#. Ceres must have been installed with ``make install``.  If the    install location is non-standard (i.e. is not in CMake's default    search paths) then it will not be detected by default, see:    :ref:`section-local-installations`.    Note that if you are using a non-standard install location you    should consider exporting Ceres instead, as this will not require    any extra information to be provided in client code for Ceres to    be detected.#. Or Ceres' build directory must have been exported by enabling the    ``EXPORT_BUILD_DIR`` option when Ceres was configured.As an example of how to use Ceres, to compile `examples/helloworld.cc<https://ceres-solver.googlesource.com/ceres-solver/+/master/examples/helloworld.cc>`_in a separate standalone project, the following CMakeList.txt can beused:.. code-block:: cmake    cmake_minimum_required(VERSION 2.8)    project(helloworld)    find_package(Ceres REQUIRED)    include_directories(${CERES_INCLUDE_DIRS})    # helloworld    add_executable(helloworld helloworld.cc)    target_link_libraries(helloworld ${CERES_LIBRARIES})Irrespective of whether Ceres was installed or exported, if multipleversions are detected, set: ``Ceres_DIR`` to control which is used.If Ceres was installed ``Ceres_DIR`` should be the path to thedirectory containing the installed ``CeresConfig.cmake`` file(e.g. ``/usr/local/share/Ceres``).  If Ceres was exported, then``Ceres_DIR`` should be the path to the exported Ceres builddirectory.Specify Ceres components-------------------------------------You can specify particular Ceres components that you require (in orderfor Ceres to be reported as found) when invoking``find_package(Ceres)``.  This allows you to specify, for example,that you require a version of Ceres built with SuiteSparse support.By definition, if you do not specify any components when calling``find_package(Ceres)`` (the default) any version of Ceres detectedwill be reported as found, irrespective of which components it wasbuilt with.The Ceres components which can be specified are:#. ``LAPACK``: Ceres built using LAPACK (``LAPACK=ON``).#. ``SuiteSparse``: Ceres built with SuiteSparse (``SUITESPARSE=ON``).#. ``CXSparse``: Ceres built with CXSparse (``CXSPARSE=ON``).#. ``EigenSparse``: Ceres built with Eigen's sparse Cholesky factorization   (``EIGENSPARSE=ON``).#. ``SparseLinearAlgebraLibrary``: Ceres built with *at least one* sparse linear   algebra library.  This is equivalent to ``SuiteSparse`` **OR** ``CXSparse``   **OR** ``EigenSparse``.#. ``SchurSpecializations``: Ceres built with Schur specializations   (``SCHUR_SPECIALIZATIONS=ON``).#. ``OpenMP``: Ceres built with OpenMP (``OPENMP=ON``).#. ``C++11``: Ceres built with C++11 (``CXX11=ON``).To specify one/multiple Ceres components use the ``COMPONENTS`` argument to`find_package()<http://www.cmake.org/cmake/help/v3.2/command/find_package.html>`_ like so:.. code-block:: cmake    # Find a version of Ceres compiled with SuiteSparse & EigenSparse support.    #    # NOTE: This will report Ceres as **not** found if the detected version of    #            Ceres was not compiled with both SuiteSparse & EigenSparse.    #            Remember, if you have multiple versions of Ceres installed, you    #            can use Ceres_DIR to specify which should be used.    find_package(Ceres REQUIRED COMPONENTS SuiteSparse EigenSparse)Specify Ceres version---------------------Additionally, when CMake has found Ceres it can optionally check the packageversion, if it has been specified in the `find_package()<http://www.cmake.org/cmake/help/v3.2/command/find_package.html>`_call.  For example:.. code-block:: cmake    find_package(Ceres 1.2.3 REQUIRED).. _section-local-installations:Local installations-------------------If Ceres was installed in a non-standard path by specifying``-DCMAKE_INSTALL_PREFIX="/some/where/local"``, then the user shouldadd the **PATHS** option to the ``find_package()`` command, e.g.,.. code-block:: cmake   find_package(Ceres REQUIRED PATHS "/some/where/local/")Note that this can be used to have multiple versions of Ceresinstalled.  However, particularly if you have only a single version ofCeres which you want to use but do not wish to install to a systemlocation, you should consider exporting Ceres using the``EXPORT_BUILD_DIR`` option instead of a local install, as exportedversions of Ceres will be automatically detected by CMake,irrespective of their location.Understanding the CMake Package System----------------------------------------Although a full tutorial on CMake is outside the scope of this guide,here we cover some of the most common CMake misunderstandings thatcrop up when using Ceres.  For more detailed CMake usage, thefollowing references are very useful:- The `official CMake tutorial <http://www.cmake.org/cmake-tutorial/>`_   Provides a tour of the core features of CMake.- `ProjectConfig tutorial  <http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file>`_  and the `cmake-packages documentation  <http://www.cmake.org/cmake/help/git-master/manual/cmake-packages.7.html>`_   Cover how to write a ``ProjectConfig.cmake`` file, discussed below,   for your own project when installing or exporting it using CMake.   It also covers how these processes in conjunction with   ``find_package()`` are actually handled by CMake.  The   `ProjectConfig tutorial   <http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file>`_   is the older style, currently used by Ceres for compatibility with   older versions of CMake.  .. NOTE :: **Targets in CMake.**    All libraries and executables built using CMake are represented as    *targets* created using `add_library()    <http://www.cmake.org/cmake/help/v3.2/command/add_library.html>`_    and `add_executable()    <http://www.cmake.org/cmake/help/v3.2/command/add_executable.html>`_.    Targets encapsulate the rules and dependencies (which can be other    targets) required to build or link against an object.  This allows    CMake to implicitly manage dependency chains.  Thus it is    sufficient to tell CMake that a library target: ``B`` depends on a    previously declared library target ``A``, and CMake will    understand that this means that ``B`` also depends on all of the    public dependencies of ``A``.When a project like Ceres is installed using CMake, or its builddirectory is exported into the local CMake package registry (see:ref:`section-install-vs-export`), in addition to the public headersand compiled libraries, a set of CMake-specific project configurationfiles are also installed to: ``<INSTALL_ROOT>/share/Ceres`` (if Ceresis installed), or created in the build directory (if Ceres' builddirectory is exported).  When `find_package<http://www.cmake.org/cmake/help/v3.2/command/find_package.html>`_ isinvoked, CMake checks various standard install locations (including``/usr/local`` on Linux & UNIX systems), and the local CMake packageregistry for CMake configuration files for the project to be found(i.e. Ceres in the case of ``find_package(Ceres)``).  Specifically itlooks for:- ``<PROJECT_NAME>Config.cmake`` (or  ``<lower_case_project_name>-config.cmake``)   Which is written by the developers of the project, and is   configured with the selected options and installed locations when   the project is built and defines the CMake variables:   ``<PROJECT_NAME>_INCLUDE_DIRS`` & ``<PROJECT_NAME>_LIBRARIES``   which are used by the caller to import the project.The ``<PROJECT_NAME>Config.cmake`` typically includes a second fileinstalled to the same location:- ``<PROJECT_NAME>Targets.cmake``   Which is autogenerated by CMake as part of the install process and defines   **imported targets** for the project in the caller's CMake scope.An **imported target** contains the same information about a libraryas a CMake target that was declared locally in the current CMakeproject using ``add_library()``.  However, imported targets refer toobjects that have already been built by a different CMake project.Principally, an imported target contains the location of the compiledobject and all of its public dependencies required to link against it.Any locally declared target can depend on an imported target, andCMake will manage the dependency chain, just as if the imported targethad been declared locally by the current project.Crucially, just like any locally declared CMake target, an imported target isidentified by its **name** when adding it as a dependency to another target.Thus, if in a project using Ceres you had the following in your CMakeLists.txt:.. code-block:: cmake    find_package(Ceres REQUIRED)    message("CERES_LIBRARIES = ${CERES_LIBRARIES}")You would see the output: ``CERES_LIBRARIES = ceres``.  **However**,here ``ceres`` is an **imported target** created when``CeresTargets.cmake`` was read as part of ``find_package(CeresREQUIRED)``.  It does **not** refer (directly) to the compiled Cereslibrary: ``libceres.a/so/dylib/lib``.  This distinction is important,as depending on the options selected when it was built, Ceres can havepublic link dependencies which are encapsulated in the imported targetand automatically added to the link step when Ceres is added as adependency of another target by CMake.  In this case, linking onlyagainst ``libceres.a/so/dylib/lib`` without these other publicdependencies would result in a linker error.Note that this description applies both to projects that are**installed** using CMake, and to those whose **build directory isexported** using `export()<http://www.cmake.org/cmake/help/v3.2/command/export.html>`_ (insteadof `install()<http://www.cmake.org/cmake/help/v3.2/command/install.html>`_).  Ceressupports both installation and export of its build directory if the``EXPORT_BUILD_DIR`` option is enabled, see:ref:`section-customizing`... _section-install-vs-export:Installing a project with CMake vs Exporting its build directory^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^When a project is **installed**, the compiled libraries and headersare copied from the source & build directory to the install location,and it is these copied files that are used by any client code.  When aproject's build directory is **exported**, instead of copying thecompiled libraries and headers, CMake creates an entry for the projectin the `user's local CMake package registry<http://www.cmake.org/cmake/help/v3.2/manual/cmake-packages.7.html#user-package-registry>`_,``<USER_HOME>/.cmake/packages`` on Linux & OS X, which contains thepath to the project's build directory which will be checked by CMakeduring a call to ``find_package()``.  The effect of which is that anyclient code uses the compiled libraries and headers in the builddirectory directly, **thus not requiring the project to be installedto be used**.Installing / Exporting a project that uses Ceres--------------------------------------------------As described in `Understanding the CMake Package System`_, the contents ofthe ``CERES_LIBRARIES`` variable is the **name** of an imported target whichrepresents Ceres.  If you are installing / exporting your *own* project which*uses* Ceres, it is important to understand that:**Imported targets are not (re)exported when a project which imported them isexported**.Thus, when a project ``Foo`` which uses Ceres is exported, its list ofdependencies as seen by another project ``Bar`` which imports ``Foo``via: ``find_package(Foo REQUIRED)`` will contain: ``ceres``.  However,the definition of ``ceres`` as an imported target is **not(re)exported** when Foo is exported.  Hence, without any additionalsteps, when processing ``Bar``, ``ceres`` will not be defined as animported target.  Thus, when processing ``Bar``, CMake will assumethat ``ceres`` refers only to: ``libceres.a/so/dylib/lib`` (thecompiled Ceres library) directly if it is on the current list ofsearch paths.  In which case, no CMake errors will occur, but ``Bar``will not link properly, as it does not have the required public linkdependencies of Ceres, which are stored in the imported targetdefintion.The solution to this is for ``Foo`` (i.e., the project that usesCeres) to invoke ``find_package(Ceres)`` in ``FooConfig.cmake``, thus``ceres`` will be defined as an imported target when CMake processes``Bar``.  An example of the required modifications to``FooConfig.cmake`` are show below:.. code-block:: cmake    # Importing Ceres in FooConfig.cmake using CMake 2.8.x style.    #    # When configure_file() is used to generate FooConfig.cmake from    # FooConfig.cmake.in, @Ceres_DIR@ will be replaced with the current    # value of Ceres_DIR being used by Foo.  This should be passed as a hint    # when invoking find_package(Ceres) to ensure that the same install of    # Ceres is used as was used to build Foo.    set(CERES_DIR_HINTS @Ceres_DIR@)    # Forward the QUIET / REQUIRED options.    if (Foo_FIND_QUIETLY)       find_package(Ceres QUIET HINTS ${CERES_DIR_HINTS})    elseif (Foo_FIND_REQUIRED)       find_package(Ceres REQUIRED HINTS ${CERES_DIR_HINTS})    else ()       find_package(Ceres HINTS ${CERES_DIR_HINTS})    endif().. code-block:: cmake    # Importing Ceres in FooConfig.cmake using CMake 3.x style.    #    # In CMake v3.x, the find_dependency() macro exists to forward the REQUIRED    # / QUIET parameters to find_package() when searching for dependencies.    #    # Note that find_dependency() does not take a path hint, so if Ceres was    # installed in a non-standard location, that location must be added to    # CMake's search list before this call.    include(CMakeFindDependencyMacro)    find_dependency(Ceres)
 |