1 # Ceres Solver - A fast non-linear least squares minimizer
2 # Copyright 2015 Google Inc. All rights reserved.
3 # http://ceres-solver.org/
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
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.
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.
29 # Author: keir@google.com (Keir Mierle)
31 set(CERES_INTERNAL_SRC
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
44 canonical_views_clustering.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
57 dense_normal_cholesky_solver.cc
59 dense_sparse_matrix.cc
62 dynamic_compressed_row_jacobian_writer.cc
63 dynamic_compressed_row_sparse_matrix.cc
64 dynamic_sparse_normal_cholesky_solver.cc
70 gradient_checking_cost_function.cc
72 gradient_problem_solver.cc
73 implicit_schur_complement.cc
74 inner_product_computer.cc
76 iterative_schur_complement_solver.cc
77 levenberg_marquardt_strategy.cc
80 line_search_direction.cc
81 line_search_minimizer.cc
82 line_search_preprocessor.cc
83 linear_least_squares_problems.cc
86 local_parameterization.cc
88 low_rank_inverse_hessian.cc
91 parameter_block_ordering.cc
92 partitioned_matrix_view.cc
101 residual_block_utils.cc
102 schur_complement_solver.cc
104 schur_jacobi_preconditioner.cc
106 scratch_evaluate_preparer.cc
107 single_linkage_clustering.cc
112 sparse_normal_cholesky_solver.cc
116 triplet_sparse_matrix.cc
117 trust_region_preprocessor.cc
118 trust_region_minimizer.cc
119 trust_region_step_evaluator.cc
120 trust_region_strategy.cc
123 visibility_based_preconditioner.cc
127 # Also depend on the header files so that they appear in IDEs.
128 file(GLOB CERES_INTERNAL_HDRS *.h)
130 file(GLOB MINIGLOG_HDRS miniglog/glog/*.h)
131 list(APPEND CERES_INTERNAL_HDRS ${MINIGLOG_HDRS})
134 # Depend also on public headers so they appear in IDEs.
135 file(GLOB CERES_PUBLIC_HDRS ${Ceres_SOURCE_DIR}/include/ceres/*.h)
136 file(GLOB CERES_PUBLIC_INTERNAL_HDRS ${Ceres_SOURCE_DIR}/include/ceres/internal/*.h)
138 # Include the specialized schur solvers.
139 if (SCHUR_SPECIALIZATIONS)
140 file(GLOB CERES_INTERNAL_SCHUR_FILES generated/*.cc)
141 else (SCHUR_SPECIALIZATIONS)
142 # Only the fully dynamic solver. The build is much faster this way.
143 file(GLOB CERES_INTERNAL_SCHUR_FILES generated/*_d_d_d.cc)
144 endif (SCHUR_SPECIALIZATIONS)
146 # Build the list of dependencies for Ceres based on the current configuration.
147 if (NOT MINIGLOG AND GLOG_FOUND)
148 list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES ${GLOG_LIBRARIES})
150 # If glog & gflags are both found, we assume that glog was built with
151 # gflags, as it is awkward to perform a try_compile() to verify this
152 # when gflags is an imported target (as it is in newer versions).
153 # As glog #includes gflags/gflags.h in glog/logging.h if compiled with
154 # gflags, it is thus a public dependency for Ceres in this case.
155 list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES ${GFLAGS_LIBRARIES})
157 endif (NOT MINIGLOG AND GLOG_FOUND)
159 if (SUITESPARSE AND SUITESPARSE_FOUND)
160 # Define version information for use in Solver::FullReport.
161 add_definitions(-DCERES_SUITESPARSE_VERSION="${SUITESPARSE_VERSION}")
162 list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${SUITESPARSE_LIBRARIES})
163 endif (SUITESPARSE AND SUITESPARSE_FOUND)
165 if (CXSPARSE AND CXSPARSE_FOUND)
166 # Define version information for use in Solver::FullReport.
167 add_definitions(-DCERES_CXSPARSE_VERSION="${CXSPARSE_VERSION}")
168 list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CXSPARSE_LIBRARIES})
169 endif (CXSPARSE AND CXSPARSE_FOUND)
171 if (BLAS_FOUND AND LAPACK_FOUND)
172 list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${LAPACK_LIBRARIES})
173 list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${BLAS_LIBRARIES})
174 endif (BLAS_FOUND AND LAPACK_FOUND)
177 # OpenMP support in Clang requires a non-GNU OpenMP library.
178 if (CMAKE_COMPILER_IS_GNUCXX)
179 list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES gomp)
182 list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CMAKE_THREAD_LIBS_INIT})
186 set(CERES_LIBRARY_SOURCE
187 ${CERES_INTERNAL_SRC}
188 ${CERES_INTERNAL_HDRS}
190 ${CERES_PUBLIC_INTERNAL_HDRS}
191 ${CERES_INTERNAL_SCHUR_FILES})
193 # Primarily for Android, but optionally for others, compile the minimal
194 # glog implementation into Ceres.
196 list(APPEND CERES_LIBRARY_SOURCE miniglog/glog/logging.cc)
199 add_library(ceres ${CERES_LIBRARY_SOURCE})
200 set_target_properties(ceres PROPERTIES
201 VERSION ${CERES_VERSION}
202 SOVERSION ${CERES_VERSION_MAJOR})
204 include(AppendTargetProperty)
205 # Always build position-independent code (PIC), even when building Ceres as a
206 # static library so that shared libraries can link against it, not just
207 # executables (PIC does not apply on Windows).
208 if (NOT WIN32 AND NOT BUILD_SHARED_LIBS)
209 # Use the explicit POSITION_INDEPENDENT_CODE target property on CMake versions
210 # that support it (>= 2.8.9). Otherwise, manually add the -fPIC flag as an
211 # additional compile definitions for the target.
212 if (CMAKE_VERSION VERSION_LESS "2.8.9")
213 append_target_property(ceres COMPILE_FLAGS "-fPIC")
215 # Use set_target_properties() not append_target_property() here as
216 # POSITION_INDEPENDENT_CODE is a binary ON/OFF switch.
217 set_target_properties(ceres PROPERTIES POSITION_INDEPENDENT_CODE ON)
222 include(AddCeresCXX11RequirementsToTarget)
223 add_ceres_cxx11_requirements_to_target(ceres)
226 if (BUILD_SHARED_LIBS)
227 # When building a shared library, mark all external libraries as
228 # PRIVATE so they don't show up as a dependency.
229 target_link_libraries(ceres
230 LINK_PUBLIC ${CERES_LIBRARY_PUBLIC_DEPENDENCIES}
231 LINK_PRIVATE ${CERES_LIBRARY_PRIVATE_DEPENDENCIES})
232 else (BUILD_SHARED_LIBS)
233 # When building a static library, all external libraries are
234 # PUBLIC(default) since the user needs to link to them.
235 # They will be listed in CeresTargets.cmake.
236 set(CERES_LIBRARY_DEPENDENCIES
237 ${CERES_LIBRARY_PUBLIC_DEPENDENCIES}
238 ${CERES_LIBRARY_PRIVATE_DEPENDENCIES})
239 target_link_libraries(ceres ${CERES_LIBRARY_DEPENDENCIES})
240 endif (BUILD_SHARED_LIBS)
242 install(TARGETS ceres
244 RUNTIME DESTINATION bin
245 LIBRARY DESTINATION lib${LIB_SUFFIX}
246 ARCHIVE DESTINATION lib${LIB_SUFFIX})
248 if (BUILD_TESTING AND GFLAGS)
249 add_library(gtest gmock_gtest_all.cc gmock_main.cc)
250 if (BUILD_SHARED_LIBS)
251 # Define gtest-specific shared library flags for compilation.
252 append_target_property(gtest COMPILE_DEFINITIONS
253 GTEST_CREATE_SHARED_LIBRARY)
256 add_library(test_util
257 evaluator_test_utils.cc
258 numeric_diff_test_utils.cc
262 # When using miniglog, it is compiled into Ceres, thus Ceres becomes
263 # the library against which other libraries should link for logging.
264 target_link_libraries(gtest ${GFLAGS_LIBRARIES} ceres)
265 target_link_libraries(test_util ceres gtest)
267 target_link_libraries(gtest ${GFLAGS_LIBRARIES} ${GLOG_LIBRARIES})
268 target_link_libraries(test_util ceres gtest ${GLOG_LIBRARIES})
271 macro (CERES_TEST NAME)
272 add_executable(${NAME}_test ${NAME}_test.cc)
273 target_link_libraries(${NAME}_test test_util ceres gtest)
274 if (BUILD_SHARED_LIBS)
275 # Define gtest-specific shared library flags for linking.
276 append_target_property(${NAME}_test COMPILE_DEFINITIONS
277 GTEST_LINKED_AS_SHARED_LIBRARY)
279 add_test(NAME ${NAME}_test
280 COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${NAME}_test
282 ${Ceres_SOURCE_DIR}/data)
283 endmacro (CERES_TEST)
285 ceres_test(array_utils)
287 ceres_test(autodiff_cost_function)
288 ceres_test(autodiff_local_parameterization)
289 ceres_test(block_jacobi_preconditioner)
290 ceres_test(block_random_access_dense_matrix)
291 ceres_test(block_random_access_diagonal_matrix)
292 ceres_test(block_random_access_sparse_matrix)
293 ceres_test(block_sparse_matrix)
295 ceres_test(canonical_views_clustering)
296 ceres_test(compressed_col_sparse_matrix_utils)
297 ceres_test(compressed_row_sparse_matrix)
298 ceres_test(conditioned_cost_function)
299 ceres_test(conjugate_gradients_solver)
300 ceres_test(corrector)
301 ceres_test(cost_function_to_functor)
302 ceres_test(covariance)
303 ceres_test(cubic_interpolation)
304 ceres_test(dense_linear_solver)
305 ceres_test(dense_sparse_matrix)
306 ceres_test(detect_structure)
307 ceres_test(dogleg_strategy)
308 ceres_test(dynamic_autodiff_cost_function)
309 ceres_test(dynamic_compressed_row_sparse_matrix)
310 ceres_test(dynamic_numeric_diff_cost_function)
311 ceres_test(dynamic_sparse_normal_cholesky_solver)
312 ceres_test(dynamic_sparsity)
313 ceres_test(evaluator)
314 ceres_test(gradient_checker)
315 ceres_test(gradient_checking_cost_function)
316 ceres_test(gradient_problem)
317 ceres_test(gradient_problem_solver)
319 ceres_test(graph_algorithms)
320 ceres_test(householder_vector)
321 ceres_test(implicit_schur_complement)
322 ceres_test(inner_product_computer)
323 ceres_test(invert_psd_matrix)
325 ceres_test(iterative_schur_complement_solver)
327 ceres_test(levenberg_marquardt_strategy)
328 ceres_test(line_search_minimizer)
329 ceres_test(line_search_preprocessor)
330 ceres_test(local_parameterization)
331 ceres_test(loss_function)
332 ceres_test(minimizer)
333 ceres_test(normal_prior)
334 ceres_test(numeric_diff_cost_function)
335 ceres_test(ordered_groups)
336 ceres_test(parameter_block)
337 ceres_test(parameter_block_ordering)
338 ceres_test(partitioned_matrix_view)
339 ceres_test(polynomial)
342 ceres_test(reorder_program)
343 ceres_test(residual_block)
344 ceres_test(residual_block_utils)
346 ceres_test(schur_complement_solver)
347 ceres_test(schur_eliminator)
348 ceres_test(single_linkage_clustering)
349 ceres_test(small_blas)
351 ceres_test(sparse_cholesky)
352 ceres_test(sparse_normal_cholesky_solver)
354 ceres_test(triplet_sparse_matrix)
355 ceres_test(trust_region_minimizer)
356 ceres_test(trust_region_preprocessor)
357 ceres_test(visibility)
358 ceres_test(visibility_based_preconditioner)
360 # Put the large end to end test last.
361 ceres_test(bundle_adjustment)
363 endif (BUILD_TESTING AND GFLAGS)