CMakeLists.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. # Ceres Solver - A fast non-linear least squares minimizer
  2. # Copyright 2022 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 %Cmust 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. # Build the list of dependencies for Ceres based on the current configuration.
  31. # Avoid 'xxx.cc has no symbols' warnings from source files which are 'empty'
  32. # when their enclosing #ifdefs are disabled.
  33. find_package(Threads REQUIRED)
  34. list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES Threads::Threads)
  35. # Make dependency visible to the parent CMakeLists.txt
  36. set(Threads_DEPENDENCY "find_dependency (Threads)" PARENT_SCOPE)
  37. # Source files that contain public symbols and live in the ceres namespaces.
  38. # Such symbols are expected to be marked with CERES_EXPORT and the files below
  39. # sorted in lexicographical order.
  40. set(CERES_EXPORTED_SRCS
  41. c_api.cc
  42. gradient_checker.cc
  43. gradient_problem.cc
  44. loss_function.cc
  45. manifold.cc
  46. normal_prior.cc
  47. problem.cc
  48. solver.cc
  49. types.cc
  50. )
  51. # Also depend on the header files so that they appear in IDEs.
  52. file(GLOB CERES_INTERNAL_HDRS *.h)
  53. if (MINIGLOG)
  54. file(GLOB MINIGLOG_HDRS miniglog/glog/*.h)
  55. list(APPEND CERES_INTERNAL_HDRS ${MINIGLOG_HDRS})
  56. if (ANDROID)
  57. list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES log)
  58. endif()
  59. endif()
  60. # Depend also on public headers so they appear in IDEs.
  61. file(GLOB CERES_PUBLIC_HDRS ${Ceres_SOURCE_DIR}/include/ceres/*.h)
  62. file(GLOB CERES_PUBLIC_INTERNAL_HDRS ${Ceres_SOURCE_DIR}/include/ceres/internal/*.h)
  63. file(GLOB CERES_PUBLIC_INTERNAL_HDRS
  64. ${Ceres_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/ceres/internal/*.h)
  65. # Include the specialized schur solvers.
  66. if (SCHUR_SPECIALIZATIONS)
  67. file(GLOB CERES_INTERNAL_SCHUR_FILES generated/*.cc)
  68. else (SCHUR_SPECIALIZATIONS)
  69. # Only the fully dynamic solver. The build is much faster this way.
  70. file(GLOB CERES_INTERNAL_SCHUR_FILES generated/*_d_d_d.cc)
  71. endif (SCHUR_SPECIALIZATIONS)
  72. # The generated specializations of the Schur eliminator include
  73. # schur_eliminator_impl.h which defines EIGEN_CACHEFRIENDLY_PRODUCT_THRESHOLD
  74. # to a different value than Eigen's default. Depending on the order of files
  75. # in the unity build this can lead to clashes. Additionally, these files are
  76. # already generated in a way which leads to fairly large compilation units,
  77. # so the gains from a unity build would be marginal.
  78. set_source_files_properties(${CERES_INTERNAL_SCHUR_FILES} PROPERTIES
  79. SKIP_UNITY_BUILD_INCLUSION ON)
  80. if (NOT MINIGLOG AND GLOG_FOUND)
  81. list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES ${GLOG_LIBRARIES})
  82. if (gflags_FOUND)
  83. # If glog & gflags are both found, we assume that glog was built with
  84. # gflags, as it is awkward to perform a try_compile() to verify this
  85. # when gflags is an imported target (as it is in newer versions).
  86. # As glog #includes gflags/gflags.h in glog/logging.h if compiled with
  87. # gflags, it is thus a public dependency for Ceres in this case.
  88. list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES gflags)
  89. endif()
  90. endif (NOT MINIGLOG AND GLOG_FOUND)
  91. if (SUITESPARSE AND SuiteSparse_FOUND)
  92. # Define version information for use in Solver::FullReport.
  93. add_definitions(-DCERES_SUITESPARSE_VERSION="${SuiteSparse_VERSION}")
  94. list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES SuiteSparse::CHOLMOD
  95. SuiteSparse::SPQR)
  96. if (SuiteSparse_Partition_FOUND)
  97. list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES SuiteSparse::Partition)
  98. endif (SuiteSparse_Partition_FOUND)
  99. endif (SUITESPARSE AND SuiteSparse_FOUND)
  100. if (SuiteSparse_Partition_FOUND OR EIGENMETIS)
  101. # Define version information for use in Solver::FullReport.
  102. add_definitions(-DCERES_METIS_VERSION="${METIS_VERSION}")
  103. list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES METIS::METIS)
  104. endif (SuiteSparse_Partition_FOUND OR EIGENMETIS)
  105. if (ACCELERATESPARSE AND AccelerateSparse_FOUND)
  106. list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${AccelerateSparse_LIBRARIES})
  107. endif()
  108. if (USE_CUDA)
  109. list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES
  110. CUDA::cublas
  111. CUDA::cudart
  112. CUDA::cusolver
  113. CUDA::cusparse)
  114. set_source_files_properties(cuda_kernels_vector_ops.cu.cc PROPERTIES LANGUAGE CUDA)
  115. set_source_files_properties(cuda_kernels_bsm_to_crs.cu.cc PROPERTIES LANGUAGE CUDA)
  116. add_library(ceres_cuda_kernels STATIC cuda_kernels_vector_ops.cu.cc cuda_kernels_bsm_to_crs.cu.cc)
  117. target_compile_features(ceres_cuda_kernels PRIVATE cxx_std_14)
  118. target_compile_definitions(ceres_cuda_kernels PRIVATE CERES_STATIC_DEFINE)
  119. # Enable __host__ / __device__ annotations in lambda declarations
  120. target_compile_options(ceres_cuda_kernels PRIVATE --extended-lambda)
  121. target_include_directories(ceres_cuda_kernels PRIVATE ${Ceres_SOURCE_DIR}/include ${Ceres_SOURCE_DIR}/internal ${Ceres_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR})
  122. list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ceres_cuda_kernels)
  123. endif (USE_CUDA)
  124. if (LAPACK_FOUND)
  125. list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES ${LAPACK_LIBRARIES})
  126. endif ()
  127. # Source files that contain private symbols and live in the ceres::internal
  128. # namespace. The corresponding symbols (classes, functions, etc.) are expected
  129. # to be marked with CERES_NO_EXPORT and the files below sorted in
  130. # lexicographical order.
  131. add_library(ceres_internal OBJECT
  132. ${CERES_INTERNAL_SCHUR_FILES}
  133. accelerate_sparse.cc
  134. array_utils.cc
  135. block_evaluate_preparer.cc
  136. block_jacobi_preconditioner.cc
  137. block_jacobian_writer.cc
  138. block_random_access_dense_matrix.cc
  139. block_random_access_diagonal_matrix.cc
  140. block_random_access_matrix.cc
  141. block_random_access_sparse_matrix.cc
  142. block_sparse_matrix.cc
  143. block_structure.cc
  144. callbacks.cc
  145. canonical_views_clustering.cc
  146. cgnr_solver.cc
  147. compressed_col_sparse_matrix_utils.cc
  148. compressed_row_jacobian_writer.cc
  149. compressed_row_sparse_matrix.cc
  150. conditioned_cost_function.cc
  151. context.cc
  152. context_impl.cc
  153. coordinate_descent_minimizer.cc
  154. corrector.cc
  155. cost_function.cc
  156. covariance.cc
  157. covariance_impl.cc
  158. cuda_block_sparse_crs_view.cc
  159. cuda_partitioned_block_sparse_crs_view.cc
  160. cuda_block_structure.cc
  161. cuda_sparse_matrix.cc
  162. cuda_vector.cc
  163. dense_cholesky.cc
  164. dense_normal_cholesky_solver.cc
  165. dense_qr.cc
  166. dense_qr_solver.cc
  167. dense_sparse_matrix.cc
  168. detect_structure.cc
  169. dogleg_strategy.cc
  170. dynamic_compressed_row_jacobian_writer.cc
  171. dynamic_compressed_row_sparse_matrix.cc
  172. dynamic_sparse_normal_cholesky_solver.cc
  173. eigensparse.cc
  174. evaluation_callback.cc
  175. evaluator.cc
  176. fake_bundle_adjustment_jacobian.cc
  177. file.cc
  178. first_order_function.cc
  179. float_suitesparse.cc
  180. function_sample.cc
  181. gradient_checking_cost_function.cc
  182. gradient_problem_solver.cc
  183. implicit_schur_complement.cc
  184. inner_product_computer.cc
  185. is_close.cc
  186. iteration_callback.cc
  187. iterative_refiner.cc
  188. iterative_schur_complement_solver.cc
  189. levenberg_marquardt_strategy.cc
  190. line_search.cc
  191. line_search_direction.cc
  192. line_search_minimizer.cc
  193. line_search_preprocessor.cc
  194. linear_least_squares_problems.cc
  195. linear_operator.cc
  196. linear_solver.cc
  197. low_rank_inverse_hessian.cc
  198. minimizer.cc
  199. parallel_invoke.cc
  200. parallel_utils.cc
  201. parallel_vector_ops.cc
  202. parameter_block_ordering.cc
  203. partitioned_matrix_view.cc
  204. polynomial.cc
  205. power_series_expansion_preconditioner.cc
  206. preconditioner.cc
  207. preprocessor.cc
  208. problem_impl.cc
  209. program.cc
  210. reorder_program.cc
  211. residual_block.cc
  212. residual_block_utils.cc
  213. schur_complement_solver.cc
  214. schur_eliminator.cc
  215. schur_jacobi_preconditioner.cc
  216. schur_templates.cc
  217. scratch_evaluate_preparer.cc
  218. single_linkage_clustering.cc
  219. solver_utils.cc
  220. sparse_cholesky.cc
  221. sparse_matrix.cc
  222. sparse_normal_cholesky_solver.cc
  223. stringprintf.cc
  224. subset_preconditioner.cc
  225. suitesparse.cc
  226. thread_pool.cc
  227. thread_token_provider.cc
  228. triplet_sparse_matrix.cc
  229. trust_region_minimizer.cc
  230. trust_region_preprocessor.cc
  231. trust_region_step_evaluator.cc
  232. trust_region_strategy.cc
  233. visibility.cc
  234. visibility_based_preconditioner.cc
  235. wall_time.cc
  236. )
  237. set(CERES_LIBRARY_SOURCE
  238. ${CERES_EXPORTED_SRCS}
  239. ${CERES_INTERNAL_HDRS}
  240. ${CERES_PUBLIC_HDRS}
  241. ${CERES_PUBLIC_INTERNAL_HDRS})
  242. # Primarily for Android, but optionally for others, compile the minimal
  243. # glog implementation into Ceres.
  244. if (MINIGLOG)
  245. list(APPEND CERES_LIBRARY_SOURCE miniglog/glog/logging.cc)
  246. endif (MINIGLOG)
  247. # Ceres C++ compiler flags can be too strict for an external library code
  248. # which we do not maintain.
  249. include(CheckCXXCompilerFlag)
  250. check_cxx_compiler_flag("-Wno-missing-declarations"
  251. CHECK_CXX_FLAG_Wno_missing_declarations)
  252. if (CHECK_CXX_FLAG_Wno_missing_declarations)
  253. set_property(SOURCE gmock_gtest_all.cc
  254. APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-missing-declarations")
  255. endif()
  256. add_library(ceres $<TARGET_OBJECTS:ceres_internal> ${CERES_LIBRARY_SOURCE})
  257. if(BUILD_SHARED_LIBS)
  258. # While building shared libraries, we additionally require a static variant to
  259. # be able to access internal symbols which are not intended for general use.
  260. # Therefore, create a static library from object files and apply all the
  261. # compiler options from the main library to the static one.
  262. add_library(ceres_static STATIC $<TARGET_OBJECTS:ceres_internal> ${CERES_LIBRARY_SOURCE})
  263. target_include_directories(ceres_static PUBLIC $<TARGET_PROPERTY:ceres,INCLUDE_DIRECTORIES>)
  264. target_compile_definitions(ceres_static PUBLIC $<TARGET_PROPERTY:ceres,COMPILE_DEFINITIONS>)
  265. target_compile_features(ceres_static PUBLIC $<TARGET_PROPERTY:ceres,COMPILE_FEATURES>)
  266. target_compile_options(ceres_static PUBLIC $<TARGET_PROPERTY:ceres,COMPILE_OPTIONS>)
  267. target_link_libraries(ceres_static
  268. INTERFACE $<TARGET_PROPERTY:ceres,INTERFACE_LINK_LIBRARIES>
  269. PRIVATE ${CERES_LIBRARY_PRIVATE_DEPENDENCIES})
  270. # CERES_STATIC_DEFINE is generated by the GenerateExportHeader CMake module
  271. # used to autogerate export.h. The macro should not be renamed without
  272. # updating the corresponding generate_export_header invocation.
  273. target_compile_definitions(ceres_static PUBLIC CERES_STATIC_DEFINE)
  274. else()
  275. # In a static library build, not additional access layer is necessary as all
  276. # symbols are visible.
  277. add_library(ceres_static ALIAS ceres)
  278. endif()
  279. # Create a local alias target that matches the expected installed target.
  280. add_library(Ceres::ceres ALIAS ceres)
  281. # Apply all compiler options from the main Ceres target. Compiler options should
  282. # be generally defined on the main target referenced by the ceres_target CMake
  283. # variable.
  284. target_include_directories(ceres_internal PUBLIC $<TARGET_PROPERTY:ceres,INCLUDE_DIRECTORIES>)
  285. target_compile_definitions(ceres_internal PUBLIC $<TARGET_PROPERTY:ceres,COMPILE_DEFINITIONS>)
  286. target_compile_options(ceres_internal PUBLIC $<TARGET_PROPERTY:ceres,COMPILE_OPTIONS>)
  287. target_compile_definitions(ceres_internal PRIVATE ceres_EXPORTS)
  288. target_compile_features(ceres_internal PRIVATE $<TARGET_PROPERTY:ceres,COMPILE_FEATURES>)
  289. # Ensure the minimum required C++ language version is fulfilled as our
  290. # requirement by downstream clients. Consumers can choose the same or a newer
  291. # language standard revision.
  292. target_compile_features(ceres PUBLIC cxx_std_17)
  293. set_target_properties(ceres PROPERTIES
  294. VERSION ${CERES_VERSION}
  295. SOVERSION 4)
  296. target_link_libraries(ceres
  297. PUBLIC ${CERES_LIBRARY_PUBLIC_DEPENDENCIES}
  298. PRIVATE ${CERES_LIBRARY_PRIVATE_DEPENDENCIES})
  299. # Add the Ceres headers to its target.
  300. #
  301. # Force the location containing the configured config.h to the front of the
  302. # include_directories list (by default it is appended to the back) to ensure
  303. # that if the user has an installed version of Ceres in the same location as one
  304. # of the dependencies (e.g. /usr/local) that we find the config.h we just
  305. # configured, not the (older) installed config.h.
  306. target_include_directories(ceres
  307. BEFORE PUBLIC
  308. $<BUILD_INTERFACE:${Ceres_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}>
  309. PRIVATE ${Ceres_SOURCE_DIR}/internal
  310. PUBLIC $<BUILD_INTERFACE:${Ceres_SOURCE_DIR}/include>
  311. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
  312. # Eigen SparseQR generates various compiler warnings related to unused and
  313. # uninitialised local variables. To avoid having to individually suppress these
  314. # warnings around the #include statements for Eigen headers across all GCC/Clang
  315. # versions, we tell CMake to treat Eigen headers as system headers. This
  316. # results in all compiler warnings from them being suppressed.
  317. target_link_libraries(ceres PUBLIC Eigen3::Eigen)
  318. # Gather the list of public & private include locations for all enabled optional
  319. # dependencies to be added to the Ceres target.
  320. set(CERES_LIBRARY_PRIVATE_DEPENDENCIES_INCLUDE_DIRS "")
  321. set(CERES_LIBRARY_PUBLIC_DEPENDENCIES_INCLUDE_DIRS "")
  322. if (MINIGLOG)
  323. # Force the miniglog headers to the front of the public include directories
  324. # to protect against the case when the user has glog installed in a standard
  325. # location (specifically the same as the Ceres install location) but compiled
  326. # Ceres with MINIGLOG anyway. Otherwise: "glog/logging.h" in the public Ceres
  327. # headers used in client code would match the installed version of glog, not
  328. # the miniglog headers, and the client application would fail to link.
  329. #
  330. # Note that this is an imperfect fix, as we cannot control the include
  331. # directories in client projects, and they could easily invert this ordering
  332. # themselves (intentionally or otherwise) and so break their build.
  333. target_include_directories(ceres BEFORE PUBLIC
  334. $<BUILD_INTERFACE:${Ceres_SOURCE_DIR}/internal/ceres/miniglog>
  335. $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/ceres/internal/miniglog>)
  336. elseif (NOT FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION)
  337. # Only append glog include directories if the glog found was not a CMake
  338. # exported target that already includes them.
  339. list(APPEND CERES_LIBRARY_PUBLIC_DEPENDENCIES_INCLUDE_DIRS
  340. ${GLOG_INCLUDE_DIRS})
  341. endif()
  342. if (ACCELERATESPARSE)
  343. list(APPEND CERES_LIBRARY_PRIVATE_DEPENDENCIES_INCLUDE_DIRS
  344. ${AccelerateSparse_INCLUDE_DIRS})
  345. endif()
  346. # Add include locations for optional dependencies to the Ceres target without
  347. # duplication.
  348. list(REMOVE_DUPLICATES CERES_LIBRARY_PRIVATE_DEPENDENCIES_INCLUDE_DIRS)
  349. target_include_directories(ceres PRIVATE ${CERES_LIBRARY_PRIVATE_DEPENDENCIES_INCLUDE_DIRS})
  350. list(REMOVE_DUPLICATES CERES_LIBRARY_PUBLIC_DEPENDENCIES_INCLUDE_DIRS)
  351. target_include_directories(ceres PUBLIC ${CERES_LIBRARY_PUBLIC_DEPENDENCIES_INCLUDE_DIRS})
  352. # Generate an export header for annotating symbols visibility
  353. include(GenerateExportHeader)
  354. generate_export_header(ceres EXPORT_FILE_NAME
  355. ${Ceres_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/ceres/internal/export.h)
  356. if (USE_CUDA)
  357. install(TARGETS ceres_cuda_kernels
  358. EXPORT CeresExport
  359. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  360. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  361. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
  362. endif(USE_CUDA)
  363. install(TARGETS ceres
  364. EXPORT CeresExport
  365. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  366. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  367. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
  368. if (BUILD_TESTING AND GFLAGS)
  369. add_library(gtest STATIC gmock_gtest_all.cc gmock_main.cc)
  370. target_include_directories(gtest PRIVATE ${Ceres_SOURCE_DIR}/internal/ceres)
  371. if (CMAKE_SYSTEM_NAME MATCHES "QNX")
  372. target_link_libraries(gtest PUBLIC regex)
  373. endif()
  374. target_link_libraries(gtest PRIVATE Ceres::ceres gflags)
  375. add_library(test_util STATIC
  376. evaluator_test_utils.cc
  377. numeric_diff_test_utils.cc
  378. test_util.cc)
  379. target_include_directories(test_util PUBLIC ${Ceres_SOURCE_DIR}/internal)
  380. target_link_libraries (test_util PUBLIC ceres_static gflags gtest)
  381. macro (CERES_TEST NAME)
  382. add_executable(${NAME}_test ${NAME}_test.cc)
  383. # Pull in local headers from the generated test directories when ceres_test()
  384. # is invoked there, as well as the private headers in this directory which
  385. # may be referenced without the 'ceres' path prefix and all private
  386. # dependencies that may be directly referenced.
  387. target_include_directories(${NAME}_test
  388. PRIVATE ${Ceres_SOURCE_DIR}/internal/ceres
  389. ${CERES_LIBRARY_PRIVATE_DEPENDENCIES_INCLUDE_DIRS})
  390. # Some tests include direct references/includes of private dependency
  391. # headers which are not propagated via the ceres targets, so link them
  392. # explicitly.
  393. target_link_libraries(${NAME}_test PRIVATE gtest test_util ceres_static
  394. ${CERES_LIBRARY_PRIVATE_DEPENDENCIES})
  395. # covariance_test uses SuiteSparseQR.hpp. However, since SuiteSparse import
  396. # targets are private (link only) dependencies not propagated to consumers,
  397. # we need to link against the target explicitly here.
  398. if (TARGET SuiteSparse::SPQR)
  399. target_link_libraries (${NAME}_test PRIVATE SuiteSparse::SPQR)
  400. endif (TARGET SuiteSparse::SPQR)
  401. add_test(NAME ${NAME}_test
  402. COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${NAME}_test
  403. --test_srcdir
  404. ${Ceres_SOURCE_DIR}/data)
  405. endmacro (CERES_TEST)
  406. ceres_test(array_utils)
  407. ceres_test(array_selector)
  408. ceres_test(autodiff)
  409. ceres_test(autodiff_first_order_function)
  410. ceres_test(autodiff_cost_function)
  411. ceres_test(autodiff_manifold)
  412. ceres_test(block_jacobi_preconditioner)
  413. ceres_test(block_random_access_dense_matrix)
  414. ceres_test(block_random_access_diagonal_matrix)
  415. ceres_test(block_random_access_sparse_matrix)
  416. ceres_test(block_sparse_matrix)
  417. ceres_test(c_api)
  418. ceres_test(canonical_views_clustering)
  419. ceres_test(compressed_col_sparse_matrix_utils)
  420. ceres_test(compressed_row_sparse_matrix)
  421. ceres_test(concurrent_queue)
  422. ceres_test(conditioned_cost_function)
  423. ceres_test(conjugate_gradients_solver)
  424. ceres_test(corrector)
  425. ceres_test(cost_function_to_functor)
  426. ceres_test(covariance)
  427. ceres_test(cubic_interpolation)
  428. ceres_test(cuda_partitioned_block_sparse_crs_view)
  429. ceres_test(cuda_block_sparse_crs_view)
  430. ceres_test(cuda_block_structure)
  431. ceres_test(cuda_dense_cholesky)
  432. ceres_test(cuda_dense_qr)
  433. ceres_test(cuda_kernels_vector_ops)
  434. ceres_test(cuda_sparse_matrix)
  435. ceres_test(cuda_streamed_buffer)
  436. ceres_test(cuda_vector)
  437. ceres_test(dense_linear_solver)
  438. ceres_test(dense_cholesky)
  439. ceres_test(dense_qr)
  440. ceres_test(dense_sparse_matrix)
  441. ceres_test(detect_structure)
  442. ceres_test(dogleg_strategy)
  443. ceres_test(dynamic_autodiff_cost_function)
  444. ceres_test(dynamic_compressed_row_sparse_matrix)
  445. ceres_test(dynamic_numeric_diff_cost_function)
  446. ceres_test(dynamic_sparse_normal_cholesky_solver)
  447. ceres_test(dynamic_sparsity)
  448. ceres_test(evaluation_callback)
  449. ceres_test(evaluator)
  450. ceres_test(fixed_array)
  451. ceres_test(gradient_checker)
  452. ceres_test(gradient_checking_cost_function)
  453. ceres_test(gradient_problem)
  454. ceres_test(gradient_problem_solver)
  455. ceres_test(graph)
  456. ceres_test(graph_algorithms)
  457. ceres_test(householder_vector)
  458. ceres_test(implicit_schur_complement)
  459. ceres_test(inner_product_computer)
  460. ceres_test(invert_psd_matrix)
  461. ceres_test(integer_sequence_algorithm)
  462. ceres_test(is_close)
  463. ceres_test(iterative_refiner)
  464. ceres_test(iterative_schur_complement_solver)
  465. ceres_test(jet)
  466. ceres_test(jet_traits)
  467. ceres_test(levenberg_marquardt_strategy)
  468. ceres_test(line_search_minimizer)
  469. ceres_test(line_search_preprocessor)
  470. ceres_test(loss_function)
  471. ceres_test(manifold)
  472. ceres_test(minimizer)
  473. ceres_test(normal_prior)
  474. ceres_test(numeric_diff_cost_function)
  475. ceres_test(numeric_diff_first_order_function)
  476. ceres_test(ordered_groups)
  477. ceres_test(parallel_for)
  478. ceres_test(parallel_utils)
  479. ceres_test(parameter_block)
  480. ceres_test(parameter_block_ordering)
  481. ceres_test(parameter_dims)
  482. ceres_test(partitioned_matrix_view)
  483. ceres_test(polynomial)
  484. ceres_test(power_series_expansion_preconditioner)
  485. ceres_test(problem)
  486. ceres_test(program)
  487. ceres_test(reorder_program)
  488. ceres_test(residual_block)
  489. ceres_test(residual_block_utils)
  490. ceres_test(rotation)
  491. ceres_test(schur_complement_solver)
  492. ceres_test(schur_eliminator)
  493. ceres_test(single_linkage_clustering)
  494. ceres_test(small_blas)
  495. ceres_test(solver)
  496. ceres_test(sparse_cholesky)
  497. ceres_test(sparse_normal_cholesky_solver)
  498. ceres_test(subset_preconditioner)
  499. ceres_test(system)
  500. ceres_test(tiny_solver)
  501. ceres_test(tiny_solver_autodiff_function)
  502. ceres_test(tiny_solver_cost_function_adapter)
  503. ceres_test(thread_pool)
  504. ceres_test(triplet_sparse_matrix)
  505. ceres_test(trust_region_minimizer)
  506. ceres_test(trust_region_preprocessor)
  507. ceres_test(visibility)
  508. ceres_test(visibility_based_preconditioner)
  509. add_subdirectory(generated_bundle_adjustment_tests)
  510. endif (BUILD_TESTING AND GFLAGS)
  511. macro(add_dependencies_to_benchmark BENCHMARK_TARGET)
  512. target_include_directories(${BENCHMARK_TARGET}
  513. PRIVATE ${Ceres_SOURCE_DIR}/internal
  514. ${CERES_LIBRARY_PRIVATE_DEPENDENCIES_INCLUDE_DIRS})
  515. # Benchmarks include direct references/includes of private dependency headers
  516. # which are not propagated via the ceres targets, so link them explicitly.
  517. target_link_libraries(${BENCHMARK_TARGET}
  518. PRIVATE benchmark::benchmark ceres_static
  519. ${CERES_LIBRARY_PRIVATE_DEPENDENCIES})
  520. endmacro()
  521. if (BUILD_BENCHMARKS)
  522. add_executable(evaluation_benchmark evaluation_benchmark.cc)
  523. add_dependencies_to_benchmark(evaluation_benchmark)
  524. add_executable(small_blas_gemv_benchmark small_blas_gemv_benchmark.cc)
  525. add_dependencies_to_benchmark(small_blas_gemv_benchmark)
  526. add_executable(small_blas_gemm_benchmark small_blas_gemm_benchmark.cc)
  527. add_dependencies_to_benchmark(small_blas_gemm_benchmark)
  528. add_executable(invert_psd_matrix_benchmark invert_psd_matrix_benchmark.cc)
  529. add_dependencies_to_benchmark(invert_psd_matrix_benchmark)
  530. add_executable(schur_eliminator_benchmark schur_eliminator_benchmark.cc)
  531. add_dependencies_to_benchmark(schur_eliminator_benchmark)
  532. add_executable(jet_operator_benchmark jet_operator_benchmark.cc)
  533. add_dependencies_to_benchmark(jet_operator_benchmark)
  534. add_executable(dense_linear_solver_benchmark dense_linear_solver_benchmark.cc)
  535. add_dependencies_to_benchmark(dense_linear_solver_benchmark)
  536. add_executable(spmv_benchmark spmv_benchmark.cc)
  537. add_dependencies_to_benchmark(spmv_benchmark)
  538. add_executable(parallel_vector_operations_benchmark parallel_vector_operations_benchmark.cc)
  539. add_dependencies_to_benchmark(parallel_vector_operations_benchmark)
  540. add_executable(parallel_for_benchmark parallel_for_benchmark.cc)
  541. add_dependencies_to_benchmark(parallel_for_benchmark)
  542. add_executable(block_jacobi_preconditioner_benchmark
  543. block_jacobi_preconditioner_benchmark.cc)
  544. add_dependencies_to_benchmark(block_jacobi_preconditioner_benchmark)
  545. add_subdirectory(autodiff_benchmarks)
  546. endif (BUILD_BENCHMARKS)