Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame^] | 1 | # Ceres Solver - A fast non-linear least squares minimizer |
| 2 | # Copyright 2016 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 | # Authors: alexs.mac@gmail.com (Alex Stewart) |
| 30 | # |
| 31 | |
| 32 | # Conditionally add a value to the output list based on whether the specified |
| 33 | # value is found in the input list. |
| 34 | function(update_output_if_found INPUT_LIST_VAR OUTPUT_LIST_VAR ITEM_TO_FIND VAR_TO_COPY_IF_FOUND VAR_TO_COPY_IF_NOT_FOUND) |
| 35 | list(FIND ${INPUT_LIST_VAR} "${ITEM_TO_FIND}" HAVE_ITEM) |
| 36 | # list(FIND ..) returns -1 if the element was not in the list, but CMake |
| 37 | # interprets if (VAR) to be true if VAR is any non-zero number, even |
| 38 | # negative ones, hence we have to explicitly check for >= 0. |
| 39 | if (HAVE_ITEM GREATER -1) |
| 40 | list(APPEND ${OUTPUT_LIST_VAR} "${VAR_TO_COPY_IF_FOUND}") |
| 41 | else() |
| 42 | list(APPEND ${OUTPUT_LIST_VAR} "${VAR_TO_COPY_IF_NOT_FOUND}") |
| 43 | endif() |
| 44 | set(${OUTPUT_LIST_VAR} ${${OUTPUT_LIST_VAR}} PARENT_SCOPE) |
| 45 | endfunction() |
| 46 | |
| 47 | # Helpers for update_output_if_found() to improve legibility when dealing with |
| 48 | # USE_XXX & NO_XXX option types in ceres_compile_options_to_components(). |
| 49 | macro(add_to_output_if_found INPUT_LIST_VAR OUTPUT_LIST_VAR ITEM_TO_FIND VAR_TO_COPY_IF_FOUND) |
| 50 | update_output_if_found(${INPUT_LIST_VAR} |
| 51 | ${OUTPUT_LIST_VAR} |
| 52 | "${ITEM_TO_FIND}" |
| 53 | "${VAR_TO_COPY_IF_FOUND}" |
| 54 | "") # Copy nothing if not found. |
| 55 | endmacro() |
| 56 | |
| 57 | macro(add_to_output_if_not_found INPUT_LIST_VAR OUTPUT_LIST_VAR ITEM_TO_FIND VAR_TO_COPY_IF_NOT_FOUND) |
| 58 | update_output_if_found(${INPUT_LIST_VAR} |
| 59 | ${OUTPUT_LIST_VAR} |
| 60 | "${ITEM_TO_FIND}" |
| 61 | "" # Copy nothing if found |
| 62 | "${VAR_TO_COPY_IF_NOT_FOUND}") |
| 63 | endmacro() |
| 64 | |
| 65 | # Convert the Ceres compile options specified by: CURRENT_CERES_COMPILE_OPTIONS |
| 66 | # into the corresponding list of Ceres components (names), which may be used in: |
| 67 | # find_package(Ceres COMPONENTS <XXX>). |
| 68 | function(ceres_compile_options_to_components CURRENT_CERES_COMPILE_OPTIONS CERES_COMPONENTS_VAR) |
| 69 | # To enable users to specify that they want *a* sparse linear algebra backend |
| 70 | # without having to specify explicitly which one, for each sparse library we |
| 71 | # add the 'meta-module': SparseLinearAlgebraLibrary in addition to their own |
| 72 | # module name. |
| 73 | add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} |
| 74 | CERES_USE_EIGEN_SPARSE "EigenSparse;SparseLinearAlgebraLibrary") |
| 75 | add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} |
| 76 | CERES_NO_LAPACK "LAPACK") |
| 77 | add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} |
| 78 | CERES_NO_SUITESPARSE "SuiteSparse;SparseLinearAlgebraLibrary") |
| 79 | add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} |
| 80 | CERES_NO_CXSPARSE "CXSparse;SparseLinearAlgebraLibrary") |
| 81 | add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} |
| 82 | CERES_NO_ACCELERATE_SPARSE "AccelerateSparse;SparseLinearAlgebraLibrary") |
| 83 | add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} |
| 84 | CERES_RESTRICT_SCHUR_SPECIALIZATION "SchurSpecializations") |
| 85 | add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR} |
| 86 | CERES_USE_OPENMP "OpenMP;Multithreading") |
| 87 | # Remove duplicates of SparseLinearAlgebraLibrary if multiple sparse backends |
| 88 | # are present. |
| 89 | list(REMOVE_DUPLICATES ${CERES_COMPONENTS_VAR}) |
| 90 | set(${CERES_COMPONENTS_VAR} "${${CERES_COMPONENTS_VAR}}" PARENT_SCOPE) |
| 91 | endfunction() |