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# 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# Called if we failed to find glog 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(GLOG_REPORT_NOT_FOUND REASON_MSG) 67 UNSET(GLOG_FOUND) 68 UNSET(GLOG_INCLUDE_DIRS) 69 UNSET(GLOG_LIBRARIES) 70 # Make results of search visible in the CMake GUI if glog has not 71 # been found so that user does not have to toggle to advanced view. 72 MARK_AS_ADVANCED(CLEAR GLOG_INCLUDE_DIR 73 GLOG_LIBRARY) 74 # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage() 75 # use the camelcase library name, not uppercase. 76 IF (Glog_FIND_QUIETLY) 77 MESSAGE(STATUS "Failed to find glog - " ${REASON_MSG} ${ARGN}) 78 ELSEIF (Glog_FIND_REQUIRED) 79 MESSAGE(FATAL_ERROR "Failed to find glog - " ${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 glog - " ${REASON_MSG} ${ARGN}) 84 ENDIF () 85ENDMACRO(GLOG_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 glog. 91LIST(APPEND GLOG_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 GLOG_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(GLOG_INCLUDE_DIR 105 NAMES glog/logging.h 106 PATHS ${GLOG_INCLUDE_DIR_HINTS} 107 ${GLOG_CHECK_INCLUDE_DIRS}) 108IF (NOT GLOG_INCLUDE_DIR OR 109 NOT EXISTS ${GLOG_INCLUDE_DIR}) 110 GLOG_REPORT_NOT_FOUND( 111 "Could not find glog include directory, set GLOG_INCLUDE_DIR " 112 "to directory containing glog/logging.h") 113ENDIF (NOT GLOG_INCLUDE_DIR OR 114 NOT EXISTS ${GLOG_INCLUDE_DIR}) 115 116FIND_LIBRARY(GLOG_LIBRARY NAMES glog 117 PATHS ${GLOG_LIBRARY_DIR_HINTS} 118 ${GLOG_CHECK_LIBRARY_DIRS}) 119IF (NOT GLOG_LIBRARY OR 120 NOT EXISTS ${GLOG_LIBRARY}) 121 GLOG_REPORT_NOT_FOUND( 122 "Could not find glog library, set GLOG_LIBRARY " 123 "to full path to libglog.") 124ENDIF (NOT GLOG_LIBRARY OR 125 NOT EXISTS ${GLOG_LIBRARY}) 126 127# Mark internally as found, then verify. GLOG_REPORT_NOT_FOUND() unsets 128# if called. 129SET(GLOG_FOUND TRUE) 130 131# Glog 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 GLOG_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 (GLOG_INCLUDE_DIR AND 138 NOT EXISTS ${GLOG_INCLUDE_DIR}/glog/logging.h) 139 GLOG_REPORT_NOT_FOUND( 140 "Caller defined GLOG_INCLUDE_DIR:" 141 " ${GLOG_INCLUDE_DIR} does not contain glog/logging.h header.") 142ENDIF (GLOG_INCLUDE_DIR AND 143 NOT EXISTS ${GLOG_INCLUDE_DIR}/glog/logging.h) 144# TODO: This regex for glog 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 "${GLOG_LIBRARY}" LOWERCASE_GLOG_LIBRARY) 148IF (GLOG_LIBRARY AND 149 NOT "${LOWERCASE_GLOG_LIBRARY}" MATCHES ".*glog[^/]*") 150 GLOG_REPORT_NOT_FOUND( 151 "Caller defined GLOG_LIBRARY: " 152 "${GLOG_LIBRARY} does not match glog.") 153ENDIF (GLOG_LIBRARY AND 154 NOT "${LOWERCASE_GLOG_LIBRARY}" MATCHES ".*glog[^/]*") 155 156# Set standard CMake FindPackage variables if found. 157IF (GLOG_FOUND) 158 SET(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR}) 159 SET(GLOG_LIBRARIES ${GLOG_LIBRARY}) 160ENDIF (GLOG_FOUND) 161 162# Handle REQUIRED / QUIET optional arguments. 163INCLUDE(FindPackageHandleStandardArgs) 164FIND_PACKAGE_HANDLE_STANDARD_ARGS(Glog DEFAULT_MSG 165 GLOG_INCLUDE_DIRS GLOG_LIBRARIES) 166 167# Only mark internal variables as advanced if we found glog, otherwise 168# leave them visible in the standard GUI for the user to set manually. 169IF (GLOG_FOUND) 170 MARK_AS_ADVANCED(FORCE GLOG_INCLUDE_DIR 171 GLOG_LIBRARY) 172ENDIF (GLOG_FOUND) 173