Blame cmake/CeresConfig.cmake.in

Packit ea1746
# Ceres Solver - A fast non-linear least squares minimizer
Packit ea1746
# Copyright 2015 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: pablo.speciale@gmail.com (Pablo Speciale)
Packit ea1746
#          alexs.mac@gmail.com (Alex Stewart)
Packit ea1746
#
Packit ea1746
Packit ea1746
# Config file for Ceres Solver - Find Ceres & dependencies.
Packit ea1746
#
Packit ea1746
# This file is used by CMake when find_package(Ceres) is invoked and either
Packit ea1746
# the directory containing this file either is present in CMAKE_MODULE_PATH
Packit ea1746
# (if Ceres was installed), or exists in the local CMake package registry if
Packit ea1746
# the Ceres build directory was exported.
Packit ea1746
#
Packit ea1746
# This module defines the following variables:
Packit ea1746
#
Packit ea1746
# Ceres_FOUND / CERES_FOUND: True if Ceres has been successfully
Packit ea1746
#                            found. Both variables are set as although
Packit ea1746
#                            FindPackage() only references Ceres_FOUND
Packit ea1746
#                            in Config mode, given the conventions for
Packit ea1746
#                            <package>_FOUND when FindPackage() is
Packit ea1746
#                            called in Module mode, users could
Packit ea1746
#                            reasonably expect to use CERES_FOUND
Packit ea1746
#                            instead.
Packit ea1746
#
Packit ea1746
# CERES_VERSION: Version of Ceres found.
Packit ea1746
#
Packit ea1746
# CERES_INCLUDE_DIRS: Include directories for Ceres and the
Packit ea1746
#                     dependencies which appear in the Ceres public
Packit ea1746
#                     API and are thus required to use Ceres.
Packit ea1746
#
Packit ea1746
# CERES_LIBRARIES: Libraries for Ceres and all
Packit ea1746
#                  dependencies against which Ceres was
Packit ea1746
#                  compiled. This will not include any optional
Packit ea1746
#                  dependencies that were disabled when Ceres was
Packit ea1746
#                  compiled.
Packit ea1746
#
Packit ea1746
# The following variables are also defined for legacy compatibility
Packit ea1746
# only.  Any new code should not use them as they do not conform to
Packit ea1746
# the standard CMake FindPackage naming conventions.
Packit ea1746
#
Packit ea1746
# CERES_INCLUDES = ${CERES_INCLUDE_DIRS}.
Packit ea1746
Packit ea1746
# Called if we failed to find Ceres or any of its required dependencies,
Packit ea1746
# unsets all public (designed to be used externally) variables and reports
Packit ea1746
# error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument.
Packit ea1746
macro(CERES_REPORT_NOT_FOUND REASON_MSG)
Packit ea1746
  # FindPackage() only references Ceres_FOUND, and requires it to be
Packit ea1746
  # explicitly set FALSE to denote not found (not merely undefined).
Packit ea1746
  set(Ceres_FOUND FALSE)
Packit ea1746
  set(CERES_FOUND FALSE)
Packit ea1746
  unset(CERES_INCLUDE_DIRS)
Packit ea1746
  unset(CERES_LIBRARIES)
Packit ea1746
Packit ea1746
  # Reset the CMake module path to its state when this script was called.
Packit ea1746
  set(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH})
Packit ea1746
Packit ea1746
  # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by
Packit ea1746
  # FindPackage() use the camelcase library name, not uppercase.
Packit ea1746
  if (Ceres_FIND_QUIETLY)
Packit ea1746
    message(STATUS "Failed to find Ceres - " ${REASON_MSG} ${ARGN})
Packit ea1746
  elseif (Ceres_FIND_REQUIRED)
Packit ea1746
    message(FATAL_ERROR "Failed to find Ceres - " ${REASON_MSG} ${ARGN})
Packit ea1746
  else()
Packit ea1746
    # Neither QUIETLY nor REQUIRED, use SEND_ERROR which emits an error
Packit ea1746
    # that prevents generation, but continues configuration.
Packit ea1746
    message(SEND_ERROR "Failed to find Ceres - " ${REASON_MSG} ${ARGN})
Packit ea1746
  endif ()
Packit ea1746
  return()
Packit ea1746
endmacro(CERES_REPORT_NOT_FOUND)
Packit ea1746
Packit ea1746
# ceres_pretty_print_cmake_list( OUTPUT_VAR [item1 [item2 ... ]] )
Packit ea1746
#
Packit ea1746
# Sets ${OUTPUT_VAR} in the caller's scope to a human-readable string
Packit ea1746
# representation of the list passed as the remaining arguments formed
Packit ea1746
# as: "[item1, item2, ..., itemN]".
Packit ea1746
function(ceres_pretty_print_cmake_list OUTPUT_VAR)
Packit ea1746
  string(REPLACE ";" ", " PRETTY_LIST_STRING "[${ARGN}]")
Packit ea1746
  set(${OUTPUT_VAR} "${PRETTY_LIST_STRING}" PARENT_SCOPE)
Packit ea1746
endfunction()
Packit ea1746
Packit ea1746
# The list of (optional) components this version of Ceres was compiled with.
Packit ea1746
set(CERES_COMPILED_COMPONENTS "@CERES_COMPILED_COMPONENTS@")
Packit ea1746
Packit ea1746
# If Ceres was not installed, then by definition it was exported
Packit ea1746
# from a build directory.
Packit ea1746
set(CERES_WAS_INSTALLED @SETUP_CERES_CONFIG_FOR_INSTALLATION@)
Packit ea1746
Packit ea1746
# Record the state of the CMake module path when this script was
Packit ea1746
# called so that we can ensure that we leave it in the same state on
Packit ea1746
# exit as it was on entry, but modify it locally.
Packit ea1746
set(CALLERS_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
Packit ea1746
Packit ea1746
# Get the (current, i.e. installed) directory containing this file.
Packit ea1746
get_filename_component(CERES_CURRENT_CONFIG_DIR
Packit ea1746
  "${CMAKE_CURRENT_LIST_FILE}" PATH)
Packit ea1746
Packit ea1746
if (CERES_WAS_INSTALLED)
Packit ea1746
  # Reset CMake module path to the installation directory of this
Packit ea1746
  # script, thus we will use the FindPackage() scripts shipped with
Packit ea1746
  # Ceres to find Ceres' dependencies, even if the user has equivalently
Packit ea1746
  # named FindPackage() scripts in their project.
Packit ea1746
  set(CMAKE_MODULE_PATH ${CERES_CURRENT_CONFIG_DIR})
Packit ea1746
Packit ea1746
  # Build the absolute root install directory as a relative path
Packit ea1746
  # (determined when Ceres was configured & built) from the current
Packit ea1746
  # install directory for this this file.  This allows for the install
Packit ea1746
  # tree to be relocated, after Ceres was built, outside of CMake.
Packit ea1746
  get_filename_component(CURRENT_ROOT_INSTALL_DIR
Packit ea1746
    ${CERES_CURRENT_CONFIG_DIR}/@INSTALL_ROOT_REL_CONFIG_INSTALL_DIR@
Packit ea1746
    ABSOLUTE)
Packit ea1746
  if (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR})
Packit ea1746
    ceres_report_not_found(
Packit ea1746
      "Ceres install root: ${CURRENT_ROOT_INSTALL_DIR}, "
Packit ea1746
      "determined from relative path from CeresConfig.cmake install location: "
Packit ea1746
      "${CERES_CURRENT_CONFIG_DIR}, does not exist. Either the install "
Packit ea1746
      "directory was deleted, or the install tree was only partially relocated "
Packit ea1746
      "outside of CMake after Ceres was built.")
Packit ea1746
  endif (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR})
Packit ea1746
Packit ea1746
  # Set the include directories for Ceres (itself).
Packit ea1746
  set(CERES_INCLUDE_DIR "${CURRENT_ROOT_INSTALL_DIR}/include")
Packit ea1746
  if (NOT EXISTS ${CERES_INCLUDE_DIR}/ceres/ceres.h)
Packit ea1746
    ceres_report_not_found(
Packit ea1746
      "Ceres install root: ${CURRENT_ROOT_INSTALL_DIR}, "
Packit ea1746
      "determined from relative path from CeresConfig.cmake install location: "
Packit ea1746
      "${CERES_CURRENT_CONFIG_DIR}, does not contain Ceres headers. "
Packit ea1746
      "Either the install directory was deleted, or the install tree was only "
Packit ea1746
      "partially relocated outside of CMake after Ceres was built.")
Packit ea1746
  endif (NOT EXISTS ${CERES_INCLUDE_DIR}/ceres/ceres.h)
Packit ea1746
  list(APPEND CERES_INCLUDE_DIRS ${CERES_INCLUDE_DIR})
Packit ea1746
Packit ea1746
else(CERES_WAS_INSTALLED)
Packit ea1746
  # Ceres was exported from the build tree.
Packit ea1746
  set(CERES_EXPORTED_BUILD_DIR ${CERES_CURRENT_CONFIG_DIR})
Packit ea1746
  get_filename_component(CERES_EXPORTED_SOURCE_DIR
Packit ea1746
    ${CERES_EXPORTED_BUILD_DIR}/@INSTALL_ROOT_REL_CONFIG_INSTALL_DIR@
Packit ea1746
    ABSOLUTE)
Packit ea1746
  if (NOT EXISTS ${CERES_EXPORTED_SOURCE_DIR})
Packit ea1746
    ceres_report_not_found(
Packit ea1746
      "Ceres exported source directory: ${CERES_EXPORTED_SOURCE_DIR}, "
Packit ea1746
      "determined from relative path from CeresConfig.cmake exported build "
Packit ea1746
      "directory: ${CERES_EXPORTED_BUILD_DIR} does not exist.")
Packit ea1746
  endif()
Packit ea1746
Packit ea1746
  # Reset CMake module path to the cmake directory in the Ceres source
Packit ea1746
  # tree which was exported, thus we will use the FindPackage() scripts shipped
Packit ea1746
  # with Ceres to find Ceres' dependencies, even if the user has equivalently
Packit ea1746
  # named FindPackage() scripts in their project.
Packit ea1746
  set(CMAKE_MODULE_PATH ${CERES_EXPORTED_SOURCE_DIR}/cmake)
Packit ea1746
Packit ea1746
  # Set the include directories for Ceres (itself).
Packit ea1746
  set(CERES_INCLUDE_DIR "${CERES_EXPORTED_SOURCE_DIR}/include")
Packit ea1746
  if (NOT EXISTS ${CERES_INCLUDE_DIR}/ceres/ceres.h)
Packit ea1746
    ceres_report_not_found(
Packit ea1746
      "Ceres exported source directory: ${CERES_EXPORTED_SOURCE_DIR}, "
Packit ea1746
      "determined from relative path from CeresConfig.cmake exported build "
Packit ea1746
      "directory: ${CERES_EXPORTED_BUILD_DIR}, does not contain Ceres headers.")
Packit ea1746
  endif (NOT EXISTS ${CERES_INCLUDE_DIR}/ceres/ceres.h)
Packit ea1746
  list(APPEND CERES_INCLUDE_DIRS ${CERES_INCLUDE_DIR})
Packit ea1746
Packit ea1746
  # Append the path to the configured config.h in the exported build directory
Packit ea1746
  # to the Ceres include directories.
Packit ea1746
  set(CERES_CONFIG_FILE
Packit ea1746
    ${CERES_EXPORTED_BUILD_DIR}/config/ceres/internal/config.h)
Packit ea1746
  if (NOT EXISTS ${CERES_CONFIG_FILE})
Packit ea1746
    ceres_report_not_found(
Packit ea1746
      "Ceres exported build directory: ${CERES_EXPORTED_BUILD_DIR}, "
Packit ea1746
      "does not contain required configured Ceres config.h, it is not here: "
Packit ea1746
      "${CERES_CONFIG_FILE}.")
Packit ea1746
  endif (NOT EXISTS ${CERES_CONFIG_FILE})
Packit ea1746
  list(APPEND CERES_INCLUDE_DIRS ${CERES_EXPORTED_BUILD_DIR}/config)
Packit ea1746
endif(CERES_WAS_INSTALLED)
Packit ea1746
Packit ea1746
# Set the version.
Packit ea1746
set(CERES_VERSION @CERES_VERSION@ )
Packit ea1746
Packit ea1746
# Eigen.
Packit ea1746
# Flag set during configuration and build of Ceres.
Packit ea1746
set(CERES_EIGEN_VERSION @EIGEN_VERSION@)
Packit ea1746
set(EIGEN_WAS_BUILT_WITH_CMAKE @FOUND_INSTALLED_EIGEN_CMAKE_CONFIGURATION@)
Packit ea1746
# Append the locations of Eigen when Ceres was built to the search path hints.
Packit ea1746
if (EIGEN_WAS_BUILT_WITH_CMAKE)
Packit ea1746
  set(Eigen3_DIR @Eigen3_DIR@)
Packit ea1746
  set(EIGEN_PREFER_EXPORTED_EIGEN_CMAKE_CONFIGURATION TRUE)
Packit ea1746
else()
Packit ea1746
  list(APPEND EIGEN_INCLUDE_DIR_HINTS @EIGEN_INCLUDE_DIR@)
Packit ea1746
endif()
Packit ea1746
# Search quietly to control the timing of the error message if not found. The
Packit ea1746
# search should be for an exact match, but for usability reasons do a soft
Packit ea1746
# match and reject with an explanation below.
Packit ea1746
find_package(Eigen ${CERES_EIGEN_VERSION} QUIET)
Packit ea1746
if (EIGEN_FOUND)
Packit ea1746
  if (NOT EIGEN_VERSION VERSION_EQUAL CERES_EIGEN_VERSION)
Packit ea1746
    # CMake's VERSION check in FIND_PACKAGE() will accept any version >= the
Packit ea1746
    # specified version. However, only version = is supported. Improve
Packit ea1746
    # usability by explaining why we don't accept non-exact version matching.
Packit ea1746
    ceres_report_not_found("Found Eigen dependency, but the version of Eigen "
Packit ea1746
      "found (${EIGEN_VERSION}) does not exactly match the version of Eigen "
Packit ea1746
      "Ceres was compiled with (${CERES_EIGEN_VERSION}). This can cause subtle "
Packit ea1746
      "bugs by triggering violations of the One Definition Rule. See the "
Packit ea1746
      "Wikipedia article http://en.wikipedia.org/wiki/One_Definition_Rule "
Packit ea1746
      "for more details")
Packit ea1746
  endif ()
Packit ea1746
  message(STATUS "Found required Ceres dependency: "
Packit ea1746
    "Eigen version ${CERES_EIGEN_VERSION} in ${EIGEN_INCLUDE_DIRS}")
Packit ea1746
else (EIGEN_FOUND)
Packit ea1746
  ceres_report_not_found("Missing required Ceres "
Packit ea1746
    "dependency: Eigen version ${CERES_EIGEN_VERSION}, please set "
Packit ea1746
    "EIGEN_INCLUDE_DIR.")
Packit ea1746
endif (EIGEN_FOUND)
Packit ea1746
list(APPEND CERES_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS})
Packit ea1746
Packit ea1746
# Glog.
Packit ea1746
# Flag set during configuration and build of Ceres.
Packit ea1746
set(CERES_USES_MINIGLOG @MINIGLOG@)
Packit ea1746
set(CERES_USES_GFLAGS @GFLAGS@)
Packit ea1746
if (CERES_USES_MINIGLOG)
Packit ea1746
  set(MINIGLOG_INCLUDE_DIR ${CERES_INCLUDE_DIR}/ceres/internal/miniglog)
Packit ea1746
  if (NOT CERES_WAS_INSTALLED)
Packit ea1746
    # When Ceres was exported from the build tree, the miniglog headers
Packit ea1746
    # will be in Ceres internal source directory, not in the public headers
Packit ea1746
    # directory (they are copied with the public headers when installed).
Packit ea1746
    set(MINIGLOG_INCLUDE_DIR
Packit ea1746
      ${CERES_EXPORTED_SOURCE_DIR}/internal/ceres/miniglog)
Packit ea1746
  endif()
Packit ea1746
  if (NOT EXISTS ${MINIGLOG_INCLUDE_DIR})
Packit ea1746
    ceres_report_not_found(
Packit ea1746
      "Failed to find miniglog headers in expected include directory: "
Packit ea1746
      "${MINIGLOG_INCLUDE_DIR}, but Ceres was compiled with MINIGLOG enabled "
Packit ea1746
      "(in place of glog).")
Packit ea1746
  endif (NOT EXISTS ${MINIGLOG_INCLUDE_DIR})
Packit ea1746
  list(APPEND CERES_INCLUDE_DIRS ${MINIGLOG_INCLUDE_DIR})
Packit ea1746
  # Output message at standard log level (not the lower STATUS) so that
Packit ea1746
  # the message is output in GUI during configuration to warn user.
Packit ea1746
  message("-- Found Ceres compiled with miniglog substitute "
Packit ea1746
    "for glog, beware this will likely cause problems if glog is later linked.")
Packit ea1746
else (CERES_USES_MINIGLOG)
Packit ea1746
  # Append the locations of glog when Ceres was built to the search path hints.
Packit ea1746
  set(GLOG_WAS_BUILT_WITH_CMAKE @FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION@)
Packit ea1746
  if (GLOG_WAS_BUILT_WITH_CMAKE)
Packit ea1746
    set(glog_DIR @glog_DIR@)
Packit ea1746
    set(GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION TRUE)
Packit ea1746
  else()
Packit ea1746
    list(APPEND GLOG_INCLUDE_DIR_HINTS @GLOG_INCLUDE_DIR@)
Packit ea1746
    get_filename_component(CERES_BUILD_GLOG_LIBRARY_DIR @GLOG_LIBRARY@ PATH)
Packit ea1746
    list(APPEND GLOG_LIBRARY_DIR_HINTS ${CERES_BUILD_GLOG_LIBRARY_DIR})
Packit ea1746
  endif()
Packit ea1746
Packit ea1746
  # Search quietly s/t we control the timing of the error message if not found.
Packit ea1746
  find_package(Glog QUIET)
Packit ea1746
  if (GLOG_FOUND)
Packit ea1746
    message(STATUS "Found required Ceres dependency: glog")
Packit ea1746
  else (GLOG_FOUND)
Packit ea1746
    ceres_report_not_found("Missing required Ceres "
Packit ea1746
      "dependency: glog. Searched using GLOG_INCLUDE_DIR_HINTS: "
Packit ea1746
      "${GLOG_INCLUDE_DIR_HINTS} and glog_DIR: ${glog_DIR}.")
Packit ea1746
  endif (GLOG_FOUND)
Packit ea1746
  list(APPEND CERES_INCLUDE_DIRS ${GLOG_INCLUDE_DIRS})
Packit ea1746
Packit ea1746
  # gflags is only a public dependency of Ceres via glog, thus is not required
Packit ea1746
  # if Ceres was built with MINIGLOG.
Packit ea1746
  if (CERES_USES_GFLAGS)
Packit ea1746
    # If gflags was found as an imported CMake target, we need to call
Packit ea1746
    # find_packge(Gflags) again here, as imported CMake targets are not
Packit ea1746
    # re-exported.  Without this, the 'gflags-shared' target name which is
Packit ea1746
    # present in CERES_LIBRARIES in this case would not be defined, and so
Packit ea1746
    # CMake will assume it is a library name (which it is not) and fail to link.
Packit ea1746
    #
Packit ea1746
    # Append the locations of gflags when Ceres was built to the search path
Packit ea1746
    # hints.
Packit ea1746
    set(GFLAGS_WAS_BUILT_WITH_CMAKE @FOUND_INSTALLED_GFLAGS_CMAKE_CONFIGURATION@)
Packit ea1746
    if (GFLAGS_WAS_BUILT_WITH_CMAKE)
Packit ea1746
      set(gflags_DIR @gflags_DIR@)
Packit ea1746
      set(GFLAGS_PREFER_EXPORTED_GFLAGS_CMAKE_CONFIGURATION TRUE)
Packit ea1746
    else()
Packit ea1746
      list(APPEND GFLAGS_INCLUDE_DIR_HINTS @GFLAGS_INCLUDE_DIR@)
Packit ea1746
      get_filename_component(CERES_BUILD_GFLAGS_LIBRARY_DIR @GFLAGS_LIBRARY@ PATH)
Packit ea1746
      list(APPEND GFLAGS_LIBRARY_DIR_HINTS ${CERES_BUILD_GFLAGS_LIBRARY_DIR})
Packit ea1746
    endif()
Packit ea1746
Packit ea1746
    # Search quietly s/t we control the timing of the error message if not found.
Packit ea1746
    find_package(Gflags QUIET)
Packit ea1746
    if (GFLAGS_FOUND)
Packit ea1746
      message(STATUS "Found required Ceres dependency: gflags")
Packit ea1746
    else()
Packit ea1746
      ceres_report_not_found("Missing required Ceres "
Packit ea1746
        "dependency: gflags. Searched using GFLAGS_INCLUDE_DIR_HINTS: "
Packit ea1746
        "${GFLAGS_INCLUDE_DIR_HINTS} and gflags_DIR: ${gflags_DIR}.")
Packit ea1746
    endif()
Packit ea1746
    list(APPEND CERES_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR_HINTS})
Packit ea1746
  endif()
Packit ea1746
endif (CERES_USES_MINIGLOG)
Packit ea1746
Packit ea1746
# Import exported Ceres targets, if they have not already been imported.
Packit ea1746
if (NOT TARGET ceres AND NOT Ceres_BINARY_DIR)
Packit ea1746
  include(${CERES_CURRENT_CONFIG_DIR}/CeresTargets.cmake)
Packit ea1746
endif (NOT TARGET ceres AND NOT Ceres_BINARY_DIR)
Packit ea1746
# Set the expected XX_LIBRARIES variable for FindPackage().
Packit ea1746
set(CERES_LIBRARIES ceres)
Packit ea1746
Packit ea1746
# Make user aware of any compile flags that will be added to their targets
Packit ea1746
# which use Ceres (i.e. flags exported in the Ceres target).  Only CMake
Packit ea1746
# versions >= 2.8.12 support target_compile_options().
Packit ea1746
if (TARGET ${CERES_LIBRARIES} AND
Packit ea1746
    NOT CMAKE_VERSION VERSION_LESS "2.8.12")
Packit ea1746
  get_target_property(CERES_INTERFACE_COMPILE_OPTIONS
Packit ea1746
    ${CERES_LIBRARIES} INTERFACE_COMPILE_OPTIONS)
Packit ea1746
Packit ea1746
  if (CERES_WAS_INSTALLED)
Packit ea1746
    set(CERES_LOCATION "${CURRENT_ROOT_INSTALL_DIR}")
Packit ea1746
  else()
Packit ea1746
    set(CERES_LOCATION "${CERES_EXPORTED_BUILD_DIR}")
Packit ea1746
  endif()
Packit ea1746
Packit ea1746
  # Check for -std=c++11 flags.
Packit ea1746
  if (CERES_INTERFACE_COMPILE_OPTIONS MATCHES ".*std=c\\+\\+11.*")
Packit ea1746
    message(STATUS "Ceres version ${CERES_VERSION} detected here: "
Packit ea1746
      "${CERES_LOCATION} was built with C++11. Ceres target will add "
Packit ea1746
      "C++11 flags to compile options for targets using it.")
Packit ea1746
  endif()
Packit ea1746
endif()
Packit ea1746
Packit ea1746
# Set legacy include directories variable for backwards compatibility.
Packit ea1746
set(CERES_INCLUDES ${CERES_INCLUDE_DIRS})
Packit ea1746
Packit ea1746
# Reset CMake module path to its state when this script was called.
Packit ea1746
set(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH})
Packit ea1746
Packit ea1746
# Build the detected Ceres version string to correctly capture whether it
Packit ea1746
# was installed, or exported.
Packit ea1746
ceres_pretty_print_cmake_list(CERES_COMPILED_COMPONENTS_STRING
Packit ea1746
  ${CERES_COMPILED_COMPONENTS})
Packit ea1746
if (CERES_WAS_INSTALLED)
Packit ea1746
  set(CERES_DETECTED_VERSION_STRING "Ceres version: ${CERES_VERSION} "
Packit ea1746
    "installed in: ${CURRENT_ROOT_INSTALL_DIR} with components: "
Packit ea1746
    "${CERES_COMPILED_COMPONENTS_STRING}")
Packit ea1746
else (CERES_WAS_INSTALLED)
Packit ea1746
  set(CERES_DETECTED_VERSION_STRING "Ceres version: ${CERES_VERSION} "
Packit ea1746
    "exported from build directory: ${CERES_EXPORTED_BUILD_DIR} with "
Packit ea1746
    "components: ${CERES_COMPILED_COMPONENTS_STRING}")
Packit ea1746
endif()
Packit ea1746
Packit ea1746
# If the user called this script through find_package() whilst specifying
Packit ea1746
# particular Ceres components that should be found via:
Packit ea1746
# find_package(Ceres COMPONENTS XXX YYY), check the requested components against
Packit ea1746
# those with which Ceres was compiled.  In this case, we should only report
Packit ea1746
# Ceres as found if all the requested components have been found.
Packit ea1746
if (Ceres_FIND_COMPONENTS)
Packit ea1746
  foreach (REQUESTED_COMPONENT ${Ceres_FIND_COMPONENTS})
Packit ea1746
    list(FIND CERES_COMPILED_COMPONENTS ${REQUESTED_COMPONENT} HAVE_REQUESTED_COMPONENT)
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_REQUESTED_COMPONENT EQUAL -1)
Packit ea1746
      # Check for the presence of all requested components before reporting
Packit ea1746
      # not found, such that we report all of the missing components rather
Packit ea1746
      # than just the first.
Packit ea1746
      list(APPEND MISSING_CERES_COMPONENTS ${REQUESTED_COMPONENT})
Packit ea1746
    endif()
Packit ea1746
  endforeach()
Packit ea1746
  if (MISSING_CERES_COMPONENTS)
Packit ea1746
    ceres_pretty_print_cmake_list(REQUESTED_CERES_COMPONENTS_STRING
Packit ea1746
      ${Ceres_FIND_COMPONENTS})
Packit ea1746
    ceres_pretty_print_cmake_list(MISSING_CERES_COMPONENTS_STRING
Packit ea1746
      ${MISSING_CERES_COMPONENTS})
Packit ea1746
    ceres_report_not_found("Missing requested Ceres components: "
Packit ea1746
      "${MISSING_CERES_COMPONENTS_STRING} (components requested: "
Packit ea1746
      "${REQUESTED_CERES_COMPONENTS_STRING}). Detected "
Packit ea1746
      "${CERES_DETECTED_VERSION_STRING}.")
Packit ea1746
  endif()
Packit ea1746
endif()
Packit ea1746
Packit ea1746
# As we use CERES_REPORT_NOT_FOUND() to abort, if we reach this point we have
Packit ea1746
# found Ceres and all required dependencies.
Packit ea1746
message(STATUS "Found " ${CERES_DETECTED_VERSION_STRING})
Packit ea1746
Packit ea1746
# Set CERES_FOUND to be equivalent to Ceres_FOUND, which is set to
Packit ea1746
# TRUE by FindPackage() if this file is found and run, and after which
Packit ea1746
# Ceres_FOUND is not (explicitly, i.e. undefined does not count) set
Packit ea1746
# to FALSE.
Packit ea1746
set(CERES_FOUND TRUE)