Blame cmake/CeresCompileOptionsToComponents.cmake

Packit ea1746
# Ceres Solver - A fast non-linear least squares minimizer
Packit ea1746
# Copyright 2016 Google Inc. All rights reserved.
Packit ea1746
# http://ceres-solver.org/
Packit ea1746
#
Packit ea1746
# Redistribution and use in source and binary forms, with or without
Packit ea1746
# modification, are permitted provided that the following conditions are met:
Packit ea1746
#
Packit ea1746
# * Redistributions of source code must retain the above copyright notice,
Packit ea1746
#   this list of conditions and the following disclaimer.
Packit ea1746
# * Redistributions in binary form must reproduce the above copyright notice,
Packit ea1746
#   this list of conditions and the following disclaimer in the documentation
Packit ea1746
#   and/or other materials provided with the distribution.
Packit ea1746
# * Neither the name of Google Inc. nor the names of its contributors may be
Packit ea1746
#   used to endorse or promote products derived from this software without
Packit ea1746
#   specific prior written permission.
Packit ea1746
#
Packit ea1746
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit ea1746
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit ea1746
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit ea1746
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Packit ea1746
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit ea1746
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit ea1746
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit ea1746
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit ea1746
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit ea1746
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit ea1746
# POSSIBILITY OF SUCH DAMAGE.
Packit ea1746
#
Packit ea1746
# Authors: alexs.mac@gmail.com (Alex Stewart)
Packit ea1746
#
Packit ea1746
Packit ea1746
# Conditionally add a value to the output list based on whether the specified
Packit ea1746
# value is found in the input list.
Packit ea1746
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)
Packit ea1746
  list(FIND ${INPUT_LIST_VAR} "${ITEM_TO_FIND}" HAVE_ITEM)
Packit ea1746
  # list(FIND ..) returns -1 if the element was not in the list, but CMake
Packit ea1746
  # interprets if (VAR) to be true if VAR is any non-zero number, even
Packit ea1746
  # negative ones, hence we have to explicitly check for >= 0.
Packit ea1746
  if (HAVE_ITEM GREATER -1)
Packit ea1746
    list(APPEND ${OUTPUT_LIST_VAR} "${VAR_TO_COPY_IF_FOUND}")
Packit ea1746
  else()
Packit ea1746
    list(APPEND ${OUTPUT_LIST_VAR} "${VAR_TO_COPY_IF_NOT_FOUND}")
Packit ea1746
  endif()
Packit ea1746
  set(${OUTPUT_LIST_VAR} ${${OUTPUT_LIST_VAR}} PARENT_SCOPE)
Packit ea1746
endfunction()
Packit ea1746
Packit ea1746
# Helpers for update_output_if_found() to improve legibility when dealing with
Packit ea1746
# USE_XXX & NO_XXX option types in ceres_compile_options_to_components().
Packit ea1746
macro(add_to_output_if_found INPUT_LIST_VAR OUTPUT_LIST_VAR ITEM_TO_FIND VAR_TO_COPY_IF_FOUND)
Packit ea1746
  update_output_if_found(${INPUT_LIST_VAR}
Packit ea1746
    ${OUTPUT_LIST_VAR}
Packit ea1746
    "${ITEM_TO_FIND}"
Packit ea1746
    "${VAR_TO_COPY_IF_FOUND}"
Packit ea1746
    "") # Copy nothing if not found.
Packit ea1746
endmacro()
Packit ea1746
Packit ea1746
macro(add_to_output_if_not_found INPUT_LIST_VAR OUTPUT_LIST_VAR ITEM_TO_FIND VAR_TO_COPY_IF_NOT_FOUND)
Packit ea1746
  update_output_if_found(${INPUT_LIST_VAR}
Packit ea1746
    ${OUTPUT_LIST_VAR}
Packit ea1746
    "${ITEM_TO_FIND}"
Packit ea1746
    "" # Copy nothing if found
Packit ea1746
    "${VAR_TO_COPY_IF_NOT_FOUND}")
Packit ea1746
endmacro()
Packit ea1746
Packit ea1746
# Convert the Ceres compile options specified by: CURRENT_CERES_COMPILE_OPTIONS
Packit ea1746
# into the correponding list of Ceres components (names), which may be used in:
Packit ea1746
# find_package(Ceres COMPONENTS <XXX>).
Packit ea1746
function(ceres_compile_options_to_components CURRENT_CERES_COMPILE_OPTIONS CERES_COMPONENTS_VAR)
Packit ea1746
  # To enable users to specify that they want *a* sparse linear algebra backend
Packit ea1746
  # without having to specify explicitly which one, for each sparse library we
Packit ea1746
  # add the 'meta-module': SparseLinearAlgebraLibrary in addition to their own
Packit ea1746
  # module name.
Packit ea1746
  add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
Packit ea1746
    CERES_USE_EIGEN_SPARSE "EigenSparse;SparseLinearAlgebraLibrary")
Packit ea1746
  add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
Packit ea1746
    CERES_NO_LAPACK "LAPACK")
Packit ea1746
  add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
Packit ea1746
    CERES_NO_SUITESPARSE "SuiteSparse;SparseLinearAlgebraLibrary")
Packit ea1746
  add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
Packit ea1746
    CERES_NO_CXSPARSE "CXSparse;SparseLinearAlgebraLibrary")
Packit ea1746
  add_to_output_if_not_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
Packit ea1746
    CERES_RESTRICT_SCHUR_SPECIALIZATION "SchurSpecializations")
Packit ea1746
  add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
Packit ea1746
    CERES_USE_CXX11 "C++11")
Packit ea1746
  add_to_output_if_found(CURRENT_CERES_COMPILE_OPTIONS ${CERES_COMPONENTS_VAR}
Packit ea1746
    CERES_USE_OPENMP "OpenMP")
Packit ea1746
  # Remove duplicates of SparseLinearAlgebraLibrary if multiple sparse backends
Packit ea1746
  # are present.
Packit ea1746
  list(REMOVE_DUPLICATES ${CERES_COMPONENTS_VAR})
Packit ea1746
  set(${CERES_COMPONENTS_VAR} "${${CERES_COMPONENTS_VAR}}" PARENT_SCOPE)
Packit ea1746
endfunction()