Home | History | Annotate | Download | only in ceres
      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 SET(CERES_INTERNAL_SRC
     32     array_utils.cc
     33     blas.cc
     34     block_evaluate_preparer.cc
     35     block_jacobi_preconditioner.cc
     36     block_jacobian_writer.cc
     37     block_random_access_dense_matrix.cc
     38     block_random_access_diagonal_matrix.cc
     39     block_random_access_matrix.cc
     40     block_random_access_sparse_matrix.cc
     41     block_sparse_matrix.cc
     42     block_structure.cc
     43     c_api.cc
     44     canonical_views_clustering.cc
     45     cgnr_solver.cc
     46     callbacks.cc
     47     compressed_col_sparse_matrix_utils.cc
     48     compressed_row_jacobian_writer.cc
     49     compressed_row_sparse_matrix.cc
     50     conditioned_cost_function.cc
     51     conjugate_gradients_solver.cc
     52     coordinate_descent_minimizer.cc
     53     corrector.cc
     54     covariance.cc
     55     covariance_impl.cc
     56     cxsparse.cc
     57     dense_normal_cholesky_solver.cc
     58     dense_qr_solver.cc
     59     dense_sparse_matrix.cc
     60     detect_structure.cc
     61     dogleg_strategy.cc
     62     dynamic_compressed_row_jacobian_writer.cc
     63     dynamic_compressed_row_sparse_matrix.cc
     64     evaluator.cc
     65     file.cc
     66     gradient_checking_cost_function.cc
     67     implicit_schur_complement.cc
     68     incomplete_lq_factorization.cc
     69     iterative_schur_complement_solver.cc
     70     levenberg_marquardt_strategy.cc
     71     lapack.cc
     72     line_search.cc
     73     line_search_direction.cc
     74     line_search_minimizer.cc
     75     linear_least_squares_problems.cc
     76     linear_operator.cc
     77     linear_solver.cc
     78     local_parameterization.cc
     79     loss_function.cc
     80     low_rank_inverse_hessian.cc
     81     minimizer.cc
     82     normal_prior.cc
     83     parameter_block_ordering.cc
     84     partitioned_matrix_view.cc
     85     polynomial.cc
     86     preconditioner.cc
     87     problem.cc
     88     problem_impl.cc
     89     program.cc
     90     reorder_program.cc
     91     residual_block.cc
     92     residual_block_utils.cc
     93     schur_complement_solver.cc
     94     schur_eliminator.cc
     95     schur_jacobi_preconditioner.cc
     96     scratch_evaluate_preparer.cc
     97     single_linkage_clustering.cc
     98     solver.cc
     99     solver_impl.cc
    100     sparse_matrix.cc
    101     sparse_normal_cholesky_solver.cc
    102     split.cc
    103     stringprintf.cc
    104     suitesparse.cc
    105     summary_utils.cc
    106     triplet_sparse_matrix.cc
    107     trust_region_minimizer.cc
    108     trust_region_strategy.cc
    109     types.cc
    110     visibility.cc
    111     visibility_based_preconditioner.cc
    112     wall_time.cc
    113 )
    114 
    115 # Heuristic for determining LIB_SUFFIX. FHS recommends that 64-bit systems
    116 # install native libraries to lib64 rather than lib. Most distros seem to
    117 # follow this convention with a couple notable exceptions (Debian-based and
    118 # Arch-based distros) which we try to detect here.
    119 IF (CMAKE_SYSTEM_NAME MATCHES "Linux" AND
    120     NOT DEFINED LIB_SUFFIX AND
    121     NOT CMAKE_CROSSCOMPILING AND
    122     CMAKE_SIZEOF_VOID_P EQUAL "8" AND
    123     NOT EXISTS "/etc/debian_version" AND
    124     NOT EXISTS "/etc/arch-release")
    125   SET(LIB_SUFFIX "64")
    126 ENDIF ()
    127 
    128 # Also depend on the header files so that they appear in IDEs.
    129 FILE(GLOB CERES_INTERNAL_HDRS *.h)
    130 
    131 # Include the specialized schur solvers.
    132 IF (SCHUR_SPECIALIZATIONS)
    133   FILE(GLOB CERES_INTERNAL_SCHUR_FILES generated/*.cc)
    134 ELSE (SCHUR_SPECIALIZATIONS)
    135   # Only the fully dynamic solver. The build is much faster this way.
    136   FILE(GLOB CERES_INTERNAL_SCHUR_FILES generated/*_d_d_d.cc)
    137 ENDIF (SCHUR_SPECIALIZATIONS)
    138 
    139 # Build the list of dependencies for Ceres based on the current configuration.
    140 IF (NOT MINIGLOG AND GLOG_FOUND)
    141   LIST(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES ${GLOG_LIBRARIES})
    142 ENDIF (NOT MINIGLOG AND GLOG_FOUND)
    143 
    144 IF (SUITESPARSE AND SUITESPARSE_FOUND)
    145   LIST(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${SUITESPARSE_LIBRARIES})
    146 ENDIF (SUITESPARSE AND SUITESPARSE_FOUND)
    147 
    148 IF (CXSPARSE AND CXSPARSE_FOUND)
    149   LIST(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CXSPARSE_LIBRARIES})
    150 ENDIF (CXSPARSE AND CXSPARSE_FOUND)
    151 
    152 IF (BLAS_FOUND AND LAPACK_FOUND)
    153   LIST(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${LAPACK_LIBRARIES})
    154   LIST(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${BLAS_LIBRARIES})
    155 ENDIF (BLAS_FOUND AND LAPACK_FOUND)
    156 
    157 IF (OPENMP_FOUND)
    158   IF (NOT MSVC)
    159     LIST(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES gomp)
    160     LIST(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CMAKE_THREAD_LIBS_INIT})
    161   ENDIF (NOT MSVC)
    162 ENDIF (OPENMP_FOUND)
    163 
    164 SET(CERES_LIBRARY_SOURCE
    165     ${CERES_INTERNAL_SRC}
    166     ${CERES_INTERNAL_HDRS}
    167     ${CERES_INTERNAL_SCHUR_FILES})
    168 
    169 # Primarily for Android, but optionally for others, compile the minimal
    170 # glog implementation into Ceres.
    171 IF (MINIGLOG)
    172   LIST(APPEND CERES_LIBRARY_SOURCE miniglog/glog/logging.cc)
    173 ENDIF (MINIGLOG)
    174 
    175 ADD_LIBRARY(ceres ${CERES_LIBRARY_SOURCE})
    176 SET_TARGET_PROPERTIES(ceres PROPERTIES
    177   VERSION ${CERES_VERSION}
    178   SOVERSION ${CERES_VERSION_MAJOR}
    179 )
    180 
    181 IF (BUILD_SHARED_LIBS)
    182   # When building a shared library, mark all external libraries as
    183   # PRIVATE so they don't show up as a dependency.
    184   TARGET_LINK_LIBRARIES(ceres
    185         LINK_PUBLIC ${CERES_LIBRARY_PUBLIC_DEPENDENCIES}
    186         LINK_PRIVATE ${CERES_LIBRARY_PRIVATE_DEPENDENCIES})
    187 ELSE (BUILD_SHARED_LIBS)
    188   # When building a static library, all external libraries are
    189   # PUBLIC(default) since the user needs to link to them.
    190   # They will be listed in CeresTargets.cmake.
    191   SET(CERES_LIBRARY_DEPENDENCIES
    192         ${CERES_LIBRARY_PUBLIC_DEPENDENCIES}
    193         ${CERES_LIBRARY_PRIVATE_DEPENDENCIES})
    194   TARGET_LINK_LIBRARIES(ceres ${CERES_LIBRARY_DEPENDENCIES})
    195 ENDIF (BUILD_SHARED_LIBS)
    196 
    197 INSTALL(TARGETS ceres
    198         EXPORT  CeresExport
    199         RUNTIME DESTINATION bin
    200         LIBRARY DESTINATION lib${LIB_SUFFIX}
    201         ARCHIVE DESTINATION lib${LIB_SUFFIX})
    202 
    203 IF (BUILD_TESTING AND GFLAGS)
    204   ADD_LIBRARY(gtest gmock_gtest_all.cc gmock_main.cc)
    205   ADD_LIBRARY(test_util
    206               evaluator_test_utils.cc
    207               numeric_diff_test_utils.cc
    208               test_util.cc)
    209 
    210   IF (MINIGLOG)
    211     # When using miniglog, it is compiled into Ceres, thus Ceres becomes
    212     # the library against which other libraries should link for logging.
    213     TARGET_LINK_LIBRARIES(gtest ${GFLAGS_LIBRARIES} ceres)
    214     TARGET_LINK_LIBRARIES(test_util ceres gtest)
    215   ELSE (MINIGLOG)
    216     TARGET_LINK_LIBRARIES(gtest ${GFLAGS_LIBRARIES} ${GLOG_LIBRARIES})
    217     TARGET_LINK_LIBRARIES(test_util ceres gtest ${GLOG_LIBRARIES})
    218   ENDIF (MINIGLOG)
    219 
    220   MACRO (CERES_TEST NAME)
    221     ADD_EXECUTABLE(${NAME}_test ${NAME}_test.cc)
    222     TARGET_LINK_LIBRARIES(${NAME}_test test_util ceres gtest)
    223     ADD_TEST(NAME ${NAME}_test
    224              COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${NAME}_test
    225              --test_srcdir
    226              ${CMAKE_SOURCE_DIR}/data)
    227   ENDMACRO (CERES_TEST)
    228 
    229   CERES_TEST(array_utils)
    230   CERES_TEST(autodiff)
    231   CERES_TEST(autodiff_cost_function)
    232   CERES_TEST(autodiff_local_parameterization)
    233   CERES_TEST(block_random_access_dense_matrix)
    234   CERES_TEST(block_random_access_diagonal_matrix)
    235   CERES_TEST(block_random_access_sparse_matrix)
    236   CERES_TEST(block_sparse_matrix)
    237   CERES_TEST(c_api)
    238   CERES_TEST(canonical_views_clustering)
    239   CERES_TEST(compressed_row_sparse_matrix)
    240   CERES_TEST(conditioned_cost_function)
    241   CERES_TEST(corrector)
    242   CERES_TEST(cost_function_to_functor)
    243   CERES_TEST(covariance)
    244   CERES_TEST(dense_sparse_matrix)
    245   CERES_TEST(dynamic_autodiff_cost_function)
    246   CERES_TEST(dynamic_compressed_row_sparse_matrix)
    247   CERES_TEST(dynamic_numeric_diff_cost_function)
    248   CERES_TEST(evaluator)
    249   CERES_TEST(gradient_checker)
    250   CERES_TEST(gradient_checking_cost_function)
    251   CERES_TEST(graph)
    252   CERES_TEST(graph_algorithms)
    253   CERES_TEST(implicit_schur_complement)
    254   CERES_TEST(incomplete_lq_factorization)
    255   CERES_TEST(iterative_schur_complement_solver)
    256   CERES_TEST(jet)
    257   CERES_TEST(levenberg_marquardt_strategy)
    258   CERES_TEST(dogleg_strategy)
    259   CERES_TEST(local_parameterization)
    260   CERES_TEST(loss_function)
    261   CERES_TEST(minimizer)
    262   CERES_TEST(normal_prior)
    263   CERES_TEST(numeric_diff_cost_function)
    264   CERES_TEST(numeric_diff_functor)
    265   CERES_TEST(ordered_groups)
    266   CERES_TEST(parameter_block)
    267   CERES_TEST(parameter_block_ordering)
    268   CERES_TEST(partitioned_matrix_view)
    269   CERES_TEST(polynomial)
    270   CERES_TEST(problem)
    271   CERES_TEST(program)
    272   CERES_TEST(reorder_program)
    273   CERES_TEST(residual_block)
    274   CERES_TEST(residual_block_utils)
    275   CERES_TEST(rotation)
    276   CERES_TEST(schur_complement_solver)
    277   CERES_TEST(schur_eliminator)
    278   CERES_TEST(single_linkage_clustering)
    279   CERES_TEST(small_blas)
    280   CERES_TEST(solver)
    281   CERES_TEST(solver_impl)
    282 
    283   # TODO(sameeragarwal): This test should ultimately be made
    284   # independent of SuiteSparse.
    285   IF (SUITESPARSE AND SUITESPARSE_FOUND)
    286     CERES_TEST(compressed_col_sparse_matrix_utils)
    287   ENDIF (SUITESPARSE AND SUITESPARSE_FOUND)
    288 
    289   CERES_TEST(symmetric_linear_solver)
    290   CERES_TEST(triplet_sparse_matrix)
    291   CERES_TEST(trust_region_minimizer)
    292   CERES_TEST(unsymmetric_linear_solver)
    293   CERES_TEST(visibility)
    294   CERES_TEST(visibility_based_preconditioner)
    295 
    296   # Put the large end to end test last.
    297   CERES_TEST(system)
    298 ENDIF (BUILD_TESTING AND GFLAGS)
    299