Debian Codegraph @

cmake/FindGlog.cmake

raw
1 # Copyright (c), ETH Zurich and UNC Chapel Hill.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 #
14 # * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of
15 # its contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29
30
31 # Find package module for Glog library.
32 #
33 # The following variables are set by this module:
34 #
35 # GLOG_FOUND: TRUE if Glog is found.
36 # glog::glog: Imported target to link against.
37 #
38 # The following variables control the behavior of this module:
39 #
40 # GLOG_INCLUDE_DIR_HINTS: List of additional directories in which to
41 # search for Glog includes.
42 # GLOG_LIBRARY_DIR_HINTS: List of additional directories in which to
43 # search for Glog libraries.
44
45 set(GLOG_INCLUDE_DIR_HINTS "" CACHE PATH "Glog include directory")
46 set(GLOG_LIBRARY_DIR_HINTS "" CACHE PATH "Glog library directory")
47
48 unset(GLOG_FOUND)
49
50 find_package(glog CONFIG QUIET)
51 if(TARGET glog::glog)
52 set(GLOG_FOUND TRUE)
53 message(STATUS "Found Glog")
54 message(STATUS " Target : glog::glog")
55 else()
56 # Older versions of glog don't come with a find_package config.
57 # Fall back to custom logic to find the library and remap to imported target.
58
59 include(FindPackageHandleStandardArgs)
60
61 list(APPEND GLOG_CHECK_INCLUDE_DIRS
62 /usr/local/include
63 /usr/local/homebrew/include
64 /opt/local/var/macports/software
65 /opt/local/include
66 /usr/include)
67 list(APPEND GLOG_CHECK_PATH_SUFFIXES
68 glog/include
69 glog/Include
70 Glog/include
71 Glog/Include
72 src/windows)
73
74 list(APPEND GLOG_CHECK_LIBRARY_DIRS
75 /usr/local/lib
76 /usr/local/homebrew/lib
77 /opt/local/lib
78 /usr/lib)
79 list(APPEND GLOG_CHECK_LIBRARY_SUFFIXES
80 glog/lib
81 glog/Lib
82 Glog/lib
83 Glog/Lib
84 x64/Release)
85
86 find_path(GLOG_INCLUDE_DIRS
87 NAMES
88 glog/logging.h
89 PATHS
90 ${GLOG_INCLUDE_DIR_HINTS}
91 ${GLOG_CHECK_INCLUDE_DIRS}
92 PATH_SUFFIXES
93 ${GLOG_CHECK_PATH_SUFFIXES})
94 find_library(GLOG_LIBRARIES
95 NAMES
96 glog
97 libglog
98 PATHS
99 ${GLOG_LIBRARY_DIR_HINTS}
100 ${GLOG_CHECK_LIBRARY_DIRS}
101 PATH_SUFFIXES
102 ${GLOG_CHECK_LIBRARY_SUFFIXES})
103
104 if(GLOG_INCLUDE_DIRS AND GLOG_LIBRARIES)
105 set(GLOG_FOUND TRUE)
106 message(STATUS "Found Glog")
107 message(STATUS " Includes : ${GLOG_INCLUDE_DIRS}")
108 message(STATUS " Libraries : ${GLOG_LIBRARIES}")
109 endif()
110
111 add_library(glog::glog INTERFACE IMPORTED)
112 target_include_directories(glog::glog INTERFACE ${GLOG_INCLUDE_DIRS})
113 target_link_libraries(glog::glog INTERFACE ${GLOG_LIBRARIES})
114 endif()
115
116 if(NOT GLOG_FOUND AND GLOG_FIND_REQUIRED)
117 message(FATAL_ERROR "Could not find Glog")
118 endif()