• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Ceres Solver - A fast non-linear least squares minimizer
2# Copyright 2013 Google Inc. All rights reserved.
3# http://code.google.com/p/ceres-solver/
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: pablo.speciale@gmail.com (Pablo Speciale)
30#          alexs.mac@gmail.com (Alex Stewart)
31#
32
33# Config file for Ceres Solver - Find Ceres & dependencies.
34#
35# This file is used by CMake when FIND_PACKAGE( Ceres ) is invoked (and
36# the directory containing this file is present in CMAKE_MODULE_PATH).
37#
38# This module defines the following variables:
39#
40# Ceres_FOUND / CERES_FOUND: True iff Ceres has been successfully
41#                            found. Both variables are set as although
42#                            FindPackage() only references Ceres_FOUND
43#                            in Config mode, given the conventions for
44#                            <package>_FOUND when FindPackage() is
45#                            called in Module mode, users could
46#                            reasonably expect to use CERES_FOUND
47#                            instead.
48#
49# CERES_VERSION: Version of Ceres found.
50#
51# CERES_INCLUDE_DIRS: Include directories for Ceres and the
52#                     dependencies which appear in the Ceres public
53#                     API and are thus required to use Ceres.
54#                     CERES_LIBRARIES: Libraries for Ceres and all
55#                     dependencies against which Ceres was
56#                     compiled. This will not include any optional
57#                     dependencies that were disabled when Ceres was
58#                     compiled.
59#
60# The following variables are also defined for legacy compatibility
61# only.  Any new code should not use them as they do not conform to
62# the standard CMake FindPackage naming conventions.
63#
64# CERES_INCLUDES = ${CERES_INCLUDE_DIRS}.
65
66# Called if we failed to find Ceres or any of it's required dependencies,
67# unsets all public (designed to be used externally) variables and reports
68# error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument.
69MACRO(CERES_REPORT_NOT_FOUND REASON_MSG)
70  # FindPackage() only references Ceres_FOUND, and requires it to be
71  # explicitly set FALSE to denote not found (not merely undefined).
72  SET(Ceres_FOUND FALSE)
73  SET(CERES_FOUND FALSE)
74  UNSET(CERES_INCLUDE_DIRS)
75  UNSET(CERES_LIBRARIES)
76
77  # Reset the CMake module path to its state when this script was called.
78  SET(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH})
79
80  # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by
81  # FindPackage() use the camelcase library name, not uppercase.
82  IF (Ceres_FIND_QUIETLY)
83    MESSAGE(STATUS "Failed to find Ceres - " ${REASON_MSG} ${ARGN})
84  ELSE (Ceres_FIND_REQUIRED)
85    MESSAGE(FATAL_ERROR "Failed to find Ceres - " ${REASON_MSG} ${ARGN})
86  ELSE()
87    # Neither QUIETLY nor REQUIRED, use SEND_ERROR which emits an error
88    # that prevents generation, but continues configuration.
89    MESSAGE(SEND_ERROR "Failed to find Ceres - " ${REASON_MSG} ${ARGN})
90  ENDIF ()
91  RETURN()
92ENDMACRO(CERES_REPORT_NOT_FOUND)
93
94# Get the (current, i.e. installed) directory containing this file.
95GET_FILENAME_COMPONENT(CURRENT_CONFIG_INSTALL_DIR
96  "${CMAKE_CURRENT_LIST_FILE}" PATH)
97
98# Record the state of the CMake module path when this script was
99# called so that we can ensure that we leave it in the same state on
100# exit as it was on entry, but modify it locally.
101SET(CALLERS_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
102# Reset CMake module path to the installation directory of this
103# script, thus we will use the FindPackage() scripts shipped with
104# Ceres to find Ceres' dependencies, even if the user has equivalently
105# named FindPackage() scripts in their project.
106SET(CMAKE_MODULE_PATH ${CURRENT_CONFIG_INSTALL_DIR})
107
108# Build the absolute root install directory as a relative path
109# (determined when Ceres was configured & built) from the current
110# install directory for this this file.  This allows for the install
111# tree to be relocated, after Ceres was built, outside of CMake.
112GET_FILENAME_COMPONENT(CURRENT_ROOT_INSTALL_DIR
113  ${CURRENT_CONFIG_INSTALL_DIR}/@INSTALL_ROOT_REL_CONFIG_INSTALL_DIR@ ABSOLUTE)
114IF (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR})
115  CERES_REPORT_NOT_FOUND(
116    "Ceres install root: ${CURRENT_ROOT_INSTALL_DIR}, "
117    "determined from relative path from CeresConfg.cmake install location: "
118    "${CURRENT_CONFIG_INSTALL_DIR}, does not exist. Either the install "
119    "directory was deleted, or the install tree was only partially relocated "
120    "outside of CMake after Ceres was built.")
121ENDIF (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR})
122
123# Set the version.
124SET(CERES_VERSION @CERES_VERSION@ )
125
126# Set the include directories for Ceres (itself).
127SET(CERES_INCLUDE_DIR "${CURRENT_ROOT_INSTALL_DIR}/include")
128IF (NOT EXISTS ${CERES_INCLUDE_DIR}/ceres/ceres.h)
129  CERES_REPORT_NOT_FOUND(
130    "Ceres install root: ${CURRENT_ROOT_INSTALL_DIR}, "
131    "determined from relative path from CeresConfg.cmake install location: "
132    "${CURRENT_CONFIG_INSTALL_DIR}, does not contain Ceres headers. "
133    "Either the install directory was deleted, or the install tree was only "
134    "partially relocated outside of CMake after Ceres was built.")
135ENDIF (NOT EXISTS ${CERES_INCLUDE_DIR}/ceres/ceres.h)
136
137# Append the include directories for all (potentially optional)
138# dependencies with which Ceres was compiled, the libraries themselves
139# come in via CeresTargets-<release/debug>.cmake as link libraries for
140# Ceres target.
141SET(CERES_INCLUDE_DIRS ${CERES_INCLUDE_DIR})
142
143# Eigen.
144# Flag set during configuration and build of Ceres.
145SET(CERES_EIGEN_VERSION @EIGEN_VERSION@)
146# Append the locations of Eigen when Ceres was built to the search path hints.
147LIST(APPEND EIGEN_INCLUDE_DIR_HINTS @EIGEN_INCLUDE_DIR@)
148# Search quietly s/t we control the timing of the error message if not found.
149FIND_PACKAGE(Eigen ${CERES_EIGEN_VERSION} EXACT QUIET)
150IF (EIGEN_FOUND)
151  MESSAGE(STATUS "Found required Ceres dependency: "
152    "Eigen version ${CERES_EIGEN_VERSION} in ${EIGEN_INCLUDE_DIRS}")
153ELSE (EIGEN_FOUND)
154  CERES_REPORT_NOT_FOUND("Missing required Ceres "
155    "dependency: Eigen version ${CERES_EIGEN_VERSION}, please set "
156    "EIGEN_INCLUDE_DIR.")
157ENDIF (EIGEN_FOUND)
158LIST(APPEND CERES_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS})
159
160# Glog.
161# Flag set during configuration and build of Ceres.
162SET(CERES_USES_MINIGLOG @MINIGLOG@)
163IF (CERES_USES_MINIGLOG)
164  SET(MINIGLOG_INCLUDE_DIR ${CERES_INCLUDE_DIR}/ceres/internal/miniglog)
165  IF (NOT EXISTS ${MINIGLOG_INCLUDE_DIR})
166    CERES_REPORT_NOT_FOUND(
167      "Ceres install include directory: "
168      "${CERES_INCLUDE_DIR} does not include miniglog, but Ceres was "
169      "compiled with MINIGLOG enabled (in place of Glog).")
170  ENDIF (NOT EXISTS ${MINIGLOG_INCLUDE_DIR})
171  LIST(APPEND CERES_INCLUDE_DIRS ${MINIGLOG_INCLUDE_DIR})
172  # Output message at standard log level (not the lower STATUS) so that
173  # the message is output in GUI during configuration to warn user.
174  MESSAGE("-- Found Ceres installation compiled with miniglog substitute "
175    "for glog, beware this will likely cause problems if glog is later linked.")
176ELSE (CERES_USES_MINIGLOG)
177  # Append the locations of glog when Ceres was built to the search path hints.
178  LIST(APPEND GLOG_INCLUDE_DIR_HINTS @GLOG_INCLUDE_DIR@)
179  GET_FILENAME_COMPONENT(CERES_BUILD_GLOG_LIBRARY_DIR @GLOG_LIBRARY@ PATH)
180  LIST(APPEND GLOG_LIBRARY_DIR_HINTS ${CERES_BUILD_GLOG_LIBRARY_DIR})
181
182  # Search quietly s/t we control the timing of the error message if not found.
183  FIND_PACKAGE(Glog QUIET)
184  IF (GLOG_FOUND)
185    MESSAGE(STATUS "Found required Ceres dependency: "
186      "Glog in ${GLOG_INCLUDE_DIRS}")
187  ELSE (GLOG_FOUND)
188    CERES_REPORT_NOT_FOUND("Missing required Ceres "
189      "dependency: Glog, please set GLOG_INCLUDE_DIR.")
190  ENDIF (GLOG_FOUND)
191  LIST(APPEND CERES_INCLUDE_DIRS ${GLOG_INCLUDE_DIRS})
192ENDIF (CERES_USES_MINIGLOG)
193
194# Import exported Ceres targets.
195IF (NOT TARGET ceres AND NOT Ceres_BINARY_DIR)
196  INCLUDE(${CURRENT_CONFIG_INSTALL_DIR}/CeresTargets.cmake)
197ENDIF (NOT TARGET ceres AND NOT Ceres_BINARY_DIR)
198# Set the expected XX_LIBRARIES variable for FindPackage().
199SET(CERES_LIBRARIES ceres)
200
201# Set legacy include directories variable for backwards compatibility.
202SET(CERES_INCLUDES ${CERES_INCLUDE_DIRS})
203
204# Reset CMake module path to its state when this script was called.
205SET(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH})
206
207# As we use CERES_REPORT_NOT_FOUND() to abort, if we reach this point we have
208# found Ceres and all required dependencies.
209MESSAGE(STATUS "Found Ceres version: ${CERES_VERSION} "
210    "installed in: ${CURRENT_ROOT_INSTALL_DIR}")
211
212# Set CERES_FOUND to be equivalent to Ceres_FOUND, which is set to
213# TRUE by FindPackage() if this file is found and run, and after which
214# Ceres_FOUND is not (explicitly, i.e. undefined does not count) set
215# to FALSE.
216SET(CERES_FOUND TRUE)
217