• 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# Author: alexs.mac@gmail.com (Alex Stewart)
30#
31
32# FindGflags.cmake - Find Google gflags logging library.
33#
34# This module defines the following variables:
35#
36# GFLAGS_FOUND: TRUE iff gflags is found.
37# GFLAGS_INCLUDE_DIRS: Include directories for gflags.
38# GFLAGS_LIBRARIES: Libraries required to link gflags.
39#
40# The following variables control the behaviour of this module:
41#
42# GFLAGS_INCLUDE_DIR_HINTS: List of additional directories in which to
43#                           search for gflags includes, e.g: /timbuktu/include.
44# GFLAGS_LIBRARY_DIR_HINTS: List of additional directories in which to
45#                           search for gflags libraries, e.g: /timbuktu/lib.
46#
47# The following variables are also defined by this module, but in line with
48# CMake recommended FindPackage() module style should NOT be referenced directly
49# by callers (use the plural variables detailed above instead).  These variables
50# do however affect the behaviour of the module via FIND_[PATH/LIBRARY]() which
51# are NOT re-called (i.e. search for library is not repeated) if these variables
52# are set with valid values _in the CMake cache_. This means that if these
53# variables are set directly in the cache, either by the user in the CMake GUI,
54# or by the user passing -DVAR=VALUE directives to CMake when called (which
55# explicitly defines a cache variable), then they will be used verbatim,
56# bypassing the HINTS variables and other hard-coded search locations.
57#
58# GFLAGS_INCLUDE_DIR: Include directory for gflags, not including the
59#                     include directory of any dependencies.
60# GFLAGS_LIBRARY: gflags library, not including the libraries of any
61#                 dependencies.
62
63# Called if we failed to find gflags or any of it's required dependencies,
64# unsets all public (designed to be used externally) variables and reports
65# error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument.
66MACRO(GFLAGS_REPORT_NOT_FOUND REASON_MSG)
67  UNSET(GFLAGS_FOUND)
68  UNSET(GFLAGS_INCLUDE_DIRS)
69  UNSET(GFLAGS_LIBRARIES)
70  # Make results of search visible in the CMake GUI if gflags has not
71  # been found so that user does not have to toggle to advanced view.
72  MARK_AS_ADVANCED(CLEAR GFLAGS_INCLUDE_DIR
73                         GFLAGS_LIBRARY)
74  # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage()
75  # use the camelcase library name, not uppercase.
76  IF (Gflags_FIND_QUIETLY)
77    MESSAGE(STATUS "Failed to find gflags - " ${REASON_MSG} ${ARGN})
78  ELSEIF (Gflags_FIND_REQUIRED)
79    MESSAGE(FATAL_ERROR "Failed to find gflags - " ${REASON_MSG} ${ARGN})
80  ELSE()
81    # Neither QUIETLY nor REQUIRED, use no priority which emits a message
82    # but continues configuration and allows generation.
83    MESSAGE("-- Failed to find gflags - " ${REASON_MSG} ${ARGN})
84  ENDIF ()
85ENDMACRO(GFLAGS_REPORT_NOT_FOUND)
86
87# Search user-installed locations first, so that we prefer user installs
88# to system installs where both exist.
89#
90# TODO: Add standard Windows search locations for gflags.
91LIST(APPEND GFLAGS_CHECK_INCLUDE_DIRS
92  /usr/local/include
93  /usr/local/homebrew/include # Mac OS X
94  /opt/local/var/macports/software # Mac OS X.
95  /opt/local/include
96  /usr/include)
97LIST(APPEND GFLAGS_CHECK_LIBRARY_DIRS
98  /usr/local/lib
99  /usr/local/homebrew/lib # Mac OS X.
100  /opt/local/lib
101  /usr/lib)
102
103# Search supplied hint directories first if supplied.
104FIND_PATH(GFLAGS_INCLUDE_DIR
105  NAMES gflags/gflags.h
106  PATHS ${GFLAGS_INCLUDE_DIR_HINTS}
107  ${GFLAGS_CHECK_INCLUDE_DIRS})
108IF (NOT GFLAGS_INCLUDE_DIR OR
109    NOT EXISTS ${GFLAGS_INCLUDE_DIR})
110  GFLAGS_REPORT_NOT_FOUND(
111    "Could not find gflags include directory, set GFLAGS_INCLUDE_DIR "
112    "to directory containing gflags/gflags.h")
113ENDIF (NOT GFLAGS_INCLUDE_DIR OR
114       NOT EXISTS ${GFLAGS_INCLUDE_DIR})
115
116FIND_LIBRARY(GFLAGS_LIBRARY NAMES gflags
117  PATHS ${GFLAGS_LIBRARY_DIR_HINTS}
118  ${GFLAGS_CHECK_LIBRARY_DIRS})
119IF (NOT GFLAGS_LIBRARY OR
120    NOT EXISTS ${GFLAGS_LIBRARY})
121  GFLAGS_REPORT_NOT_FOUND(
122    "Could not find gflags library, set GFLAGS_LIBRARY "
123    "to full path to libgflags.")
124ENDIF (NOT GFLAGS_LIBRARY OR
125       NOT EXISTS ${GFLAGS_LIBRARY})
126
127# Mark internally as found, then verify. GFLAGS_REPORT_NOT_FOUND() unsets
128# if called.
129SET(GFLAGS_FOUND TRUE)
130
131# gflags does not seem to provide any record of the version in its
132# source tree, thus cannot extract version.
133
134# Catch case when caller has set GFLAGS_INCLUDE_DIR in the cache / GUI and
135# thus FIND_[PATH/LIBRARY] are not called, but specified locations are
136# invalid, otherwise we would report the library as found.
137IF (GFLAGS_INCLUDE_DIR AND
138    NOT EXISTS ${GFLAGS_INCLUDE_DIR}/gflags/gflags.h)
139  GFLAGS_REPORT_NOT_FOUND(
140    "Caller defined GFLAGS_INCLUDE_DIR:"
141    " ${GFLAGS_INCLUDE_DIR} does not contain gflags/gflags.h header.")
142ENDIF (GFLAGS_INCLUDE_DIR AND
143       NOT EXISTS ${GFLAGS_INCLUDE_DIR}/gflags/gflags.h)
144# TODO: This regex for gflags library is pretty primitive, we use lowercase
145#       for comparison to handle Windows using CamelCase library names, could
146#       this check be better?
147STRING(TOLOWER "${GFLAGS_LIBRARY}" LOWERCASE_GFLAGS_LIBRARY)
148IF (GFLAGS_LIBRARY AND
149    NOT "${LOWERCASE_GFLAGS_LIBRARY}" MATCHES ".*gflags[^/]*")
150  GFLAGS_REPORT_NOT_FOUND(
151    "Caller defined GFLAGS_LIBRARY: "
152    "${GFLAGS_LIBRARY} does not match gflags.")
153ENDIF (GFLAGS_LIBRARY AND
154       NOT "${LOWERCASE_GFLAGS_LIBRARY}" MATCHES ".*gflags[^/]*")
155
156# Set standard CMake FindPackage variables if found.
157IF (GFLAGS_FOUND)
158  SET(GFLAGS_INCLUDE_DIRS ${GFLAGS_INCLUDE_DIR})
159  SET(GFLAGS_LIBRARIES ${GFLAGS_LIBRARY})
160ENDIF (GFLAGS_FOUND)
161
162# Handle REQUIRED / QUIET optional arguments.
163INCLUDE(FindPackageHandleStandardArgs)
164FIND_PACKAGE_HANDLE_STANDARD_ARGS(Gflags DEFAULT_MSG
165  GFLAGS_INCLUDE_DIRS GFLAGS_LIBRARIES)
166
167# Only mark internal variables as advanced if we found gflags, otherwise
168# leave them visible in the standard GUI for the user to set manually.
169IF (GFLAGS_FOUND)
170  MARK_AS_ADVANCED(FORCE GFLAGS_INCLUDE_DIR
171                         GFLAGS_LIBRARY)
172ENDIF (GFLAGS_FOUND)
173