CeresCompileOptionsToComponents.cmake 4.5 KB

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