blob: 02da76648da97439daaf35a8940d8a547e218733 [file] [log] [blame]
Pablo Speciale16dbf112013-03-11 14:44:02 -07001# 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#
Alex Stewart78cc2c42013-10-11 15:50:10 +010029# Authors: pablo.speciale@gmail.com (Pablo Speciale)
30# alexs.mac@gmail.com (Alex Stewart)
Pablo Speciale16dbf112013-03-11 14:44:02 -070031#
32
Alex Stewart78cc2c42013-10-11 15:50:10 +010033# 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#
Alex Stewart9697a082013-11-23 10:03:37 +000040# Ceres_FOUND / CERES_FOUND: True iff Ceres has been successfully found. Both
41# variables are set as although FindPackage() only
42# references Ceres_FOUND in Config mode, given the
43# conventions for <package>_FOUND when FindPackage()
44# is called in Module mode, users could reasonably
45# expect to use CERES_FOUND instead.
46# CERES_VERSION: Version of Ceres found.
Alex Stewart78cc2c42013-10-11 15:50:10 +010047# CERES_INCLUDE_DIRS: Include directories for Ceres and the dependencies which
48# appear in the Ceres public API and are thus required to
49# use Ceres.
50# CERES_LIBRARIES: Libraries for Ceres and all dependencies against which Ceres
51# was compiled. This will not include any optional dependencies
52# that were disabled when Ceres was compiled.
53#
54# The following variables are also defined for legacy compatibility only.
55# Any new code should not use them as they do not conform to the standard CMake
56# FindPackage naming conventions.
57#
58# CERES_INCLUDES = ${CERES_INCLUDE_DIRS}.
Pablo Speciale16dbf112013-03-11 14:44:02 -070059
Alex Stewart78cc2c42013-10-11 15:50:10 +010060# Called if we failed to find Ceres or any of it's required dependencies,
61# unsets all public (designed to be used externally) variables and reports
62# error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument.
63MACRO(CERES_REPORT_NOT_FOUND REASON_MSG)
Alex Stewart9697a082013-11-23 10:03:37 +000064 # FindPackage() only references Ceres_FOUND, and requires it to be explicitly
65 # set FALSE to denote not found (not merely undefined).
66 SET(Ceres_FOUND FALSE)
67 SET(CERES_FOUND FALSE)
Alex Stewart78cc2c42013-10-11 15:50:10 +010068 UNSET(CERES_INCLUDE_DIRS)
69 UNSET(CERES_LIBRARIES)
Pablo Speciale16dbf112013-03-11 14:44:02 -070070
Alex Stewart78cc2c42013-10-11 15:50:10 +010071 # Reset the CMake module path to its state when this script was called.
72 SET(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH})
73
74 # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage()
75 # use the camelcase library name, not uppercase.
76 IF (Ceres_FIND_QUIETLY)
77 MESSAGE(STATUS "Failed to find Ceres - " ${REASON_MSG} ${ARGN})
78 ELSE (Ceres_FIND_REQUIRED)
79 MESSAGE(FATAL_ERROR "Failed to find Ceres - " ${REASON_MSG} ${ARGN})
80 ELSE()
81 # Neither QUIETLY nor REQUIRED, use SEND_ERROR which emits an error
82 # that prevents generation, but continues configuration.
83 MESSAGE(SEND_ERROR "Failed to find Ceres - " ${REASON_MSG} ${ARGN})
84 ENDIF ()
85 RETURN()
86ENDMACRO(CERES_REPORT_NOT_FOUND)
87
88# Get the (current, i.e. installed) directory containing this file.
Alex Stewart4d0e6262013-11-15 13:53:44 +000089GET_FILENAME_COMPONENT(CURRENT_CONFIG_INSTALL_DIR
90 "${CMAKE_CURRENT_LIST_FILE}" PATH)
Alex Stewart78cc2c42013-10-11 15:50:10 +010091
92# Record the state of the CMake module path when this script was called so
93# that we can ensure that we leave it in the same state on exit as it was
94# on entry, but modify it locally.
95SET(CALLERS_CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
96# Reset CMake module path to the installation directory of this script,
97# thus we will use the FindPackage() scripts shipped with Ceres to find
98# Ceres' dependencies, even if the user has equivalently named FindPackage()
99# scripts in their project.
100SET(CMAKE_MODULE_PATH ${CURRENT_CONFIG_INSTALL_DIR})
101
102# Build the absolute root install directory as a relative path (determined when
103# Ceres was configured & built) from the current install directory for this
104# this file. This allows for the install tree to be relocated, after Ceres was
105# built, outside of CMake.
106GET_FILENAME_COMPONENT(CURRENT_ROOT_INSTALL_DIR
107 ${CURRENT_CONFIG_INSTALL_DIR}/@INSTALL_ROOT_REL_CONFIG_INSTALL_DIR@ ABSOLUTE)
108IF (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR})
109 CERES_REPORT_NOT_FOUND(
110 "Ceres install root: ${CURRENT_ROOT_INSTALL_DIR}, "
111 "determined from relative path from CeresConfg.cmake install location: "
112 "${CURRENT_CONFIG_INSTALL_DIR}, does not exist. Either the install "
113 "directory was deleted, or the install tree was only partially relocated "
114 "outside of CMake after Ceres was built.")
115ENDIF (NOT EXISTS ${CURRENT_ROOT_INSTALL_DIR})
116
117# Set the version.
Pablo Speciale16dbf112013-03-11 14:44:02 -0700118SET(CERES_VERSION @CERES_VERSION@ )
119
Alex Stewart78cc2c42013-10-11 15:50:10 +0100120# Set the include directories for Ceres (itself).
Alex Stewart54fc9422013-11-14 11:42:00 +0000121SET(CERES_INCLUDE_DIR "${CURRENT_ROOT_INSTALL_DIR}/include")
Alex Stewart78cc2c42013-10-11 15:50:10 +0100122IF (NOT EXISTS ${CERES_INCLUDE_DIR}/ceres/ceres.h)
123 CERES_REPORT_NOT_FOUND(
124 "Ceres install root: ${CURRENT_ROOT_INSTALL_DIR}, "
125 "determined from relative path from CeresConfg.cmake install location: "
126 "${CURRENT_CONFIG_INSTALL_DIR}, does not contain Ceres headers. "
127 "Either the install directory was deleted, or the install tree was only "
128 "partially relocated outside of CMake after Ceres was built.")
129ENDIF (NOT EXISTS ${CERES_INCLUDE_DIR}/ceres/ceres.h)
Pablo Speciale16dbf112013-03-11 14:44:02 -0700130
Alex Stewart78cc2c42013-10-11 15:50:10 +0100131# Append the include directories for all (potentially optional) dependencies
132# with which Ceres was compiled, the libraries themselves come in via
133# CeresTargets-<release/debug>.cmake as link libraries for Ceres target.
134SET(CERES_INCLUDE_DIRS ${CERES_INCLUDE_DIR})
Pablo Speciale16dbf112013-03-11 14:44:02 -0700135
Alex Stewart78cc2c42013-10-11 15:50:10 +0100136# Eigen.
137# Flag set during configuration and build of Ceres.
138SET(CERES_EIGEN_VERSION @EIGEN_VERSION@)
Alex Stewartfcbbb112013-11-13 22:22:30 +0000139# Append the locations of Eigen when Ceres was built to the search path hints.
140LIST(APPEND EIGEN_INCLUDE_DIR_HINTS @EIGEN_INCLUDE_DIR@)
Alex Stewart78cc2c42013-10-11 15:50:10 +0100141# Search quietly s/t we control the timing of the error message if not found.
142FIND_PACKAGE(Eigen ${CERES_EIGEN_VERSION} EXACT QUIET)
143IF (EIGEN_FOUND)
144 MESSAGE(STATUS "Found required Ceres dependency: "
145 "Eigen version ${CERES_EIGEN_VERSION} in ${EIGEN_INCLUDE_DIRS}")
146ELSE (EIGEN_FOUND)
147 CERES_REPORT_NOT_FOUND("Missing required Ceres "
148 "dependency: Eigen version ${CERES_EIGEN_VERSION}, please set "
149 "EIGEN_INCLUDE_DIR.")
150ENDIF (EIGEN_FOUND)
151LIST(APPEND CERES_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS})
152
153# Glog.
154# Flag set during configuration and build of Ceres.
155SET(CERES_USES_MINIGLOG @MINIGLOG@)
Alex Stewartfcbbb112013-11-13 22:22:30 +0000156# Append the locations of glog when Ceres was built to the search path hints.
157LIST(APPEND GLOG_INCLUDE_DIR_HINTS @GLOG_INCLUDE_DIR@)
158GET_FILENAME_COMPONENT(CERES_BUILD_GLOG_LIBRARY_DIR @GLOG_LIBRARY@ PATH)
159LIST(APPEND GLOG_LIBRARY_DIR_HINTS ${CERES_BUILD_GLOG_LIBRARY_DIR})
Alex Stewart78cc2c42013-10-11 15:50:10 +0100160IF (CERES_USES_MINIGLOG)
161 SET(MINIGLOG_INCLUDE_DIR ${CERES_INCLUDE_DIR}/ceres/internal/miniglog)
162 IF (NOT EXISTS ${MINIGLOG_INCLUDE_DIR})
163 CERES_REPORT_NOT_FOUND(
164 "Ceres install include directory: "
165 "${CERES_INCLUDE_DIR} does not include miniglog, but Ceres was "
166 "compiled with MINIGLOG enabled (in place of Glog).")
167 ENDIF (NOT EXISTS ${MINIGLOG_INCLUDE_DIR})
168 LIST(APPEND CERES_INCLUDE_DIRS ${MINIGLOG_INCLUDE_DIR})
169 # Output message at standard log level (not the lower STATUS) so that
170 # the message is output in GUI during configuration to warn user.
171 MESSAGE("-- Found Ceres installation compiled with miniglog substitute "
172 "for glog, beware this will likely cause problems if glog is later linked.")
173ELSE (CERES_USES_MINIGLOG)
174 # Search quietly s/t we control the timing of the error message if not found.
175 FIND_PACKAGE(Glog QUIET)
176 IF (GLOG_FOUND)
177 MESSAGE(STATUS "Found required Ceres dependency: "
178 "Glog in ${GLOG_INCLUDE_DIRS}")
179 ELSE (GLOG_FOUND)
180 CERES_REPORT_NOT_FOUND("Missing required Ceres "
181 "dependency: Glog, please set GLOG_INCLUDE_DIR.")
182 ENDIF (GLOG_FOUND)
183 LIST(APPEND CERES_INCLUDE_DIRS ${GLOG_INCLUDE_DIRS})
184ENDIF (CERES_USES_MINIGLOG)
185
186# Import exported Ceres targets.
187IF (NOT TARGET ceres AND NOT Ceres_BINARY_DIR)
188 INCLUDE(${CURRENT_CONFIG_INSTALL_DIR}/CeresTargets.cmake)
189ENDIF (NOT TARGET ceres AND NOT Ceres_BINARY_DIR)
190# Set the expected XX_LIBRARIES variable for FindPackage().
Pablo Speciale16dbf112013-03-11 14:44:02 -0700191SET(CERES_LIBRARIES ceres)
Alex Stewart78cc2c42013-10-11 15:50:10 +0100192
193# Set legacy include directories variable for backwards compatibility.
194SET(CERES_INCLUDES ${CERES_INCLUDE_DIRS})
195
196# Reset CMake module path to its state when this script was called.
197SET(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH})
198
199# As we use CERES_REPORT_NOT_FOUND() to abort, if we reach this point we have
200# found Ceres and all required dependencies.
201MESSAGE(STATUS "Found Ceres version: ${CERES_VERSION} "
202 "installed in: ${CURRENT_ROOT_INSTALL_DIR}")
Alex Stewart9697a082013-11-23 10:03:37 +0000203# Set CERES_FOUND to be equivalent to Ceres_FOUND, which is set to TRUE by
204# FindPackage() if this file is found and run, and after which Ceres_FOUND
205# is not (explicitly, i.e. undefined does not count) set to FALSE.
206SET(CERES_FOUND TRUE)