building.rst 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. .. _chapter-building:
  2. =======================
  3. Building & Installation
  4. =======================
  5. Getting the source code
  6. =======================
  7. .. _section-source:
  8. You can start with the `latest stable release
  9. <http://ceres-solver.org/ceres-solver-1.9.0.tar.gz>`_ . Or if you want
  10. the latest version, you can clone the git repository
  11. .. code-block:: bash
  12. git clone https://ceres-solver.googlesource.com/ceres-solver
  13. .. _section-dependencies:
  14. Dependencies
  15. ============
  16. Ceres relies on a number of open source libraries, some of which are
  17. optional. For details on customizing the build process, see
  18. :ref:`section-customizing` .
  19. - `Eigen <http://eigen.tuxfamily.org/index.php?title=Main_Page>`_ 3.0 or later.
  20. **Required**
  21. - `CMake <http://www.cmake.org>`_ 2.8.0 or later.
  22. **Required on all platforms except for Android.**
  23. - `Google Log <http://code.google.com/p/google-glog>`_ 0.3.1 or
  24. later. **Recommended**
  25. .. NOTE::
  26. Ceres has a minimal replacement of ``glog`` called ``miniglog``
  27. that can be enabled with the ``MINIGLOG`` build
  28. option. ``miniglog`` is needed on Android as ``glog`` currently
  29. does not build using the NDK. It can however be used on other
  30. platforms too.
  31. **We do not advise using** ``miniglog`` **on platforms other than
  32. Android due to the various performance and functionality
  33. compromises in** ``miniglog``.
  34. - `Google Flags <http://code.google.com/p/gflags>`_. Needed to build
  35. examples and tests.
  36. - `SuiteSparse
  37. <http://www.cise.ufl.edu/research/sparse/SuiteSparse/>`_. Needed for
  38. solving large sparse linear systems. **Optional; strongly recomended
  39. for large scale bundle adjustment**
  40. - `CXSparse <http://www.cise.ufl.edu/research/sparse/CXSparse/>`_.
  41. Similar to ``SuiteSparse`` but simpler and slower. CXSparse has
  42. no dependencies on ``LAPACK`` and ``BLAS``. This makes for a simpler
  43. build process and a smaller binary. **Optional**
  44. - `BLAS <http://www.netlib.org/blas/>`_ and `LAPACK
  45. <http://www.netlib.org/lapack/>`_ routines are needed by
  46. ``SuiteSparse``, and optionally used by Ceres directly for some
  47. operations.
  48. On ``UNIX`` OSes other than Mac OS X we recommend `ATLAS
  49. <http://math-atlas.sourceforge.net/>`_, which includes ``BLAS`` and
  50. ``LAPACK`` routines. It is also possible to use `OpenBLAS
  51. <https://github.com/xianyi/OpenBLAS>`_ . However, one needs to be
  52. careful to `turn off the threading
  53. <https://github.com/xianyi/OpenBLAS/wiki/faq#wiki-multi-threaded>`_
  54. inside ``OpenBLAS`` as it conflicts with use of threads in Ceres.
  55. MAC OS X ships with an optimized ``LAPACK`` and ``BLAS``
  56. implementation as part of the ``Accelerate`` framework. The Ceres
  57. build system will automatically detect and use it.
  58. For Windows things are much more complicated. `LAPACK For
  59. Windows <http://icl.cs.utk.edu/lapack-for-windows/lapack/>`_
  60. has detailed instructions..
  61. **Optional but required for** ``SuiteSparse``.
  62. .. _section-linux:
  63. Linux
  64. =====
  65. We will use `Ubuntu <http://www.ubuntu.com>`_ as our example linux
  66. distribution.
  67. .. NOTE::
  68. Up to at least Ubuntu 13.10, the SuiteSparse package in the official
  69. package repository (built from SuiteSparse v3.4.0) **cannot** be used
  70. to build Ceres as a *shared* library. Thus if you want to build
  71. Ceres as a shared library using SuiteSparse, you must perform a
  72. source install of SuiteSparse. It is recommended that you use the
  73. current version of SuiteSparse (4.2.1 at the time of writing).
  74. Start by installing all the dependencies.
  75. .. code-block:: bash
  76. # CMake
  77. sudo apt-get install cmake
  78. # gflags
  79. tar -xvzf gflags-2.0.tar.gz
  80. cd gflags-2.0
  81. ./configure --prefix=/usr/local
  82. make
  83. sudo make install.
  84. # google-glog must be configured to use the previously installed gflags
  85. tar -xvzf glog-0.3.2.tar.gz
  86. cd glog-0.3.2
  87. ./configure --with-gflags=/usr/local/
  88. make
  89. sudo make install
  90. # BLAS & LAPACK
  91. sudo apt-get install libatlas-base-dev
  92. # Eigen3
  93. sudo apt-get install libeigen3-dev
  94. # SuiteSparse and CXSparse (optional)
  95. # - If you want to build Ceres as a *static* library (the default)
  96. # you can use the SuiteSparse package in the main Ubuntu package
  97. # repository:
  98. sudo apt-get install libsuitesparse-dev
  99. # - However, if you want to build Ceres as a *shared* library, you must
  100. # perform a source install of SuiteSparse (and uninstall the Ubuntu
  101. # package if it is currently installed.
  102. We are now ready to build, test, and install Ceres.
  103. .. code-block:: bash
  104. tar zxf ceres-solver-1.9.0.tar.gz
  105. mkdir ceres-bin
  106. cd ceres-bin
  107. cmake ../ceres-solver-1.9.0
  108. make -j3
  109. make test
  110. make install
  111. You can also try running the command line bundling application with one of the
  112. included problems, which comes from the University of Washington's BAL
  113. dataset [Agarwal]_.
  114. .. code-block:: bash
  115. bin/simple_bundle_adjuster ../ceres-solver-1.9.0/data/problem-16-22106-pre.txt
  116. This runs Ceres for a maximum of 10 iterations using the
  117. ``DENSE_SCHUR`` linear solver. The output should look something like
  118. this.
  119. .. code-block:: bash
  120. iter cost cost_change |gradient| |step| tr_ratio tr_radius ls_iter iter_time total_time
  121. 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
  122. 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
  123. 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
  124. 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
  125. 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
  126. 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
  127. 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
  128. Ceres Solver v1.10.0 Solve Report
  129. ----------------------------------
  130. Original Reduced
  131. Parameter blocks 22122 22122
  132. Parameters 66462 66462
  133. Residual blocks 83718 83718
  134. Residual 167436 167436
  135. Minimizer TRUST_REGION
  136. Dense linear algebra library EIGEN
  137. Trust region strategy LEVENBERG_MARQUARDT
  138. Given Used
  139. Linear solver DENSE_SCHUR DENSE_SCHUR
  140. Threads 1 1
  141. Linear solver threads 1 1
  142. Linear solver ordering AUTOMATIC 22106, 16
  143. Cost:
  144. Initial 4.185660e+06
  145. Final 1.803390e+04
  146. Change 4.167626e+06
  147. Minimizer iterations 6
  148. Successful steps 6
  149. Unsuccessful steps 0
  150. Time (in seconds):
  151. Preprocessor 0.261
  152. Residual evaluation 0.082
  153. Jacobian evaluation 0.412
  154. Linear solver 0.442
  155. Minimizer 1.051
  156. Postprocessor 0.002
  157. Total 1.357
  158. Termination: CONVERGENCE (Function tolerance reached. |cost_change|/cost: 1.769766e-09 <= 1.000000e-06)
  159. .. section-osx:
  160. Mac OS X
  161. ========
  162. .. NOTE::
  163. Ceres will not compile using Xcode 4.5.x (Clang version 4.1) due to a bug in that version of
  164. Clang. If you are running Xcode 4.5.x, please update to Xcode >= 4.6.x before attempting to
  165. build Ceres.
  166. On OS X, we recommend using the `homebrew
  167. <http://mxcl.github.com/homebrew/>`_ package manager to install Ceres.
  168. .. code-block:: bash
  169. brew install ceres-solver
  170. will install the latest stable version along with all the required
  171. dependencies and
  172. .. code-block:: bash
  173. brew install ceres-solver --HEAD
  174. will install the latest version in the git repo.
  175. You can also install each of the dependencies by hand using `homebrew
  176. <http://mxcl.github.com/homebrew/>`_. There is no need to install
  177. ``BLAS`` or ``LAPACK`` separately as OS X ships with optimized
  178. ``BLAS`` and ``LAPACK`` routines as part of the `vecLib
  179. <https://developer.apple.com/library/mac/#documentation/Performance/Conceptual/vecLib/Reference/reference.html>`_
  180. framework.
  181. .. code-block:: bash
  182. # CMake
  183. brew install cmake
  184. # google-glog and gflags
  185. brew install glog
  186. # Eigen3
  187. brew install eigen
  188. # SuiteSparse and CXSparse
  189. brew install suite-sparse
  190. We are now ready to build, test, and install Ceres.
  191. .. code-block:: bash
  192. tar zxf ceres-solver-1.9.0.tar.gz
  193. mkdir ceres-bin
  194. cd ceres-bin
  195. cmake ../ceres-solver-1.9.0
  196. make -j3
  197. make test
  198. make install
  199. Like the Linux build, you should now be able to run
  200. ``bin/simple_bundle_adjuster``.
  201. .. _section-windows:
  202. Windows
  203. =======
  204. On Windows, we support building with Visual Studio 2010 or newer. Note
  205. that the Windows port is less featureful and less tested than the
  206. Linux or Mac OS X versions due to the lack of an officially supported
  207. way of building SuiteSparse and CXSparse. There are however a number
  208. of unofficial ways of building these libraries. Building on Windows
  209. also a bit more involved since there is no automated way to install
  210. dependencies.
  211. .. NOTE:: Using ``google-glog`` & ``miniglog`` with windows.h.
  212. The windows.h header if used with GDI (Graphics Device Interface)
  213. defines ``ERROR``, which conflicts with the definition of ``ERROR``
  214. as a LogSeverity level in ``google-glog`` and ``miniglog``. There
  215. are at least two possible fixes to this problem:
  216. #. Use ``google-glog`` and define ``GLOG_NO_ABBREVIATED_SEVERITIES``
  217. when building Ceres and your own project, as documented
  218. `here <http://google-glog.googlecode.com/svn/trunk/doc/glog.html>`__.
  219. Note that this fix will not work for ``miniglog``,
  220. but use of ``miniglog`` is strongly discouraged on any platform for which
  221. ``google-glog`` is available (which includes Windows).
  222. #. If you do not require GDI, then define ``NOGDI`` **before** including
  223. windows.h. This solution should work for both ``google-glog`` and
  224. ``miniglog`` and is documented for ``google-glog``
  225. `here <https://code.google.com/p/google-glog/issues/detail?id=33>`__.
  226. #. Make a toplevel directory for deps & build & src somewhere: ``ceres/``
  227. #. Get dependencies; unpack them as subdirectories in ``ceres/``
  228. (``ceres/eigen``, ``ceres/glog``, etc)
  229. #. ``Eigen`` 3.1 (needed on Windows; 3.0.x will not work). There is
  230. no need to build anything; just unpack the source tarball.
  231. #. ``google-glog`` Open up the Visual Studio solution and build it.
  232. #. ``gflags`` Open up the Visual Studio solution and build it.
  233. #. (Experimental) ``SuiteSparse`` Previously SuiteSparse was not available
  234. on Windows, recently it has become possible to build it on Windows using
  235. the `suitesparse-metis-for-windows <https://github.com/jlblancoc/suitesparse-metis-for-windows>`_
  236. project. If you wish to use ``SuiteSparse``, follow their instructions
  237. for obtaining and building it.
  238. #. (Experimental) ``CXSparse`` Previously CXSparse was not available on
  239. Windows, there are now several ports that enable it to be, including:
  240. `[1] <https://github.com/PetterS/CXSparse>`_ and
  241. `[2] <https://github.com/TheFrenchLeaf/CXSparse>`_. If you wish to use
  242. ``CXSparse``, follow their instructions for obtaining and building it.
  243. #. Unpack the Ceres tarball into ``ceres``. For the tarball, you
  244. should get a directory inside ``ceres`` similar to
  245. ``ceres-solver-1.3.0``. Alternately, checkout Ceres via ``git`` to
  246. get ``ceres-solver.git`` inside ``ceres``.
  247. #. Install ``CMake``,
  248. #. Make a dir ``ceres/ceres-bin`` (for an out-of-tree build)
  249. #. Run ``CMake``; select the ``ceres-solver-X.Y.Z`` or
  250. ``ceres-solver.git`` directory for the CMake file. Then select the
  251. ``ceres-bin`` for the build dir.
  252. #. Try running ``Configure``. It won't work. It'll show a bunch of options.
  253. You'll need to set:
  254. #. ``EIGEN_INCLUDE_DIR_HINTS``
  255. #. ``GLOG_INCLUDE_DIR_HINTS``
  256. #. ``GLOG_LIBRARY_DIR_HINTS``
  257. #. ``GFLAGS_INCLUDE_DIR_HINTS``
  258. #. ``GFLAGS_LIBRARY_DIR_HINTS``
  259. #. (Optional) ``SUITESPARSE_INCLUDE_DIR_HINTS``
  260. #. (Optional) ``SUITESPARSE_LIBRARY_DIR_HINTS``
  261. #. (Optional) ``CXSPARSE_INCLUDE_DIR_HINTS``
  262. #. (Optional) ``CXSPARSE_LIBRARY_DIR_HINTS``
  263. to the appropriate directories where you unpacked/built them. If any of
  264. the variables are not visible in the ``CMake`` GUI, create a new entry
  265. for them. We recommend using the ``<NAME>_(INCLUDE/LIBRARY)_DIR_HINTS``
  266. variables rather than setting the ``<NAME>_INCLUDE_DIR`` &
  267. ``<NAME>_LIBRARY`` variables directly to keep all of the validity
  268. checking, and to avoid having to specify the library files manually.
  269. #. You may have to tweak some more settings to generate a MSVC
  270. project. After each adjustment, try pressing Configure & Generate
  271. until it generates successfully.
  272. #. Open the solution and build it in MSVC
  273. To run the tests, select the ``RUN_TESTS`` target and hit **Build
  274. RUN_TESTS** from the build menu.
  275. Like the Linux build, you should now be able to run
  276. ``bin/simple_bundle_adjuster``.
  277. Notes:
  278. #. The default build is Debug; consider switching it to release mode.
  279. #. Currently ``system_test`` is not working properly.
  280. #. CMake puts the resulting test binaries in ``ceres-bin/examples/Debug``
  281. by default.
  282. #. The solvers supported on Windows are ``DENSE_QR``, ``DENSE_SCHUR``,
  283. ``CGNR``, and ``ITERATIVE_SCHUR``.
  284. #. We're looking for someone to work with upstream ``SuiteSparse`` to
  285. port their build system to something sane like ``CMake``, and get a
  286. fully supported Windows port.
  287. .. _section-android:
  288. Android
  289. =======
  290. Download the ``Android NDK`` version ``r9d`` or later. Run
  291. ``ndk-build`` from inside the ``jni`` directory. Use the
  292. ``libceres.a`` that gets created.
  293. .. _section-ios:
  294. iOS
  295. ===
  296. .. NOTE::
  297. You need iOS version 6.0 or higher to build Ceres Solver.
  298. To build Ceres for iOS, we need to force ``CMake`` to find the toolchains from
  299. the iOS SDK instead of using the standard ones. For example:
  300. .. code-block:: bash
  301. cmake ../ceres-solver \
  302. -DCMAKE_TOOLCHAIN_FILE=../ceres-solver/cmake/iOS.cmake \
  303. -DEIGEN_INCLUDE_DIR=/path/to/eigen/header \
  304. -DIOS_PLATFORM=<PLATFORM>
  305. ``PLATFORM`` can be one of ``OS``, ``SIMULATOR`` and ``SIMULATOR64``. You can
  306. build for ``OS`` (``armv7``, ``armv7s``, ``arm64``), ``SIMULATOR`` (``i386``) or
  307. ``SIMULATOR64`` (``x86_64``) separately and use ``LIPO`` to merge them into
  308. one static library. See ``cmake/iOS.cmake`` for more options.
  309. After building, you will get a ``libceres.a`` library, which you will need to
  310. add to your Xcode project.
  311. The default CMake configuration builds a bare bones version of Ceres
  312. Solver that only depends on Eigen (``MINIGLOG`` is compiled into Ceres if it is
  313. used), this should be sufficient for solving small to moderate sized problems
  314. (No ``SPARSE_SCHUR``, ``SPARSE_NORMAL_CHOLESKY`` linear solvers and no
  315. ``CLUSTER_JACOBI`` and ``CLUSTER_TRIDIAGONAL`` preconditioners).
  316. If you decide to use ``LAPACK`` and ``BLAS``, then you also need to add
  317. ``Accelerate.framework`` to your XCode project's linking dependency.
  318. .. _section-customizing:
  319. Customizing the build
  320. =====================
  321. It is possible to reduce the libraries needed to build Ceres and
  322. customize the build process by setting the appropriate options in
  323. ``CMake``. These options can either be set in the ``CMake`` GUI,
  324. or via ``-D<OPTION>=<ON/OFF>`` when running ``CMake`` from the
  325. command line. In general, you should only modify these options from
  326. their defaults if you know what you are doing.
  327. .. NOTE::
  328. If you are setting variables via ``-D<VARIABLE>=<VALUE>`` when calling
  329. ``CMake``, it is important to understand that this forcibly **overwrites** the
  330. variable ``<VARIABLE>`` in the ``CMake`` cache at the start of *every configure*.
  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. As such, it is generally easier not to pass values to ``CMake`` via ``-D``
  338. and instead interactively experiment with their values in the ``CMake`` GUI.
  339. If they are not present in the *Standard View*, toggle to the *Advanced View*
  340. with ``<t>``.
  341. Options controlling Ceres configuration
  342. ---------------------------------------
  343. #. ``LAPACK [Default: ON]``: By default Ceres will use ``LAPACK`` (&
  344. ``BLAS``) if they are found. Turn this ``OFF`` to build Ceres
  345. without ``LAPACK``. Turning this ``OFF`` also disables
  346. ``SUITESPARSE`` as it depends on ``LAPACK``.
  347. #. ``SUITESPARSE [Default: ON]``: By default, Ceres will link to
  348. ``SuiteSparse`` if it and all of its dependencies are present. Turn
  349. this ``OFF`` to build Ceres without ``SuiteSparse``. Note that
  350. ``LAPACK`` must be ``ON`` in order to build with ``SuiteSparse``.
  351. #. ``CXSPARSE [Default: ON]``: By default, Ceres will link to
  352. ``CXSparse`` if all its dependencies are present. Turn this ``OFF``
  353. to build Ceres without ``CXSparse``.
  354. #. ``GFLAGS [Default: ON]``: Turn this ``OFF`` to build Ceres without
  355. ``gflags``. This will also prevent some of the example code from
  356. building.
  357. #. ``MINIGLOG [Default: OFF]``: Ceres includes a stripped-down,
  358. minimal implementation of ``glog`` which can optionally be used as
  359. a substitute for ``glog``, thus removing ``glog`` as a required
  360. dependency. Turn this ``ON`` to use this minimal ``glog``
  361. implementation.
  362. #. ``SCHUR_SPECIALIZATIONS [Default: ON]``: If you are concerned about
  363. binary size/compilation time over some small (10-20%) performance
  364. gains in the ``SPARSE_SCHUR`` solver, you can disable some of the
  365. template specializations by turning this ``OFF``.
  366. #. ``OPENMP [Default: ON]``: On certain platforms like Android,
  367. multi-threading with ``OpenMP`` is not supported. Turn this ``OFF``
  368. to disable multithreading.
  369. #. ``BUILD_SHARED_LIBS [Default: OFF]``: By default Ceres is built as
  370. a static library, turn this ``ON`` to instead build Ceres as a
  371. shared library.
  372. #. ``BUILD_DOCUMENTATION [Default: OFF]``: Use this to enable building
  373. the documentation, requires `Sphinx <http://sphinx-doc.org/>`_ and the
  374. `sphinx_rtd_theme <https://pypi.python.org/pypi/sphinx_rtd_theme>`_
  375. package available from the Python package index. In addition,
  376. ``make ceres_docs`` can be used to build only the documentation.
  377. #. ``MSVC_USE_STATIC_CRT [Default: OFF]`` *Windows Only*: By default
  378. Ceres will use the Visual Studio default, *shared* C-Run Time (CRT) library.
  379. Turn this ``ON`` to use the *static* C-Run Time library instead.
  380. Options controlling Ceres dependency locations
  381. ----------------------------------------------
  382. Ceres uses the ``CMake``
  383. `find_package <http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:find_package>`_
  384. function to find all of its dependencies using
  385. ``Find<DEPENDENCY_NAME>.cmake`` scripts which are either included in Ceres
  386. (for most dependencies) or are shipped as standard with ``CMake``
  387. (for ``LAPACK`` & ``BLAS``). These scripts will search all of the "standard"
  388. install locations for various OSs for each dependency. However, particularly
  389. for Windows, they may fail to find the library, in this case you will have to
  390. manually specify its installed location. The ``Find<DEPENDENCY_NAME>.cmake``
  391. scripts shipped with Ceres support two ways for you to do this:
  392. #. Set the *hints* variables specifying the *directories* to search in
  393. preference, but in addition, to the search directories in the
  394. ``Find<DEPENDENCY_NAME>.cmake`` script:
  395. - ``<DEPENDENCY_NAME (CAPS)>_INCLUDE_DIR_HINTS``
  396. - ``<DEPENDENCY_NAME (CAPS)>_LIBRARY_DIR_HINTS``
  397. These variables should be set via ``-D<VAR>=<VALUE>``
  398. ``CMake`` arguments as they are not visible in the GUI.
  399. #. Set the variables specifying the *explicit* include directory
  400. and library file to use:
  401. - ``<DEPENDENCY_NAME (CAPS)>_INCLUDE_DIR``
  402. - ``<DEPENDENCY_NAME (CAPS)>_LIBRARY``
  403. This bypasses *all* searching in the
  404. ``Find<DEPENDENCY_NAME>.cmake`` script, but validation is still
  405. performed.
  406. These variables are available to set in the ``CMake`` GUI. They
  407. are visible in the *Standard View* if the library has not been
  408. found (but the current Ceres configuration requires it), but
  409. are always visible in the *Advanced View*. They can also be
  410. set directly via ``-D<VAR>=<VALUE>`` arguments to ``CMake``.
  411. Building using custom BLAS & LAPACK installs
  412. ----------------------------------------------
  413. If the standard find package scripts for ``BLAS`` & ``LAPACK`` which ship with
  414. ``CMake`` fail to find the desired libraries on your system, try setting
  415. ``CMAKE_LIBRARY_PATH`` to the path(s) to the directories containing the
  416. ``BLAS`` & ``LAPACK`` libraries when invoking ``CMake`` to build Ceres via
  417. ``-D<VAR>=<VALUE>``. This should result in the libraries being found for any
  418. common variant of each.
  419. If you are building on an exotic system, or setting ``CMAKE_LIBRARY_PATH``
  420. does not work, or is not appropriate for some other reason, one option would be
  421. to write your own custom versions of ``FindBLAS.cmake`` &
  422. ``FindLAPACK.cmake`` specific to your environment. In this case you must set
  423. ``CMAKE_MODULE_PATH`` to the directory containing these custom scripts when
  424. invoking ``CMake`` to build Ceres and they will be used in preference to the
  425. default versions. However, in order for this to work, your scripts must provide
  426. the full set of variables provided by the default scripts. Also, if you are
  427. building Ceres with ``SuiteSparse``, the versions of ``BLAS`` & ``LAPACK``
  428. used by ``SuiteSparse`` and Ceres should be the same.
  429. .. _section-using-ceres:
  430. Using Ceres with CMake
  431. ======================
  432. Once the library is installed with ``make install``, it is possible to
  433. use CMake with `FIND_PACKAGE()
  434. <http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_package>`_
  435. in order to compile **user code** against Ceres. For example, for
  436. `examples/helloworld.cc
  437. <https://ceres-solver.googlesource.com/ceres-solver/+/master/examples/helloworld.cc>`_
  438. the following CMakeList.txt can be used:
  439. .. code-block:: cmake
  440. CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
  441. PROJECT(helloworld)
  442. FIND_PACKAGE(Ceres REQUIRED)
  443. INCLUDE_DIRECTORIES(${CERES_INCLUDE_DIRS})
  444. # helloworld
  445. ADD_EXECUTABLE(helloworld helloworld.cc)
  446. TARGET_LINK_LIBRARIES(helloworld ${CERES_LIBRARIES})
  447. Specify Ceres version
  448. ---------------------
  449. Additionally, when CMake has found Ceres it can check the package
  450. version, if it has been specified in the `FIND_PACKAGE()
  451. <http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_package>`_
  452. call. For example:
  453. .. code-block:: cmake
  454. FIND_PACKAGE(Ceres 1.2.3 REQUIRED)
  455. The version is an optional argument.
  456. Local installations
  457. -------------------
  458. If Ceres was installed in a non-standard path by specifying
  459. -DCMAKE_INSTALL_PREFIX="/some/where/local", then the user should add
  460. the **PATHS** option to the ``FIND_PACKAGE()`` command. e.g.,
  461. .. code-block:: cmake
  462. FIND_PACKAGE(Ceres REQUIRED PATHS "/some/where/local/")
  463. Note that this can be used to have multiple versions of Ceres
  464. installed.