Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame^] | 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: alexs.mac@gmail.com (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 | # FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION: True iff the version of glog found |
| 40 | # was built & installed / exported |
| 41 | # as a CMake package. |
| 42 | # |
| 43 | # The following variables control the behaviour of this module: |
| 44 | # |
| 45 | # GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION: TRUE/FALSE, iff TRUE then |
| 46 | # then prefer using an exported CMake configuration |
| 47 | # generated by glog > 0.3.4 over searching for the |
| 48 | # glog components manually. Otherwise (FALSE) |
| 49 | # ignore any exported glog CMake configurations and |
| 50 | # always perform a manual search for the components. |
| 51 | # Default: TRUE iff user does not define this variable |
| 52 | # before we are called, and does NOT specify either |
| 53 | # GLOG_INCLUDE_DIR_HINTS or GLOG_LIBRARY_DIR_HINTS |
| 54 | # otherwise FALSE. |
| 55 | # GLOG_INCLUDE_DIR_HINTS: List of additional directories in which to |
| 56 | # search for glog includes, e.g: /timbuktu/include. |
| 57 | # GLOG_LIBRARY_DIR_HINTS: List of additional directories in which to |
| 58 | # search for glog libraries, e.g: /timbuktu/lib. |
| 59 | # |
| 60 | # The following variables are also defined by this module, but in line with |
| 61 | # CMake recommended FindPackage() module style should NOT be referenced directly |
| 62 | # by callers (use the plural variables detailed above instead). These variables |
| 63 | # do however affect the behaviour of the module via FIND_[PATH/LIBRARY]() which |
| 64 | # are NOT re-called (i.e. search for library is not repeated) if these variables |
| 65 | # are set with valid values _in the CMake cache_. This means that if these |
| 66 | # variables are set directly in the cache, either by the user in the CMake GUI, |
| 67 | # or by the user passing -DVAR=VALUE directives to CMake when called (which |
| 68 | # explicitly defines a cache variable), then they will be used verbatim, |
| 69 | # bypassing the HINTS variables and other hard-coded search locations. |
| 70 | # |
| 71 | # GLOG_INCLUDE_DIR: Include directory for glog, not including the |
| 72 | # include directory of any dependencies. |
| 73 | # GLOG_LIBRARY: glog library, not including the libraries of any |
| 74 | # dependencies. |
| 75 | |
| 76 | # Reset CALLERS_CMAKE_FIND_LIBRARY_PREFIXES to its value when |
| 77 | # FindGlog was invoked. |
| 78 | macro(GLOG_RESET_FIND_LIBRARY_PREFIX) |
| 79 | if (MSVC AND CALLERS_CMAKE_FIND_LIBRARY_PREFIXES) |
| 80 | set(CMAKE_FIND_LIBRARY_PREFIXES "${CALLERS_CMAKE_FIND_LIBRARY_PREFIXES}") |
| 81 | endif() |
| 82 | endmacro(GLOG_RESET_FIND_LIBRARY_PREFIX) |
| 83 | |
| 84 | # Called if we failed to find glog or any of it's required dependencies, |
| 85 | # unsets all public (designed to be used externally) variables and reports |
| 86 | # error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument. |
| 87 | macro(GLOG_REPORT_NOT_FOUND REASON_MSG) |
| 88 | unset(GLOG_FOUND) |
| 89 | unset(GLOG_INCLUDE_DIRS) |
| 90 | unset(GLOG_LIBRARIES) |
| 91 | # Make results of search visible in the CMake GUI if glog has not |
| 92 | # been found so that user does not have to toggle to advanced view. |
| 93 | mark_as_advanced(CLEAR GLOG_INCLUDE_DIR |
| 94 | GLOG_LIBRARY) |
| 95 | |
| 96 | glog_reset_find_library_prefix() |
| 97 | |
| 98 | # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage() |
| 99 | # use the camelcase library name, not uppercase. |
| 100 | if (Glog_FIND_QUIETLY) |
| 101 | message(STATUS "Failed to find glog - " ${REASON_MSG} ${ARGN}) |
| 102 | elseif (Glog_FIND_REQUIRED) |
| 103 | message(FATAL_ERROR "Failed to find glog - " ${REASON_MSG} ${ARGN}) |
| 104 | else() |
| 105 | # Neither QUIETLY nor REQUIRED, use no priority which emits a message |
| 106 | # but continues configuration and allows generation. |
| 107 | message("-- Failed to find glog - " ${REASON_MSG} ${ARGN}) |
| 108 | endif () |
| 109 | return() |
| 110 | endmacro(GLOG_REPORT_NOT_FOUND) |
| 111 | |
| 112 | # Protect against any alternative find_package scripts for this library having |
| 113 | # been called previously (in a client project) which set GLOG_FOUND, but not |
| 114 | # the other variables we require / set here which could cause the search logic |
| 115 | # here to fail. |
| 116 | unset(GLOG_FOUND) |
| 117 | |
| 118 | # ----------------------------------------------------------------- |
| 119 | # By default, if the user has expressed no preference for using an exported |
| 120 | # glog CMake configuration over performing a search for the installed |
| 121 | # components, and has not specified any hints for the search locations, then |
| 122 | # prefer a glog exported configuration if available. |
| 123 | if (NOT DEFINED GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION |
| 124 | AND NOT GLOG_INCLUDE_DIR_HINTS |
| 125 | AND NOT GLOG_LIBRARY_DIR_HINTS) |
| 126 | message(STATUS "No preference for use of exported glog CMake configuration " |
| 127 | "set, and no hints for include/library directories provided. " |
| 128 | "Defaulting to preferring an installed/exported glog CMake configuration " |
| 129 | "if available.") |
| 130 | set(GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION TRUE) |
| 131 | endif() |
| 132 | |
| 133 | if (GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION) |
| 134 | # Try to find an exported CMake configuration for glog, as generated by |
| 135 | # glog versions > 0.3.4 |
| 136 | # |
| 137 | # We search twice, s/t we can invert the ordering of precedence used by |
| 138 | # find_package() for exported package build directories, and installed |
| 139 | # packages (found via CMAKE_SYSTEM_PREFIX_PATH), listed as items 6) and 7) |
| 140 | # respectively in [1]. |
| 141 | # |
| 142 | # By default, exported build directories are (in theory) detected first, and |
| 143 | # this is usually the case on Windows. However, on OS X & Linux, the install |
| 144 | # path (/usr/local) is typically present in the PATH environment variable |
| 145 | # which is checked in item 4) in [1] (i.e. before both of the above, unless |
| 146 | # NO_SYSTEM_ENVIRONMENT_PATH is passed). As such on those OSs installed |
| 147 | # packages are usually detected in preference to exported package build |
| 148 | # directories. |
| 149 | # |
| 150 | # To ensure a more consistent response across all OSs, and as users usually |
| 151 | # want to prefer an installed version of a package over a locally built one |
| 152 | # where both exist (esp. as the exported build directory might be removed |
| 153 | # after installation), we first search with NO_CMAKE_PACKAGE_REGISTRY which |
| 154 | # means any build directories exported by the user are ignored, and thus |
| 155 | # installed directories are preferred. If this fails to find the package |
| 156 | # we then research again, but without NO_CMAKE_PACKAGE_REGISTRY, so any |
| 157 | # exported build directories will now be detected. |
| 158 | # |
| 159 | # To prevent confusion on Windows, we also pass NO_CMAKE_BUILDS_PATH (which |
| 160 | # is item 5) in [1]), to not preferentially use projects that were built |
| 161 | # recently with the CMake GUI to ensure that we always prefer an installed |
| 162 | # version if available. |
| 163 | # |
| 164 | # NOTE: We use the NAMES option as glog erroneously uses 'google-glog' as its |
| 165 | # project name when built with CMake, but exports itself as just 'glog'. |
| 166 | # On Linux/OS X this does not break detection as the project name is |
| 167 | # not used as part of the install path for the CMake package files, |
| 168 | # e.g. /usr/local/lib/cmake/glog, where the <glog> suffix is hardcoded |
| 169 | # in glog's CMakeLists. However, on Windows the project name *is* |
| 170 | # part of the install prefix: C:/Program Files/google-glog/[include,lib]. |
| 171 | # However, by default CMake checks: |
| 172 | # C:/Program Files/<FIND_PACKAGE_ARGUMENT_NAME='glog'> which does not |
| 173 | # exist and thus detection fails. Thus we use the NAMES to force the |
| 174 | # search to use both google-glog & glog. |
| 175 | # |
| 176 | # [1] http://www.cmake.org/cmake/help/v2.8.11/cmake.html#command:find_package |
| 177 | find_package(glog QUIET |
| 178 | NAMES google-glog glog |
| 179 | NO_MODULE |
| 180 | NO_CMAKE_PACKAGE_REGISTRY |
| 181 | NO_CMAKE_BUILDS_PATH) |
| 182 | if (glog_FOUND) |
| 183 | message(STATUS "Found installed version of glog: ${glog_DIR}") |
| 184 | else() |
| 185 | # Failed to find an installed version of glog, repeat search allowing |
| 186 | # exported build directories. |
| 187 | message(STATUS "Failed to find installed glog CMake configuration, " |
| 188 | "searching for glog build directories exported with CMake.") |
| 189 | # Again pass NO_CMAKE_BUILDS_PATH, as we know that glog is exported and |
| 190 | # do not want to treat projects built with the CMake GUI preferentially. |
| 191 | find_package(glog QUIET |
| 192 | NAMES google-glog glog |
| 193 | NO_MODULE |
| 194 | NO_CMAKE_BUILDS_PATH) |
| 195 | if (glog_FOUND) |
| 196 | message(STATUS "Found exported glog build directory: ${glog_DIR}") |
| 197 | endif(glog_FOUND) |
| 198 | endif(glog_FOUND) |
| 199 | |
| 200 | set(FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION ${glog_FOUND}) |
| 201 | |
| 202 | if (FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION) |
| 203 | message(STATUS "Detected glog version: ${glog_VERSION}") |
| 204 | set(GLOG_FOUND ${glog_FOUND}) |
| 205 | # glog wraps the include directories into the exported glog::glog target. |
| 206 | set(GLOG_INCLUDE_DIR "") |
| 207 | set(GLOG_LIBRARY glog::glog) |
| 208 | else (FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION) |
| 209 | message(STATUS "Failed to find an installed/exported CMake configuration " |
| 210 | "for glog, will perform search for installed glog components.") |
| 211 | endif (FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION) |
| 212 | endif(GLOG_PREFER_EXPORTED_GLOG_CMAKE_CONFIGURATION) |
| 213 | |
| 214 | if (NOT GLOG_FOUND) |
| 215 | # Either failed to find an exported glog CMake configuration, or user |
| 216 | # told us not to use one. Perform a manual search for all glog components. |
| 217 | |
| 218 | # Handle possible presence of lib prefix for libraries on MSVC, see |
| 219 | # also GLOG_RESET_FIND_LIBRARY_PREFIX(). |
| 220 | if (MSVC) |
| 221 | # Preserve the caller's original values for CMAKE_FIND_LIBRARY_PREFIXES |
| 222 | # s/t we can set it back before returning. |
| 223 | set(CALLERS_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}") |
| 224 | # The empty string in this list is important, it represents the case when |
| 225 | # the libraries have no prefix (shared libraries / DLLs). |
| 226 | set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "" "${CMAKE_FIND_LIBRARY_PREFIXES}") |
| 227 | endif (MSVC) |
| 228 | |
| 229 | # Search user-installed locations first, so that we prefer user installs |
| 230 | # to system installs where both exist. |
| 231 | list(APPEND GLOG_CHECK_INCLUDE_DIRS |
| 232 | /usr/local/include |
| 233 | /usr/local/homebrew/include # Mac OS X |
| 234 | /opt/local/var/macports/software # Mac OS X. |
| 235 | /opt/local/include |
| 236 | /usr/include) |
| 237 | # Windows (for C:/Program Files prefix). |
| 238 | list(APPEND GLOG_CHECK_PATH_SUFFIXES |
| 239 | glog/include |
| 240 | glog/Include |
| 241 | Glog/include |
| 242 | Glog/Include |
| 243 | google-glog/include # CMake installs with project name prefix. |
| 244 | google-glog/Include) |
| 245 | |
| 246 | list(APPEND GLOG_CHECK_LIBRARY_DIRS |
| 247 | /usr/local/lib |
| 248 | /usr/local/homebrew/lib # Mac OS X. |
| 249 | /opt/local/lib |
| 250 | /usr/lib) |
| 251 | # Windows (for C:/Program Files prefix). |
| 252 | list(APPEND GLOG_CHECK_LIBRARY_SUFFIXES |
| 253 | glog/lib |
| 254 | glog/Lib |
| 255 | Glog/lib |
| 256 | Glog/Lib |
| 257 | google-glog/lib # CMake installs with project name prefix. |
| 258 | google-glog/Lib) |
| 259 | |
| 260 | # Search supplied hint directories first if supplied. |
| 261 | find_path(GLOG_INCLUDE_DIR |
| 262 | NAMES glog/logging.h |
| 263 | HINTS ${GLOG_INCLUDE_DIR_HINTS} |
| 264 | PATHS ${GLOG_CHECK_INCLUDE_DIRS} |
| 265 | PATH_SUFFIXES ${GLOG_CHECK_PATH_SUFFIXES}) |
| 266 | if (NOT GLOG_INCLUDE_DIR OR |
| 267 | NOT EXISTS ${GLOG_INCLUDE_DIR}) |
| 268 | glog_report_not_found( |
| 269 | "Could not find glog include directory, set GLOG_INCLUDE_DIR " |
| 270 | "to directory containing glog/logging.h") |
| 271 | endif (NOT GLOG_INCLUDE_DIR OR |
| 272 | NOT EXISTS ${GLOG_INCLUDE_DIR}) |
| 273 | |
| 274 | find_library(GLOG_LIBRARY NAMES glog |
| 275 | HINTS ${GLOG_LIBRARY_DIR_HINTS} |
| 276 | PATHS ${GLOG_CHECK_LIBRARY_DIRS} |
| 277 | PATH_SUFFIXES ${GLOG_CHECK_LIBRARY_SUFFIXES}) |
| 278 | if (NOT GLOG_LIBRARY OR |
| 279 | NOT EXISTS ${GLOG_LIBRARY}) |
| 280 | glog_report_not_found( |
| 281 | "Could not find glog library, set GLOG_LIBRARY " |
| 282 | "to full path to libglog.") |
| 283 | endif (NOT GLOG_LIBRARY OR |
| 284 | NOT EXISTS ${GLOG_LIBRARY}) |
| 285 | |
| 286 | # Mark internally as found, then verify. GLOG_REPORT_NOT_FOUND() unsets |
| 287 | # if called. |
| 288 | set(GLOG_FOUND TRUE) |
| 289 | |
| 290 | # Glog does not seem to provide any record of the version in its |
| 291 | # source tree, thus cannot extract version. |
| 292 | |
| 293 | # Catch case when caller has set GLOG_INCLUDE_DIR in the cache / GUI and |
| 294 | # thus FIND_[PATH/LIBRARY] are not called, but specified locations are |
| 295 | # invalid, otherwise we would report the library as found. |
| 296 | if (GLOG_INCLUDE_DIR AND |
| 297 | NOT EXISTS ${GLOG_INCLUDE_DIR}/glog/logging.h) |
| 298 | glog_report_not_found( |
| 299 | "Caller defined GLOG_INCLUDE_DIR:" |
| 300 | " ${GLOG_INCLUDE_DIR} does not contain glog/logging.h header.") |
| 301 | endif (GLOG_INCLUDE_DIR AND |
| 302 | NOT EXISTS ${GLOG_INCLUDE_DIR}/glog/logging.h) |
| 303 | # TODO: This regex for glog library is pretty primitive, we use lowercase |
| 304 | # for comparison to handle Windows using CamelCase library names, could |
| 305 | # this check be better? |
| 306 | string(TOLOWER "${GLOG_LIBRARY}" LOWERCASE_GLOG_LIBRARY) |
| 307 | if (GLOG_LIBRARY AND |
| 308 | NOT "${LOWERCASE_GLOG_LIBRARY}" MATCHES ".*glog[^/]*") |
| 309 | glog_report_not_found( |
| 310 | "Caller defined GLOG_LIBRARY: " |
| 311 | "${GLOG_LIBRARY} does not match glog.") |
| 312 | endif (GLOG_LIBRARY AND |
| 313 | NOT "${LOWERCASE_GLOG_LIBRARY}" MATCHES ".*glog[^/]*") |
| 314 | |
| 315 | glog_reset_find_library_prefix() |
| 316 | |
| 317 | endif(NOT GLOG_FOUND) |
| 318 | |
| 319 | # Set standard CMake FindPackage variables if found. |
| 320 | if (GLOG_FOUND) |
| 321 | set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR}) |
| 322 | set(GLOG_LIBRARIES ${GLOG_LIBRARY}) |
| 323 | endif (GLOG_FOUND) |
| 324 | |
| 325 | # If we are using an exported CMake glog target, the include directories are |
| 326 | # wrapped into the target itself, and do not have to be (and are not) |
| 327 | # separately specified. In which case, we should not add GLOG_INCLUDE_DIRS |
| 328 | # to the list of required variables in order that glog be reported as found. |
| 329 | if (FOUND_INSTALLED_GLOG_CMAKE_CONFIGURATION) |
| 330 | set(GLOG_REQUIRED_VARIABLES GLOG_LIBRARIES) |
| 331 | else() |
| 332 | set(GLOG_REQUIRED_VARIABLES GLOG_INCLUDE_DIRS GLOG_LIBRARIES) |
| 333 | endif() |
| 334 | |
| 335 | # Handle REQUIRED / QUIET optional arguments. |
| 336 | include(FindPackageHandleStandardArgs) |
| 337 | find_package_handle_standard_args(Glog DEFAULT_MSG |
| 338 | ${GLOG_REQUIRED_VARIABLES}) |
| 339 | |
| 340 | # Only mark internal variables as advanced if we found glog, otherwise |
| 341 | # leave them visible in the standard GUI for the user to set manually. |
| 342 | if (GLOG_FOUND) |
| 343 | mark_as_advanced(FORCE GLOG_INCLUDE_DIR |
| 344 | GLOG_LIBRARY |
| 345 | glog_DIR) # Autogenerated by find_package(glog) |
| 346 | endif (GLOG_FOUND) |