Imported Upstream version ceres 1.13.0
[platform/upstream/ceres-solver.git] / internal / ceres / CMakeLists.txt
1 # Ceres Solver - A fast non-linear least squares minimizer
2 # Copyright 2015 Google Inc. All rights reserved.
3 # http://ceres-solver.org/
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@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     dynamic_sparse_normal_cholesky_solver.cc
65     evaluator.cc
66     eigensparse.cc
67     file.cc
68     function_sample.cc
69     gradient_checker.cc
70     gradient_checking_cost_function.cc
71     gradient_problem.cc
72     gradient_problem_solver.cc
73     implicit_schur_complement.cc
74     inner_product_computer.cc
75     is_close.cc
76     iterative_schur_complement_solver.cc
77     levenberg_marquardt_strategy.cc
78     lapack.cc
79     line_search.cc
80     line_search_direction.cc
81     line_search_minimizer.cc
82     line_search_preprocessor.cc
83     linear_least_squares_problems.cc
84     linear_operator.cc
85     linear_solver.cc
86     local_parameterization.cc
87     loss_function.cc
88     low_rank_inverse_hessian.cc
89     minimizer.cc
90     normal_prior.cc
91     parameter_block_ordering.cc
92     partitioned_matrix_view.cc
93     polynomial.cc
94     preconditioner.cc
95     preprocessor.cc
96     problem.cc
97     problem_impl.cc
98     program.cc
99     reorder_program.cc
100     residual_block.cc
101     residual_block_utils.cc
102     schur_complement_solver.cc
103     schur_eliminator.cc
104     schur_jacobi_preconditioner.cc
105     schur_templates.cc
106     scratch_evaluate_preparer.cc
107     single_linkage_clustering.cc
108     solver.cc
109     solver_utils.cc
110     sparse_matrix.cc
111     sparse_cholesky.cc
112     sparse_normal_cholesky_solver.cc
113     split.cc
114     stringprintf.cc
115     suitesparse.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
121     types.cc
122     visibility.cc
123     visibility_based_preconditioner.cc
124     wall_time.cc
125 )
126
127 # Also depend on the header files so that they appear in IDEs.
128 file(GLOB CERES_INTERNAL_HDRS *.h)
129 if (MINIGLOG)
130   file(GLOB MINIGLOG_HDRS miniglog/glog/*.h)
131   list(APPEND CERES_INTERNAL_HDRS ${MINIGLOG_HDRS})
132 endif()
133
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)
137
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)
145
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})
149   if (GFLAGS_FOUND)
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})
156   endif()
157 endif (NOT MINIGLOG AND GLOG_FOUND)
158
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)
164
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)
170
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)
175
176 if (OPENMP_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)
180   endif()
181   if (NOT MSVC)
182     list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${CMAKE_THREAD_LIBS_INIT})
183   endif()
184 endif (OPENMP_FOUND)
185
186 set(CERES_LIBRARY_SOURCE
187     ${CERES_INTERNAL_SRC}
188     ${CERES_INTERNAL_HDRS}
189     ${CERES_PUBLIC_HDRS}
190     ${CERES_PUBLIC_INTERNAL_HDRS}
191     ${CERES_INTERNAL_SCHUR_FILES})
192
193 # Primarily for Android, but optionally for others, compile the minimal
194 # glog implementation into Ceres.
195 if (MINIGLOG)
196   list(APPEND CERES_LIBRARY_SOURCE miniglog/glog/logging.cc)
197 endif (MINIGLOG)
198
199 add_library(ceres ${CERES_LIBRARY_SOURCE})
200 set_target_properties(ceres PROPERTIES
201   VERSION ${CERES_VERSION}
202   SOVERSION ${CERES_VERSION_MAJOR})
203
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")
214   else()
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)
218   endif()
219 endif()
220
221 if (CXX11)
222   include(AddCeresCXX11RequirementsToTarget)
223   add_ceres_cxx11_requirements_to_target(ceres)
224 endif()
225
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)
241
242 install(TARGETS ceres
243         EXPORT  CeresExport
244         RUNTIME DESTINATION bin
245         LIBRARY DESTINATION lib${LIB_SUFFIX}
246         ARCHIVE DESTINATION lib${LIB_SUFFIX})
247
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)
254   endif()
255
256   add_library(test_util
257               evaluator_test_utils.cc
258               numeric_diff_test_utils.cc
259               test_util.cc)
260
261   if (MINIGLOG)
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)
266   else (MINIGLOG)
267     target_link_libraries(gtest ${GFLAGS_LIBRARIES} ${GLOG_LIBRARIES})
268     target_link_libraries(test_util ceres gtest ${GLOG_LIBRARIES})
269   endif (MINIGLOG)
270
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)
278     endif()
279     add_test(NAME ${NAME}_test
280              COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${NAME}_test
281              --test_srcdir
282              ${Ceres_SOURCE_DIR}/data)
283   endmacro (CERES_TEST)
284
285   ceres_test(array_utils)
286   ceres_test(autodiff)
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)
294   ceres_test(c_api)
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)
318   ceres_test(graph)
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)
324   ceres_test(is_close)
325   ceres_test(iterative_schur_complement_solver)
326   ceres_test(jet)
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)
340   ceres_test(problem)
341   ceres_test(program)
342   ceres_test(reorder_program)
343   ceres_test(residual_block)
344   ceres_test(residual_block_utils)
345   ceres_test(rotation)
346   ceres_test(schur_complement_solver)
347   ceres_test(schur_eliminator)
348   ceres_test(single_linkage_clustering)
349   ceres_test(small_blas)
350   ceres_test(solver)
351   ceres_test(sparse_cholesky)
352   ceres_test(sparse_normal_cholesky_solver)
353   ceres_test(system)
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)
359
360   # Put the large end to end test last.
361   ceres_test(bundle_adjustment)
362
363 endif (BUILD_TESTING AND GFLAGS)