Home | History | Annotate | Download | only in ceres-solver
      1 # Ceres Solver - A fast non-linear least squares minimizer
      2 # Copyright 2010, 2011, 2012 Google Inc. All rights reserved.
      3 # http://code.google.com/p/ceres-solver/
      4 #
      5 # Redistribution and use in source and binary forms, with or without
      6 # modification, are permitted provided that the following conditions are met:
      7 #
      8 # * Redistributions of source code must retain the above copyright notice,
      9 #   this list of conditions and the following disclaimer.
     10 # * Redistributions in binary form must reproduce the above copyright notice,
     11 #   this list of conditions and the following disclaimer in the documentation
     12 #   and/or other materials provided with the distribution.
     13 # * Neither the name of Google Inc. nor the names of its contributors may be
     14 #   used to endorse or promote products derived from this software without
     15 #   specific prior written permission.
     16 #
     17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27 # POSSIBILITY OF SUCH DAMAGE.
     28 #
     29 # Author: keir (a] google.com (Keir Mierle)
     30 
     31 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
     32 CMAKE_POLICY(VERSION 2.8)
     33 
     34 IF (COMMAND cmake_policy)
     35   CMAKE_POLICY(SET CMP0003 NEW)
     36 ENDIF (COMMAND cmake_policy)
     37 
     38 PROJECT(CERES C CXX)
     39 
     40 # Set up the git hook to make Gerrit Change-Id: lines in commit messages.
     41 SET (LOCAL_GIT_DIRECTORY)
     42 IF (EXISTS ${CMAKE_SOURCE_DIR}/.git)
     43   # .git directory can be found on Unix based system, or on Windows with
     44   # Git Bash (shipped with msysgit)
     45   SET (LOCAL_GIT_DIRECTORY ${CMAKE_SOURCE_DIR}/.git)
     46 ELSE (EXISTS ${CMAKE_SOURCE_DIR}/.git)
     47   # TODO(keir) Add proper Windows support
     48 ENDIF (EXISTS ${CMAKE_SOURCE_DIR}/.git)
     49 
     50 IF (EXISTS ${LOCAL_GIT_DIRECTORY})
     51   IF (NOT EXISTS ${LOCAL_GIT_DIRECTORY}/hooks/commit-msg)
     52     # Download the hook only if it is not already present
     53     FILE(DOWNLOAD https://ceres-solver-review.googlesource.com/tools/hooks/commit-msg
     54          ${CMAKE_BINARY_DIR}/commit-msg)
     55 
     56     # Make the downloaded file executable, since it is not by default.
     57     FILE(COPY ${CMAKE_BINARY_DIR}/commit-msg
     58          DESTINATION ${LOCAL_GIT_DIRECTORY}/hooks/
     59          FILE_PERMISSIONS
     60            OWNER_READ OWNER_WRITE OWNER_EXECUTE
     61            GROUP_READ GROUP_WRITE GROUP_EXECUTE
     62            WORLD_READ WORLD_EXECUTE)
     63   ENDIF (NOT EXISTS ${LOCAL_GIT_DIRECTORY}/hooks/commit-msg)
     64 ENDIF (EXISTS ${LOCAL_GIT_DIRECTORY})
     65 
     66 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
     67 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
     68 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
     69 
     70 # Important: Always bump the second number (e.g. 1.3.x to 1.4.0) for any
     71 # release that changes the ABI. The ABI changes for almost any modification to
     72 # include/ceres (e.g. the public API). If you are unsure about whether
     73 # something is an ABI change, please ask on the list.
     74 #
     75 # For versions without ABI changes, bump the smallest number in CERES_VERSION,
     76 # but leave the CERES_ABI_VERSION unchanged.
     77 SET(CERES_VERSION_MAJOR 1)
     78 SET(CERES_VERSION_MINOR 7)
     79 SET(CERES_VERSION_PATCH 0)
     80 SET(CERES_VERSION
     81     ${CERES_VERSION_MAJOR}.${CERES_VERSION_MINOR}.${CERES_VERSION_PATCH})
     82 SET(CERES_ABI_VERSION 1.7.0)
     83 
     84 ENABLE_TESTING()
     85 
     86 OPTION(MINIGLOG "Use a stripped down version of glog" OFF)
     87 OPTION(GFLAGS "Enable Google Flags." ON)
     88 # Template specializations for the Schur complement based solvers. If
     89 # compile time, binary size or compiler performance is an issue, you
     90 # may consider disabling this.
     91 OPTION(SCHUR_SPECIALIZATIONS "Enable fixed-size schur specializations." ON)
     92 OPTION(CUSTOM_BLAS
     93        "Use handcoded BLAS routines (usually faster) instead of Eigen."
     94        ON)
     95 # Multithreading using OpenMP
     96 OPTION(OPENMP "Enable threaded solving in Ceres (requires OpenMP)" ON)
     97 # TODO(sameeragarwal): Replace this with a positive option instead?
     98 OPTION(DISABLE_TR1
     99        "Don't use TR1. This replaces some hash tables with sets. Slower."
    100        OFF)
    101 # Line search minimizer is useful for large scale problems or when
    102 # sparse linear algebra libraries are not available. If compile time,
    103 # binary size or compiler performance is an issue, consider disabling
    104 # this.
    105 OPTION(LINE_SEARCH_MINIMIZER "Enable the line search minimizer." ON)
    106 OPTION(BUILD_TESTING "Enable tests" ON)
    107 OPTION(BUILD_DOCUMENTATION "Build User's Guide (html)" OFF)
    108 OPTION(BUILD_EXAMPLES "Build examples" ON)
    109 
    110 # Default locations to search for on various platforms.
    111 
    112 # Libraries
    113 LIST(APPEND CMAKE_LIBRARY_PATH /opt/local/lib)
    114 LIST(APPEND CMAKE_LIBRARY_PATH /opt/local/lib/ufsparse) # Mac OS X
    115 LIST(APPEND CMAKE_LIBRARY_PATH /usr/lib)
    116 LIST(APPEND CMAKE_LIBRARY_PATH /usr/lib/atlas)
    117 LIST(APPEND CMAKE_LIBRARY_PATH /usr/lib/suitesparse) # Ubuntu
    118 LIST(APPEND CMAKE_LIBRARY_PATH /usr/lib64/atlas)
    119 LIST(APPEND CMAKE_LIBRARY_PATH /usr/local/homebrew/lib) # Mac OS X
    120 LIST(APPEND CMAKE_LIBRARY_PATH /usr/local/lib)
    121 LIST(APPEND CMAKE_LIBRARY_PATH /usr/local/lib/suitesparse)
    122 
    123 # Headers
    124 LIST(APPEND CMAKE_INCLUDE_PATH /opt/local/include)
    125 LIST(APPEND CMAKE_INCLUDE_PATH /opt/local/include/ufsparse) # Mac OS X
    126 LIST(APPEND CMAKE_INCLUDE_PATH /opt/local/var/macports/software/eigen3/opt/local/include/eigen3) # Mac OS X
    127 LIST(APPEND CMAKE_INCLUDE_PATH /usr/include)
    128 LIST(APPEND CMAKE_INCLUDE_PATH /usr/include/eigen3) # Ubuntu 10.04's default location.
    129 LIST(APPEND CMAKE_INCLUDE_PATH /usr/include/suitesparse) # Ubuntu
    130 LIST(APPEND CMAKE_INCLUDE_PATH /usr/local/homebrew/include) # Mac OS X
    131 LIST(APPEND CMAKE_INCLUDE_PATH /usr/local/homebrew/include/eigen3)  # Mac OS X
    132 LIST(APPEND CMAKE_INCLUDE_PATH /usr/local/include)
    133 LIST(APPEND CMAKE_INCLUDE_PATH /usr/local/include/eigen3)
    134 LIST(APPEND CMAKE_INCLUDE_PATH /usr/local/include/suitesparse)
    135 
    136 # Eigen
    137 FIND_PATH(EIGEN_INCLUDE NAMES Eigen/Core)
    138 IF (NOT EXISTS ${EIGEN_INCLUDE})
    139   MESSAGE(FATAL_ERROR "Can't find Eigen. Try passing -DEIGEN_INCLUDE=...")
    140 ELSE (NOT EXISTS ${EIGEN_INCLUDE})
    141   MESSAGE("-- Found Eigen 3.x: ${EIGEN_INCLUDE}")
    142 ENDIF (NOT EXISTS ${EIGEN_INCLUDE})
    143 
    144 SET(BLAS_AND_LAPACK_FOUND TRUE)
    145 IF ((NOT DEFINED LAPACK) OR (DEFINED LAPACK AND LAPACK))
    146   FIND_PACKAGE(LAPACK)
    147   IF (LAPACK_FOUND)
    148     MESSAGE("-- Found LAPACK library: ${LAPACK_LIBRARIES}")
    149   ELSE (LAPACK_FOUND)
    150     MESSAGE("-- Did not find LAPACK library")
    151     SET(BLAS_AND_LAPACK_FOUND FALSE)
    152   ENDIF (LAPACK_FOUND)
    153 
    154   FIND_PACKAGE(BLAS)
    155   IF (BLAS_FOUND)
    156     MESSAGE("-- Found BLAS library: ${BLAS_LIBRARIES}")
    157   ELSE (BLAS_FOUND)
    158     MESSAGE("-- Did not find BLAS library")
    159     SET(BLAS_AND_BLAS_FOUND FALSE)
    160   ENDIF (BLAS_FOUND)
    161 
    162 ELSE ((NOT DEFINED LAPACK) OR (DEFINED LAPACK AND LAPACK))
    163   SET(BLAS_AND_LAPACK_FOUND FALSE)
    164 ENDIF ((NOT DEFINED LAPACK) OR (DEFINED LAPACK AND LAPACK))
    165 
    166 IF (NOT BLAS_AND_LAPACK_FOUND)
    167   ADD_DEFINITIONS(-DCERES_NO_LAPACK)
    168 ENDIF (NOT BLAS_AND_LAPACK_FOUND)
    169 
    170 IF ((NOT DEFINED SUITESPARSE) OR (DEFINED SUITESPARSE AND SUITESPARSE))
    171 # Check for SuiteSparse dependencies
    172 
    173 SET(AMD_FOUND TRUE)
    174 FIND_LIBRARY(AMD_LIB NAMES amd)
    175 IF (EXISTS ${AMD_LIB})
    176   MESSAGE("-- Found AMD library: ${AMD_LIB}")
    177 ELSE (EXISTS ${AMD_LIB})
    178   MESSAGE("-- Did not find AMD library")
    179   SET(AMD_FOUND FALSE)
    180 ENDIF (EXISTS ${AMD_LIB})
    181 
    182 FIND_PATH(AMD_INCLUDE NAMES amd.h)
    183 IF (EXISTS ${AMD_INCLUDE})
    184   MESSAGE("-- Found AMD header in: ${AMD_INCLUDE}")
    185 ELSE (EXISTS ${AMD_INCLUDE})
    186   MESSAGE("-- Did not find AMD header")
    187   SET(AMD_FOUND FALSE)
    188 ENDIF (EXISTS ${AMD_INCLUDE})
    189 
    190 SET(CAMD_FOUND TRUE)
    191 FIND_LIBRARY(CAMD_LIB NAMES camd)
    192 IF (EXISTS ${CAMD_LIB})
    193   MESSAGE("-- Found CAMD library: ${CAMD_LIB}")
    194 ELSE (EXISTS ${CAMD_LIB})
    195   MESSAGE("-- Did not find CAMD library")
    196   SET(CAMD_FOUND FALSE)
    197 ENDIF (EXISTS ${CAMD_LIB})
    198 
    199 FIND_PATH(CAMD_INCLUDE NAMES camd.h)
    200 IF (EXISTS ${CAMD_INCLUDE})
    201   MESSAGE("-- Found CAMD header in: ${CAMD_INCLUDE}")
    202 ELSE (EXISTS ${CAMD_INCLUDE})
    203   MESSAGE("-- Did not find CAMD header")
    204   SET(CAMD_FOUND FALSE)
    205 ENDIF (EXISTS ${CAMD_INCLUDE})
    206 
    207 SET(COLAMD_FOUND TRUE)
    208 FIND_LIBRARY(COLAMD_LIB NAMES colamd)
    209 IF (EXISTS ${COLAMD_LIB})
    210   MESSAGE("-- Found COLAMD library: ${COLAMD_LIB}")
    211 ELSE (EXISTS ${COLAMD_LIB})
    212   MESSAGE("-- Did not find COLAMD library")
    213   SET(COLAMD_FOUND FALSE)
    214 ENDIF (EXISTS ${COLAMD_LIB})
    215 
    216 FIND_PATH(COLAMD_INCLUDE NAMES colamd.h)
    217 IF (EXISTS ${COLAMD_INCLUDE})
    218   MESSAGE("-- Found COLAMD header in: ${COLAMD_INCLUDE}")
    219 ELSE (EXISTS ${COLAMD_INCLUDE})
    220   MESSAGE("-- Did not find COLAMD header")
    221   SET(COLAMD_FOUND FALSE)
    222 ENDIF (EXISTS ${COLAMD_INCLUDE})
    223 
    224 SET(CCOLAMD_FOUND TRUE)
    225 FIND_LIBRARY(CCOLAMD_LIB NAMES ccolamd)
    226 IF (EXISTS ${CCOLAMD_LIB})
    227   MESSAGE("-- Found CCOLAMD library: ${CCOLAMD_LIB}")
    228 ELSE (EXISTS ${CCOLAMD_LIB})
    229   MESSAGE("-- Did not find CCOLAMD library")
    230   SET(CCOLAMD_FOUND FALSE)
    231 ENDIF (EXISTS ${CCOLAMD_LIB})
    232 
    233 FIND_PATH(CCOLAMD_INCLUDE NAMES ccolamd.h)
    234 IF (EXISTS ${CCOLAMD_INCLUDE})
    235   MESSAGE("-- Found CCOLAMD header in: ${CCOLAMD_INCLUDE}")
    236 ELSE (EXISTS ${CCOLAMD_INCLUDE})
    237   MESSAGE("-- Did not find CCOLAMD header")
    238   SET(CCOLAMD_FOUND FALSE)
    239 ENDIF (EXISTS ${CCOLAMD_INCLUDE})
    240 
    241 SET(CHOLMOD_FOUND TRUE)
    242 FIND_LIBRARY(CHOLMOD_LIB NAMES cholmod)
    243 IF (EXISTS ${CHOLMOD_LIB})
    244   MESSAGE("-- Found CHOLMOD library: ${CHOLMOD_LIB}")
    245 ELSE (EXISTS ${CHOLMOD_LIB})
    246   MESSAGE("-- Did not find CHOLMOD library")
    247   SET(CHOLMOD_FOUND FALSE)
    248 ENDIF (EXISTS ${CHOLMOD_LIB})
    249 
    250 FIND_PATH(CHOLMOD_INCLUDE NAMES cholmod.h)
    251 IF (EXISTS ${CHOLMOD_INCLUDE})
    252   MESSAGE("-- Found CHOLMOD header in: ${CHOLMOD_INCLUDE}")
    253 ELSE (EXISTS ${CHOLMOD_INCLUDE})
    254   MESSAGE("-- Did not find CHOLMOD header")
    255   SET(CHOLMOD_FOUND FALSE)
    256 ENDIF (EXISTS ${CHOLMOD_INCLUDE})
    257 
    258 SET(SUITESPARSEQR_FOUND TRUE)
    259 FIND_LIBRARY(SUITESPARSEQR_LIB NAMES spqr)
    260 IF (EXISTS ${SUITESPARSEQR_LIB})
    261   MESSAGE("-- Found SUITESPARSEQR library: ${SUITESPARSEQR_LIB}")
    262 ELSE (EXISTS ${SUITESPARSEQR_LIB})
    263   MESSAGE("-- Did not find SUITESPARSEQR library")
    264   SET(SUITESPARSEQR_FOUND FALSE)
    265 ENDIF (EXISTS ${SUITESPARSEQR_LIB})
    266 
    267 FIND_PATH(SUITESPARSEQR_INCLUDE NAMES SuiteSparseQR.hpp)
    268 IF (EXISTS ${SUITESPARSEQR_INCLUDE})
    269   MESSAGE("-- Found SUITESPARSEQR header in: ${SUITESPARSEQR_INCLUDE}")
    270 ELSE (EXISTS ${SUITESPARSEQR_INCLUDE})
    271   MESSAGE("-- Did not find SUITESPARSEQR header")
    272   SET(SUITESPARSEQR_FOUND FALSE)
    273 ENDIF (EXISTS ${SUITESPARSEQR_INCLUDE})
    274 
    275 # If SuiteSparse version is >= 4 then SuiteSparse_config is required.
    276 # For SuiteSparse 3, UFconfig.h is required.
    277 SET(SUITESPARSE_CONFIG_FOUND TRUE)
    278 SET(UFCONFIG_FOUND TRUE)
    279 
    280 FIND_LIBRARY(SUITESPARSE_CONFIG_LIB NAMES suitesparseconfig)
    281 IF (EXISTS ${SUITESPARSE_CONFIG_LIB})
    282   MESSAGE("-- Found SuiteSparse_config library: ${SUITESPARSE_CONFIG_LIB}")
    283 ELSE (EXISTS ${SUITESPARSE_CONFIG_LIB})
    284   MESSAGE("-- Did not find SuiteSparse_config library")
    285 ENDIF (EXISTS ${SUITESPARSE_CONFIG_LIB})
    286 
    287 FIND_PATH(SUITESPARSE_CONFIG_INCLUDE NAMES SuiteSparse_config.h)
    288 IF (EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
    289   MESSAGE("-- Found SuiteSparse_config header in: ${SUITESPARSE_CONFIG_INCLUDE}")
    290   SET(UFCONFIG_FOUND FALSE)
    291 ELSE (EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
    292   MESSAGE("-- Did not find SuiteSparse_config header")
    293 ENDIF (EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
    294 
    295 IF (NOT EXISTS ${SUITESPARSE_CONFIG_LIB} OR
    296     NOT EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
    297   SET(SUITESPARSE_CONFIG_FOUND FALSE)
    298   FIND_PATH(UFCONFIG_INCLUDE NAMES UFconfig.h)
    299   IF (EXISTS ${UFCONFIG_INCLUDE})
    300     MESSAGE("-- Found UFconfig header in: ${UFCONFIG_INCLUDE}")
    301   ELSE (EXISTS ${UFCONFIG_INCLUDE})
    302     MESSAGE("-- Did not find UFconfig header")
    303     SET(UFCONFIG_FOUND FALSE)
    304   ENDIF (EXISTS ${UFCONFIG_INCLUDE})
    305 ENDIF (NOT EXISTS ${SUITESPARSE_CONFIG_LIB} OR
    306        NOT EXISTS ${SUITESPARSE_CONFIG_INCLUDE})
    307 
    308 FIND_LIBRARY(METIS_LIB NAMES metis)
    309 IF (EXISTS ${METIS_LIB})
    310   MESSAGE("-- Found METIS library: ${METIS_LIB}")
    311 ELSE (EXISTS ${METIS_LIB})
    312   MESSAGE("-- Did not find METIS library")
    313 ENDIF (EXISTS ${METIS_LIB})
    314 
    315 # SuiteSparseQR may be compiled with Intel Threading Building Blocks.
    316 SET(TBB_FOUND TRUE)
    317 FIND_LIBRARY(TBB_LIB NAMES tbb)
    318 IF (EXISTS ${TBB_LIB})
    319   MESSAGE("-- Found TBB library: ${TBB_LIB}")
    320 ELSE (EXISTS ${TBB_LIB})
    321   MESSAGE("-- Did not find TBB library")
    322   SET(TBB_FOUND FALSE)
    323 ENDIF (EXISTS ${TBB_LIB})
    324 
    325 FIND_LIBRARY(TBB_MALLOC_LIB NAMES tbbmalloc)
    326 IF (EXISTS ${TBB_MALLOC_LIB})
    327   MESSAGE("-- Found TBB Malloc library: ${TBB_MALLOC_LIB}")
    328 ELSE (EXISTS ${TBB_MALLOC_LIB})
    329   MESSAGE("-- Did not find TBB library")
    330   SET(TBB_FOUND FALSE)
    331 ENDIF (EXISTS ${TBB_MALLOC_LIB})
    332 
    333 # We don't use SET(SUITESPARSE_FOUND ${AMD_FOUND} ...) in order to be
    334 # able to check whether SuiteSparse is available without expanding
    335 # SUITESPARSE_FOUND with ${}. This means further checks could be:
    336 #
    337 #   IF (SUITESPARSE_FOUND)
    338 #
    339 # and not:
    340 #
    341 #   IF (${SUITESPARSE_FOUND})
    342 #
    343 IF (${AMD_FOUND} AND
    344     ${CAMD_FOUND} AND
    345     ${COLAMD_FOUND} AND
    346     ${CCOLAMD_FOUND} AND
    347     ${CHOLMOD_FOUND} AND
    348     (${SUITESPARSE_CONFIG_FOUND} OR ${UFCONFIG_FOUND}) AND
    349     ${BLAS_AND_LAPACK_FOUND})
    350   SET(SUITESPARSE_FOUND TRUE)
    351 ELSE ()
    352   SET(SUITESPARSE_FOUND FALSE)
    353 ENDIF ()
    354 
    355 ENDIF ((NOT DEFINED SUITESPARSE) OR (DEFINED SUITESPARSE AND SUITESPARSE))
    356 # By default, if all of SuiteSparse's dependencies are found, Ceres is
    357 # built with SuiteSparse support. -DSUITESPARSE=ON/OFF can be used to
    358 # enable/disable SuiteSparse explicitly.
    359 IF (DEFINED SUITESPARSE)
    360   IF (SUITESPARSE)
    361     IF (NOT SUITESPARSE_FOUND)
    362       MESSAGE(FATAL_ERROR "One or more of SuiteSparse's dependencies was not found")
    363     ENDIF (NOT SUITESPARSE_FOUND)
    364   ELSE (SUITESPARSE)
    365     ADD_DEFINITIONS(-DCERES_NO_SUITESPARSE)
    366   ENDIF (SUITESPARSE)
    367 ELSE (DEFINED SUITESPARSE)
    368   IF (SUITESPARSE_FOUND)
    369     MESSAGE("-- Found all SuiteSparse dependencies. Building with SuiteSparse")
    370     SET(SUITESPARSE ON)
    371   ELSE (SUITESPARSE_FOUND)
    372     MESSAGE("-- Did not find all SuiteSparse dependencies. Building without SuiteSparse")
    373     SET(SUITESPARSE OFF)
    374     ADD_DEFINITIONS(-DCERES_NO_SUITESPARSE)
    375   ENDIF (SUITESPARSE_FOUND)
    376 ENDIF (DEFINED SUITESPARSE)
    377 
    378 # By default, if all of CXSparse's dependencies are found, Ceres is
    379 # built with CXSparse support. -DCXSPARSE=ON/OFF can be used to
    380 # enable/disable CXSparse explicitly.
    381 IF ((NOT DEFINED CXSPARSE) OR (DEFINED CXSPARSE AND CXSPARSE))
    382 
    383 SET(CXSPARSE_FOUND ON)
    384 FIND_LIBRARY(CXSPARSE_LIB NAMES cxsparse)
    385 IF (EXISTS ${CXSPARSE_LIB})
    386   MESSAGE("-- Found CXSparse library in: ${CXSPARSE_LIB}")
    387 ELSE (EXISTS ${CXSPARSE_LIB})
    388   MESSAGE("-- Did not find CXSparse header")
    389   SET(CXSPARSE_FOUND FALSE)
    390 ENDIF (EXISTS ${CXSPARSE_LIB})
    391 
    392 FIND_PATH(CXSPARSE_INCLUDE NAMES cs.h)
    393 IF (EXISTS ${CXSPARSE_INCLUDE})
    394   MESSAGE("-- Found CXSparse header in: ${CXSPARSE_INCLUDE}")
    395 ELSE (EXISTS ${CXSPARSE_INCLUDE})
    396   MESSAGE("-- Did not find CXSparse header")
    397   SET(CXSPARSE_FOUND FALSE)
    398 ENDIF (EXISTS ${CXSPARSE_INCLUDE})
    399 ENDIF ((NOT DEFINED CXSPARSE) OR (DEFINED CXSPARSE AND CXSPARSE))
    400 
    401 IF (DEFINED CXSPARSE)
    402   IF (CXSPARSE)
    403     IF (NOT CXSPARSE_FOUND)
    404       MESSAGE(FATAL_ERROR "-- CXSparse not found.")
    405     ENDIF (NOT CXSPARSE_FOUND)
    406   ELSE (CXSPARSE)
    407     ADD_DEFINITIONS(-DCERES_NO_CXSPARSE)
    408   ENDIF (CXSPARSE)
    409 ELSE (DEFINED CXSPARSE)
    410   IF (CXSPARSE_FOUND)
    411     MESSAGE("-- Building with CXSparse support.")
    412     SET(CXSPARSE ON)
    413   ELSE (CXSPARSE_FOUND)
    414     MESSAGE("-- Building without CXSparse.")
    415     SET(CXSPARSE OFF)
    416     ADD_DEFINITIONS(-DCERES_NO_CXSPARSE)
    417   ENDIF (CXSPARSE_FOUND)
    418 ENDIF (DEFINED CXSPARSE)
    419 
    420 IF (GFLAGS)
    421   FIND_LIBRARY(GFLAGS_LIB NAMES gflags)
    422   IF (NOT EXISTS ${GFLAGS_LIB})
    423     MESSAGE(FATAL_ERROR
    424             "Can't find Google Flags. Please specify: "
    425             "-DGFLAGS_LIB=...")
    426   ENDIF (NOT EXISTS ${GFLAGS_LIB})
    427   MESSAGE("-- Found Google Flags library: ${GFLAGS_LIB}")
    428   FIND_PATH(GFLAGS_INCLUDE NAMES gflags/gflags.h)
    429   IF (NOT EXISTS ${GFLAGS_INCLUDE})
    430     MESSAGE(FATAL_ERROR
    431             "Can't find Google Flags. Please specify: "
    432             "-DGFLAGS_INCLUDE=...")
    433   ENDIF (NOT EXISTS ${GFLAGS_INCLUDE})
    434   MESSAGE("-- Found Google Flags header in: ${GFLAGS_INCLUDE}")
    435 ELSE (GFLAGS)
    436   MESSAGE("-- Google Flags disabled; no tests or tools will be built!")
    437   ADD_DEFINITIONS(-DCERES_NO_GFLAGS)
    438 ENDIF (GFLAGS)
    439 
    440 IF (MINIGLOG)
    441   SET(GLOG_LIB miniglog)
    442   MESSAGE("-- Using minimal Glog substitute (library): ${GLOG_LIB}")
    443   SET(GLOG_INCLUDE internal/ceres/miniglog)
    444   MESSAGE("-- Using minimal Glog substitute (include): ${GLOG_INCLUDE}")
    445 ELSE (MINIGLOG)
    446   FIND_LIBRARY(GLOG_LIB NAMES glog)
    447   IF (EXISTS ${GLOG_LIB})
    448     MESSAGE("-- Found Google Log library: ${GLOG_LIB}")
    449   ELSE (EXISTS ${GLOG_LIB})
    450     MESSAGE(FATAL_ERROR
    451             "Can't find Google Log. Please specify: -DGLOG_LIB=...")
    452   ENDIF (EXISTS ${GLOG_LIB})
    453 
    454   FIND_PATH(GLOG_INCLUDE NAMES glog/logging.h)
    455   IF (EXISTS ${GLOG_INCLUDE})
    456     MESSAGE("-- Found Google Log header in: ${GLOG_INCLUDE}")
    457   ELSE (EXISTS ${GLOG_INCLUDE})
    458     MESSAGE(FATAL_ERROR
    459             "Can't find Google Log. Please specify: -DGLOG_INCLUDE=...")
    460   ENDIF (EXISTS ${GLOG_INCLUDE})
    461 ENDIF (MINIGLOG)
    462 
    463 IF (NOT SCHUR_SPECIALIZATIONS)
    464   ADD_DEFINITIONS(-DCERES_RESTRICT_SCHUR_SPECIALIZATION)
    465   MESSAGE("-- Disabling Schur specializations (faster compiles)")
    466 ENDIF (NOT SCHUR_SPECIALIZATIONS)
    467 
    468 IF (NOT LINE_SEARCH_MINIMIZER)
    469   ADD_DEFINITIONS(-DCERES_NO_LINE_SEARCH_MINIMIZER)
    470   MESSAGE("-- Disabling line search minimizer")
    471 ENDIF (NOT LINE_SEARCH_MINIMIZER)
    472 
    473 IF (NOT CUSTOM_BLAS)
    474   ADD_DEFINITIONS(-DCERES_NO_CUSTOM_BLAS)
    475   MESSAGE("-- Disabling custom blas")
    476 ENDIF (NOT CUSTOM_BLAS)
    477 
    478 IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    479   SET(OPENMP_FOUND FALSE)
    480 ELSE (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    481   IF (OPENMP)
    482     FIND_PACKAGE(OpenMP)
    483   ENDIF (OPENMP)
    484 ENDIF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    485 
    486 IF (OPENMP_FOUND)
    487   MESSAGE("-- Found OpenMP.")
    488   ADD_DEFINITIONS(-DCERES_USE_OPENMP)
    489   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    490   IF (UNIX)
    491     # At least on Linux, we need pthreads to be enabled for mutex to
    492     # compile.  This may not work on Windows or Android.
    493     FIND_PACKAGE(Threads REQUIRED)
    494     SET(STATIC_LIBRARY_FLAGS
    495         "${STATIC_LIBRARY_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
    496     SET(CMAKE_SHARED_LINKER_FLAGS
    497         "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
    498     ADD_DEFINITIONS(-DCERES_HAVE_PTHREAD)
    499     ADD_DEFINITIONS(-DCERES_HAVE_RWLOCK)
    500   ENDIF (UNIX)
    501 ELSE (OPENMP_FOUND)
    502   MESSAGE("-- Can't find OpenMP. Disabling multithreading.")
    503   ADD_DEFINITIONS(-DCERES_NO_THREADS)
    504 ENDIF (OPENMP_FOUND)
    505 
    506 IF (DISABLE_TR1)
    507   MESSAGE("-- Replacing unordered_map/set with map/set (warning: slower!)")
    508   ADD_DEFINITIONS(-DCERES_NO_TR1)
    509 ELSE (DISABLE_TR1)
    510   MESSAGE("-- Using normal TR1 unordered_map/set")
    511   # Use the std namespace for the hash<> and related templates. This may vary by
    512   # system.
    513   IF (MSVC)
    514     IF (MSVC90)
    515       # Special case for Visual Studio 2008.
    516       # Newer versions have got tr1 symbols in another namespace,
    517       # and this is being handled in Else branch of this condition.
    518       # Probably Visual studio 2003 and 2005 also shall be handled here,
    519       # but don't have by hand to verify and most likely they're not
    520       # used by Ceres users anyway.
    521       ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_START=namespace std { namespace tr1 {\"")
    522       ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_END=}}\"")
    523     ELSE (MSVC90)
    524       # This is known to work with Visual Studio 2010 Express.
    525       # Further, for as long Visual Studio 2012 didn't move tr1 to
    526       # just another namespace, the same define will work for it as well.
    527       # Hopefully all further versions will also keep working with this define.
    528       ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_START=namespace std {\"")
    529       ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_END=}\"")
    530     ENDIF(MSVC90)
    531   ELSE (MSVC)
    532     # This is known to work with recent versions of Linux and Mac OS X.
    533     ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_START=namespace std { namespace tr1 {\"")
    534     ADD_DEFINITIONS("\"-DCERES_HASH_NAMESPACE_END=}}\"")
    535   ENDIF (MSVC)
    536 ENDIF (DISABLE_TR1)
    537 
    538 INCLUDE_DIRECTORIES(
    539   include
    540   internal
    541   internal/ceres
    542   ${GLOG_INCLUDE}
    543   ${EIGEN_INCLUDE}
    544   )
    545 
    546 FILE(GLOB CERES_HDRS ${CMAKE_SOURCE_DIR}/include/ceres/*.h)
    547 INSTALL(FILES ${CERES_HDRS} DESTINATION include/ceres)
    548 
    549 FILE(GLOB CERES_PUBLIC_INTERNAL_HDRS ${CMAKE_SOURCE_DIR}/include/ceres/internal/*.h)
    550 INSTALL(FILES ${CERES_PUBLIC_INTERNAL_HDRS} DESTINATION include/ceres/internal)
    551 
    552 IF (SUITESPARSE)
    553   INCLUDE_DIRECTORIES(${AMD_INCLUDE})
    554   INCLUDE_DIRECTORIES(${CAMD_INCLUDE})
    555   INCLUDE_DIRECTORIES(${COLAMD_INCLUDE})
    556   INCLUDE_DIRECTORIES(${CCOLAMD_INCLUDE})
    557   INCLUDE_DIRECTORIES(${CHOLMOD_INCLUDE})
    558   INCLUDE_DIRECTORIES(${SUITESPARSEQR_INCLUDE})
    559   IF (SUITESPARSE_CONFIG_FOUND)
    560     INCLUDE_DIRECTORIES(${SUITESPARSE_CONFIG_INCLUDE})
    561   ENDIF (SUITESPARSE_CONFIG_FOUND)
    562   IF (UFCONFIG_FOUND)
    563     INCLUDE_DIRECTORIES(${UFCONFIG_INCLUDE})
    564   ENDIF (UFCONFIG_FOUND)
    565 ENDIF (SUITESPARSE)
    566 
    567 IF (CXSPARSE)
    568   INCLUDE_DIRECTORIES(${CXSPARSE_INCLUDE})
    569 ENDIF (CXSPARSE)
    570 
    571 IF (GFLAGS)
    572   INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE})
    573 ENDIF (GFLAGS)
    574 
    575 # Change the default build type from Debug to Release, while still
    576 # supporting overriding the build type.
    577 #
    578 # The CACHE STRING logic here and elsewhere is needed to force CMake
    579 # to pay attention to the value of these variables.
    580 IF (NOT CMAKE_BUILD_TYPE)
    581   MESSAGE("-- No build type specified; defaulting to CMAKE_BUILD_TYPE=Release.")
    582   SET(CMAKE_BUILD_TYPE Release CACHE STRING
    583     "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
    584     FORCE)
    585 ELSE (NOT CMAKE_BUILD_TYPE)
    586   IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
    587     MESSAGE("\n=================================================================================")
    588     MESSAGE("\n-- Build type: Debug. Performance will be terrible!")
    589     MESSAGE("-- Add -DCMAKE_BUILD_TYPE=Release to the CMake command line to get an optimized build.")
    590     MESSAGE("\n=================================================================================")
    591   ENDIF (CMAKE_BUILD_TYPE STREQUAL "Debug")
    592 ENDIF (NOT CMAKE_BUILD_TYPE)
    593 
    594 # Set the default Ceres flags to an empty string.
    595 SET (CERES_CXX_FLAGS)
    596 
    597 IF (CMAKE_BUILD_TYPE STREQUAL "Release")
    598   IF (CMAKE_COMPILER_IS_GNUCXX)
    599     # Linux
    600     IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    601       SET (CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -march=native -mtune=native")
    602     ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux")
    603     # Mac OS X
    604     IF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    605       SET (CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -msse3")
    606       # Use of -fast only applicable for Apple's GCC
    607       # Assume this is being used if GCC version < 4.3 on OSX
    608       EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
    609       IF (GCC_VERSION VERSION_LESS 4.3)
    610         SET (CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -fast")
    611       ENDIF (GCC_VERSION VERSION_LESS 4.3)
    612     ENDIF (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    613   ENDIF (CMAKE_COMPILER_IS_GNUCXX)
    614   IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    615     # Use of -O4 requires use of gold linker & LLVM-gold plugin, which might
    616     # well not be present / in use and without which files will compile, but
    617     # not link ('file not recognized') so explicitly check for support
    618     INCLUDE(CheckCXXCompilerFlag)
    619     CHECK_CXX_COMPILER_FLAG("-O4" HAVE_LTO_SUPPORT)
    620     IF (HAVE_LTO_SUPPORT)
    621       MESSAGE(STATUS "Enabling link-time optimization (-O4)")
    622       SET(CERES_CXX_FLAGS "${CERES_CXX_FLAGS} -O4")
    623     ELSE ()
    624       MESSAGE(STATUS "Compiler/linker does not support link-time optimization (-O4), disabling.")
    625     ENDIF (HAVE_LTO_SUPPORT)
    626   ENDIF ()
    627 ENDIF (CMAKE_BUILD_TYPE STREQUAL "Release")
    628 
    629 SET (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CERES_CXX_FLAGS}")
    630 
    631 # After the tweaks for the compile settings, disable some warnings on MSVC.
    632 IF (MSVC)
    633   # Disable signed/unsigned int conversion warnings.
    634   ADD_DEFINITIONS("/wd4018")
    635   # Disable warning about using struct/class for the same symobl.
    636   ADD_DEFINITIONS("/wd4099")
    637   # Disable warning about the insecurity of using "std::copy".
    638   ADD_DEFINITIONS("/wd4996")
    639   # Disable performance warning about int-to-bool conversion.
    640   ADD_DEFINITIONS("/wd4800")
    641   # Disable performance warning about fopen insecurity.
    642   ADD_DEFINITIONS("/wd4996")
    643   # Disable warning about int64 to int32 conversion. Disabling
    644   # this warning may not be correct; needs investigation.
    645   # TODO(keir): Investigate these warnings in more detail.
    646   ADD_DEFINITIONS("/wd4244")
    647   # It's not possible to use STL types in DLL interfaces in a portable and
    648   # reliable way. However, that's what happens with Google Log and Google Flags
    649   # on Windows. MSVC gets upset about this and throws warnings that we can't do
    650   # much about. The real solution is to link static versions of Google Log and
    651   # Google Test, but that seems tricky on Windows. So, disable the warning.
    652   ADD_DEFINITIONS("/wd4251")
    653 
    654   # Google Flags doesn't have their DLL import/export stuff set up correctly,
    655   # which results in linker warnings. This is irrelevant for Ceres, so ignore
    656   # the warnings.
    657   SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4049")
    658 
    659   # Tuple sizes of 10 are used by Gtest.
    660   ADD_DEFINITIONS("-D_VARIADIC_MAX=10")
    661 ENDIF (MSVC)
    662 
    663 IF (UNIX)
    664   # GCC is not strict enough by default, so enable most of the warnings.
    665   SET(CMAKE_CXX_FLAGS
    666     "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers")
    667 ENDIF (UNIX)
    668 
    669 # Use a larger inlining threshold for Clang, since it hobbles Eigen,
    670 # resulting in an unreasonably slow version of the blas routines. The
    671 # -Qunused-arguments is needed because CMake passes the inline
    672 # threshold to the linker and clang complains about it and dies.
    673 IF (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
    674   SET(CMAKE_CXX_FLAGS
    675       "${CMAKE_CXX_FLAGS} -Qunused-arguments -mllvm -inline-threshold=600 -Wno-return-type-c-linkage")
    676 ENDIF ()
    677 
    678 ADD_SUBDIRECTORY(internal/ceres)
    679 
    680 IF (BUILD_DOCUMENTATION)
    681   MESSAGE("-- Documentation building is enabled")
    682 
    683   # Make CMake aware of the cmake folder, in order to find 'FindSphinx.cmake'
    684   SET (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
    685 
    686   # Generate the User's Guide (html).
    687   # The corresponding target is UserGuide, but is included in ALL.
    688   ADD_SUBDIRECTORY(docs)
    689 ENDIF (BUILD_DOCUMENTATION)
    690 
    691 IF (BUILD_EXAMPLES)
    692   MESSAGE("-- Build the examples.")
    693   ADD_SUBDIRECTORY(examples)
    694 ELSE (BUILD_EXAMPLES)
    695   MESSAGE("-- Do not build any example.")
    696 ENDIF (BUILD_EXAMPLES)
    697 
    698 # Add an uninstall target to remove all installed files.
    699 CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/uninstall.cmake.in"
    700                "${CMAKE_BINARY_DIR}/cmake/uninstall.cmake"
    701                IMMEDIATE @ONLY)
    702 
    703 ADD_CUSTOM_TARGET(uninstall
    704                   COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/cmake/uninstall.cmake)
    705 
    706 # Set up install directories. INCLUDE_INSTALL_DIR, LIB_INSTALL_DIR and
    707 # CMAKECONFIG_INSTALL_DIR must not be absolute paths.
    708 SET(INCLUDE_INSTALL_DIR include)
    709 SET(LIB_INSTALL_DIR lib)
    710 SET(CMAKECONFIG_INSTALL_DIR share/Ceres)
    711 
    712 # This "exports" all targets which have been put into the export set
    713 # "CeresExport". This means that CMake generates a file with the given
    714 # filename, which can later on be loaded by projects using this package.
    715 # This file contains ADD_LIBRARY(bar IMPORTED) statements for each target
    716 # in the export set, so when loaded later on CMake will create "imported"
    717 # library targets from these, which can be used in many ways in the same way
    718 # as a normal library target created via a normal ADD_LIBRARY().
    719 INSTALL(EXPORT CeresExport
    720         DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE CeresTargets.cmake)
    721 
    722 # Figure out the relative path from the installed Config.cmake file to the
    723 # install prefix (which may be at runtime different from the chosen
    724 # CMAKE_INSTALL_PREFIX if under Windows the package was installed anywhere)
    725 # This relative path will be configured into the CeresConfig.cmake.
    726 FILE(RELATIVE_PATH relInstallDir
    727      ${CMAKE_INSTALL_PREFIX}/${CMAKECONFIG_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX})
    728 
    729 # Create a CeresConfig.cmake file. <name>Config.cmake files are searched by
    730 # FIND_PACKAGE() automatically. We configure that file so that we can put any
    731 # information we want in it, e.g. version numbers, include directories, etc.
    732 CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/CeresConfig.cmake.in"
    733                "${CMAKE_CURRENT_BINARY_DIR}/CeresConfig.cmake" @ONLY)
    734 
    735 # Additionally, when CMake has found a CeresConfig.cmake, it can check for a
    736 # CeresConfigVersion.cmake in the same directory when figuring out the version
    737 # of the package when a version has been specified in the FIND_PACKAGE() call,
    738 # e.g. FIND_PACKAGE(Ceres [1.4.2] REQUIRED). The version argument is optional.
    739 CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/cmake/CeresConfigVersion.cmake.in"
    740                "${CMAKE_CURRENT_BINARY_DIR}/CeresConfigVersion.cmake" @ONLY)
    741 
    742 # Install these two files into the same directory as the generated exports-file.
    743 INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/CeresConfig.cmake"
    744               "${CMAKE_CURRENT_BINARY_DIR}/CeresConfigVersion.cmake"
    745               "${CMAKE_SOURCE_DIR}/cmake/depend.cmake"
    746         DESTINATION ${CMAKECONFIG_INSTALL_DIR})
    747