|
| 1 | +# Ceres Solver - A fast non-linear least squares minimizer |
| 2 | +# Copyright 2015 Google Inc. All rights reserved. |
| 3 | +# http://ceres-solver.org/ |
| 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: [email protected] (Alex Stewart) |
| 30 | +# |
| 31 | + |
| 32 | +# FindGlog.cmake - Find Google glog logging library. |
| 33 | +# |
| 34 | +# This module defines the following variables: |
| 35 | +# |
| 36 | +# GLOG_FOUND: TRUE iff glog is found. |
| 37 | +# GLOG_INCLUDE_DIRS: Include directories for glog. |
| 38 | +# GLOG_LIBRARIES: Libraries required to link glog. |
| 39 | +# |
| 40 | +# The following variables control the behaviour of this module: |
| 41 | +# |
| 42 | +# GLOG_INCLUDE_DIR_HINTS: List of additional directories in which to |
| 43 | +# search for glog includes, e.g: /timbuktu/include. |
| 44 | +# GLOG_LIBRARY_DIR_HINTS: List of additional directories in which to |
| 45 | +# search for glog 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 | +# GLOG_INCLUDE_DIR: Include directory for glog, not including the |
| 59 | +# include directory of any dependencies. |
| 60 | +# GLOG_LIBRARY: glog library, not including the libraries of any |
| 61 | +# dependencies. |
| 62 | + |
| 63 | +# Reset CALLERS_CMAKE_FIND_LIBRARY_PREFIXES to its value when |
| 64 | +# FindGlog was invoked. |
| 65 | +macro(GLOG_RESET_FIND_LIBRARY_PREFIX) |
| 66 | + if (MSVC) |
| 67 | + set(CMAKE_FIND_LIBRARY_PREFIXES "${CALLERS_CMAKE_FIND_LIBRARY_PREFIXES}") |
| 68 | + endif (MSVC) |
| 69 | +endmacro(GLOG_RESET_FIND_LIBRARY_PREFIX) |
| 70 | + |
| 71 | +# Called if we failed to find glog or any of it's required dependencies, |
| 72 | +# unsets all public (designed to be used externally) variables and reports |
| 73 | +# error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument. |
| 74 | +macro(GLOG_REPORT_NOT_FOUND REASON_MSG) |
| 75 | + unset(GLOG_FOUND) |
| 76 | + unset(GLOG_INCLUDE_DIRS) |
| 77 | + unset(GLOG_LIBRARIES) |
| 78 | + # Make results of search visible in the CMake GUI if glog has not |
| 79 | + # been found so that user does not have to toggle to advanced view. |
| 80 | + mark_as_advanced(CLEAR GLOG_INCLUDE_DIR |
| 81 | + GLOG_LIBRARY) |
| 82 | + |
| 83 | + glog_reset_find_library_prefix() |
| 84 | + |
| 85 | + # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage() |
| 86 | + # use the camelcase library name, not uppercase. |
| 87 | + if (Glog_FIND_QUIETLY) |
| 88 | + message(STATUS "Failed to find glog - " ${REASON_MSG} ${ARGN}) |
| 89 | + elseif (Glog_FIND_REQUIRED) |
| 90 | + message(FATAL_ERROR "Failed to find glog - " ${REASON_MSG} ${ARGN}) |
| 91 | + else() |
| 92 | + # Neither QUIETLY nor REQUIRED, use no priority which emits a message |
| 93 | + # but continues configuration and allows generation. |
| 94 | + message("-- Failed to find glog - " ${REASON_MSG} ${ARGN}) |
| 95 | + endif () |
| 96 | +endmacro(GLOG_REPORT_NOT_FOUND) |
| 97 | + |
| 98 | +# Handle possible presence of lib prefix for libraries on MSVC, see |
| 99 | +# also GLOG_RESET_FIND_LIBRARY_PREFIX(). |
| 100 | +if (MSVC) |
| 101 | + # Preserve the caller's original values for CMAKE_FIND_LIBRARY_PREFIXES |
| 102 | + # s/t we can set it back before returning. |
| 103 | + set(CALLERS_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}") |
| 104 | + # The empty string in this list is important, it represents the case when |
| 105 | + # the libraries have no prefix (shared libraries / DLLs). |
| 106 | + set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "" "${CMAKE_FIND_LIBRARY_PREFIXES}") |
| 107 | +endif (MSVC) |
| 108 | + |
| 109 | +# Search user-installed locations first, so that we prefer user installs |
| 110 | +# to system installs where both exist. |
| 111 | +list(APPEND GLOG_CHECK_INCLUDE_DIRS |
| 112 | + /usr/local/include |
| 113 | + /usr/local/homebrew/include # Mac OS X |
| 114 | + /opt/local/var/macports/software # Mac OS X. |
| 115 | + /opt/local/include |
| 116 | + /usr/include) |
| 117 | +# Windows (for C:/Program Files prefix). |
| 118 | +list(APPEND GLOG_CHECK_PATH_SUFFIXES |
| 119 | + glog/include |
| 120 | + glog/Include |
| 121 | + Glog/include |
| 122 | + Glog/Include) |
| 123 | + |
| 124 | +list(APPEND GLOG_CHECK_LIBRARY_DIRS |
| 125 | + /usr/local/lib |
| 126 | + /usr/local/homebrew/lib # Mac OS X. |
| 127 | + /opt/local/lib |
| 128 | + /usr/lib) |
| 129 | +# Windows (for C:/Program Files prefix). |
| 130 | +list(APPEND GLOG_CHECK_LIBRARY_SUFFIXES |
| 131 | + glog/lib |
| 132 | + glog/Lib |
| 133 | + Glog/lib |
| 134 | + Glog/Lib) |
| 135 | + |
| 136 | +# Search supplied hint directories first if supplied. |
| 137 | +find_path(GLOG_INCLUDE_DIR |
| 138 | + NAMES glog/logging.h |
| 139 | + PATHS ${GLOG_INCLUDE_DIR_HINTS} |
| 140 | + ${GLOG_CHECK_INCLUDE_DIRS} |
| 141 | + PATH_SUFFIXES ${GLOG_CHECK_PATH_SUFFIXES}) |
| 142 | +if (NOT GLOG_INCLUDE_DIR OR |
| 143 | + NOT EXISTS ${GLOG_INCLUDE_DIR}) |
| 144 | + glog_report_not_found( |
| 145 | + "Could not find glog include directory, set GLOG_INCLUDE_DIR " |
| 146 | + "to directory containing glog/logging.h") |
| 147 | +endif (NOT GLOG_INCLUDE_DIR OR |
| 148 | + NOT EXISTS ${GLOG_INCLUDE_DIR}) |
| 149 | + |
| 150 | +find_library(GLOG_LIBRARY NAMES glog |
| 151 | + PATHS ${GLOG_LIBRARY_DIR_HINTS} |
| 152 | + ${GLOG_CHECK_LIBRARY_DIRS} |
| 153 | + PATH_SUFFIXES ${GLOG_CHECK_LIBRARY_SUFFIXES}) |
| 154 | +if (NOT GLOG_LIBRARY OR |
| 155 | + NOT EXISTS ${GLOG_LIBRARY}) |
| 156 | + glog_report_not_found( |
| 157 | + "Could not find glog library, set GLOG_LIBRARY " |
| 158 | + "to full path to libglog.") |
| 159 | +endif (NOT GLOG_LIBRARY OR |
| 160 | + NOT EXISTS ${GLOG_LIBRARY}) |
| 161 | + |
| 162 | +# Mark internally as found, then verify. GLOG_REPORT_NOT_FOUND() unsets |
| 163 | +# if called. |
| 164 | +set(GLOG_FOUND TRUE) |
| 165 | + |
| 166 | +# Glog does not seem to provide any record of the version in its |
| 167 | +# source tree, thus cannot extract version. |
| 168 | + |
| 169 | +# Catch case when caller has set GLOG_INCLUDE_DIR in the cache / GUI and |
| 170 | +# thus FIND_[PATH/LIBRARY] are not called, but specified locations are |
| 171 | +# invalid, otherwise we would report the library as found. |
| 172 | +if (GLOG_INCLUDE_DIR AND |
| 173 | + NOT EXISTS ${GLOG_INCLUDE_DIR}/glog/logging.h) |
| 174 | + glog_report_not_found( |
| 175 | + "Caller defined GLOG_INCLUDE_DIR:" |
| 176 | + " ${GLOG_INCLUDE_DIR} does not contain glog/logging.h header.") |
| 177 | +endif (GLOG_INCLUDE_DIR AND |
| 178 | + NOT EXISTS ${GLOG_INCLUDE_DIR}/glog/logging.h) |
| 179 | +# TODO: This regex for glog library is pretty primitive, we use lowercase |
| 180 | +# for comparison to handle Windows using CamelCase library names, could |
| 181 | +# this check be better? |
| 182 | +string(TOLOWER "${GLOG_LIBRARY}" LOWERCASE_GLOG_LIBRARY) |
| 183 | +if (GLOG_LIBRARY AND |
| 184 | + NOT "${LOWERCASE_GLOG_LIBRARY}" MATCHES ".*glog[^/]*") |
| 185 | + glog_report_not_found( |
| 186 | + "Caller defined GLOG_LIBRARY: " |
| 187 | + "${GLOG_LIBRARY} does not match glog.") |
| 188 | +endif (GLOG_LIBRARY AND |
| 189 | + NOT "${LOWERCASE_GLOG_LIBRARY}" MATCHES ".*glog[^/]*") |
| 190 | + |
| 191 | +# Set standard CMake FindPackage variables if found. |
| 192 | +if (GLOG_FOUND) |
| 193 | + set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR}) |
| 194 | + set(GLOG_LIBRARIES ${GLOG_LIBRARY}) |
| 195 | +endif (GLOG_FOUND) |
| 196 | + |
| 197 | +glog_reset_find_library_prefix() |
| 198 | + |
| 199 | +# Handle REQUIRED / QUIET optional arguments. |
| 200 | +include(FindPackageHandleStandardArgs) |
| 201 | +find_package_handle_standard_args(Glog DEFAULT_MSG |
| 202 | + GLOG_INCLUDE_DIRS GLOG_LIBRARIES) |
| 203 | + |
| 204 | +# Only mark internal variables as advanced if we found glog, otherwise |
| 205 | +# leave them visible in the standard GUI for the user to set manually. |
| 206 | +if (GLOG_FOUND) |
| 207 | + mark_as_advanced(FORCE GLOG_INCLUDE_DIR |
| 208 | + GLOG_LIBRARY) |
| 209 | +endif (GLOG_FOUND) |
0 commit comments