Austin Schuh | 033df09 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 1 | # Ceres Solver - A fast non-linear least squares minimizer |
| 2 | # Copyright 2018 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 | # Support for building Ceres Solver with a specific configuration. |
| 30 | |
| 31 | CERES_SRCS = ["internal/ceres/" + filename for filename in [ |
| 32 | "accelerate_sparse.cc", |
| 33 | "array_utils.cc", |
| 34 | "blas.cc", |
| 35 | "block_evaluate_preparer.cc", |
| 36 | "block_jacobian_writer.cc", |
| 37 | "block_jacobi_preconditioner.cc", |
| 38 | "block_random_access_dense_matrix.cc", |
| 39 | "block_random_access_diagonal_matrix.cc", |
| 40 | "block_random_access_matrix.cc", |
| 41 | "block_random_access_sparse_matrix.cc", |
| 42 | "block_sparse_matrix.cc", |
| 43 | "block_structure.cc", |
| 44 | "c_api.cc", |
| 45 | "callbacks.cc", |
| 46 | "canonical_views_clustering.cc", |
| 47 | "cgnr_solver.cc", |
| 48 | "compressed_col_sparse_matrix_utils.cc", |
| 49 | "compressed_row_jacobian_writer.cc", |
| 50 | "compressed_row_sparse_matrix.cc", |
| 51 | "conditioned_cost_function.cc", |
| 52 | "conjugate_gradients_solver.cc", |
| 53 | "context.cc", |
| 54 | "context_impl.cc", |
| 55 | "coordinate_descent_minimizer.cc", |
| 56 | "corrector.cc", |
| 57 | "covariance.cc", |
| 58 | "covariance_impl.cc", |
| 59 | "dense_normal_cholesky_solver.cc", |
| 60 | "dense_qr_solver.cc", |
| 61 | "dense_sparse_matrix.cc", |
| 62 | "detect_structure.cc", |
| 63 | "dogleg_strategy.cc", |
| 64 | "dynamic_compressed_row_jacobian_writer.cc", |
| 65 | "dynamic_compressed_row_sparse_matrix.cc", |
| 66 | "dynamic_sparse_normal_cholesky_solver.cc", |
| 67 | "eigensparse.cc", |
| 68 | "evaluator.cc", |
| 69 | "file.cc", |
| 70 | "function_sample.cc", |
| 71 | "gradient_checker.cc", |
| 72 | "gradient_checking_cost_function.cc", |
| 73 | "gradient_problem.cc", |
| 74 | "gradient_problem_solver.cc", |
| 75 | "is_close.cc", |
| 76 | "implicit_schur_complement.cc", |
| 77 | "inner_product_computer.cc", |
| 78 | "iterative_refiner.cc", |
| 79 | "iterative_schur_complement_solver.cc", |
| 80 | "lapack.cc", |
| 81 | "levenberg_marquardt_strategy.cc", |
| 82 | "line_search.cc", |
| 83 | "line_search_direction.cc", |
| 84 | "line_search_minimizer.cc", |
| 85 | "linear_least_squares_problems.cc", |
| 86 | "linear_operator.cc", |
| 87 | "line_search_preprocessor.cc", |
| 88 | "linear_solver.cc", |
| 89 | "local_parameterization.cc", |
| 90 | "loss_function.cc", |
| 91 | "low_rank_inverse_hessian.cc", |
| 92 | "minimizer.cc", |
| 93 | "normal_prior.cc", |
| 94 | "parallel_for_cxx.cc", |
| 95 | "parallel_for_openmp.cc", |
| 96 | "parallel_utils.cc", |
| 97 | "parameter_block_ordering.cc", |
| 98 | "partitioned_matrix_view.cc", |
| 99 | "polynomial.cc", |
| 100 | "preconditioner.cc", |
| 101 | "preprocessor.cc", |
| 102 | "problem.cc", |
| 103 | "problem_impl.cc", |
| 104 | "program.cc", |
| 105 | "reorder_program.cc", |
| 106 | "residual_block.cc", |
| 107 | "residual_block_utils.cc", |
| 108 | "schur_complement_solver.cc", |
| 109 | "schur_eliminator.cc", |
| 110 | "schur_jacobi_preconditioner.cc", |
| 111 | "schur_templates.cc", |
| 112 | "scratch_evaluate_preparer.cc", |
| 113 | "single_linkage_clustering.cc", |
| 114 | "solver.cc", |
| 115 | "solver_utils.cc", |
| 116 | "sparse_cholesky.cc", |
| 117 | "sparse_matrix.cc", |
| 118 | "sparse_normal_cholesky_solver.cc", |
| 119 | "split.cc", |
| 120 | "stringprintf.cc", |
| 121 | "subset_preconditioner.cc", |
| 122 | "suitesparse.cc", |
| 123 | "thread_pool.cc", |
| 124 | "thread_token_provider.cc", |
| 125 | "triplet_sparse_matrix.cc", |
| 126 | "trust_region_minimizer.cc", |
| 127 | "trust_region_preprocessor.cc", |
| 128 | "trust_region_step_evaluator.cc", |
| 129 | "trust_region_strategy.cc", |
| 130 | "types.cc", |
| 131 | "visibility_based_preconditioner.cc", |
| 132 | "visibility.cc", |
| 133 | "wall_time.cc", |
| 134 | ]] |
| 135 | |
| 136 | # TODO(rodrigoq): add support to configure Ceres into various permutations, |
| 137 | # like SuiteSparse or not, threading or not, glog or not, and so on. |
| 138 | # See https://github.com/ceres-solver/ceres-solver/issues/335. |
| 139 | def ceres_library(name, |
| 140 | restrict_schur_specializations=False, |
| 141 | gflags_namespace="gflags"): |
| 142 | # The path to internal/ depends on whether Ceres is the main workspace or |
| 143 | # an external repository. |
| 144 | if native.repository_name() != '@': |
| 145 | internal = 'external/%s/internal' % native.repository_name().lstrip('@') |
| 146 | else: |
| 147 | internal = 'internal' |
| 148 | |
| 149 | # The fixed-size Schur eliminator template instantiations incur a large |
| 150 | # binary size penalty, and are slow to compile, so support disabling them. |
| 151 | schur_eliminator_copts = [] |
| 152 | if restrict_schur_specializations: |
| 153 | schur_eliminator_copts.append("-DCERES_RESTRICT_SCHUR_SPECIALIZATION") |
| 154 | schur_sources = [ |
| 155 | "internal/ceres/generated/schur_eliminator_d_d_d.cc", |
| 156 | "internal/ceres/generated/partitioned_matrix_view_d_d_d.cc", |
| 157 | ] |
| 158 | else: |
| 159 | schur_sources = native.glob(["internal/ceres/generated/*.cc"]) |
| 160 | |
| 161 | native.cc_library( |
| 162 | name = name, |
| 163 | |
| 164 | # Internal sources, options, and dependencies. |
| 165 | srcs = CERES_SRCS + schur_sources + native.glob([ |
| 166 | "include/ceres/internal/*.h", |
| 167 | ]) + native.glob([ |
| 168 | "internal/ceres/*.h", |
| 169 | ]), |
| 170 | |
| 171 | # These headers are made available to other targets. |
| 172 | hdrs = |
| 173 | native.glob(["include/ceres/*.h"]) + native.glob([ |
| 174 | "include/ceres/internal/*.h", |
| 175 | ]) + |
| 176 | |
| 177 | # This is an empty config, since the Bazel-based build does not |
| 178 | # generate a config.h from config.h.in. This is fine, since Bazel |
| 179 | # properly handles propagating -D defines to dependent targets. |
| 180 | native.glob([ |
| 181 | "config/ceres/internal/config.h", |
| 182 | ]), |
| 183 | copts = [ |
| 184 | "-I" + internal, |
| 185 | "-Wno-sign-compare", |
| 186 | "-Wno-ignored-qualifiers", |
| 187 | "-Wno-unused-parameter", |
| 188 | "-Wno-format-nonliteral", |
| 189 | ] + schur_eliminator_copts, |
| 190 | |
| 191 | # These include directories and defines are propagated to other targets |
| 192 | # depending on Ceres. |
| 193 | # TODO(keir): These defines are placeholders for now to facilitate getting |
| 194 | # started with a Bazel build. However, these should become configurable as |
| 195 | # part of a Skylark Ceres target macro. |
| 196 | # https://github.com/ceres-solver/ceres-solver/issues/396 |
| 197 | defines = [ |
| 198 | "CERES_NO_SUITESPARSE", |
| 199 | "CERES_NO_CXSPARSE", |
| 200 | "CERES_NO_ACCELERATE_SPARSE", |
| 201 | "CERES_NO_LAPACK", |
| 202 | "CERES_USE_EIGEN_SPARSE", |
| 203 | "CERES_USE_CXX11_THREADS", |
| 204 | "CERES_GFLAGS_NAMESPACE=" + gflags_namespace, |
| 205 | ], |
| 206 | includes = [ |
| 207 | "config", |
| 208 | "include", |
| 209 | ], |
| 210 | visibility = ["//visibility:public"], |
| 211 | deps = [ |
Austin Schuh | 033df09 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 212 | "@com_github_google_glog//:glog", |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 213 | "@org_tuxfamily_eigen//:eigen", |
Austin Schuh | 033df09 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 214 | ], |
| 215 | ) |