xref: /aosp_15_r20/external/pytorch/cmake/public/glog.cmake (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1# ---[ glog
2
3# We will try to use the config mode first, and then manual find.
4find_package(glog CONFIG QUIET)
5if(NOT TARGET glog::glog)
6  find_package(glog MODULE QUIET)
7endif()
8
9if(TARGET glog::glog)
10  message(STATUS "Caffe2: Found glog with new-style glog target.")
11elseif(GLOG_FOUND)
12  message(
13      STATUS
14      "Caffe2: Found glog with old-style glog starget. Glog never shipped "
15      "old style glog targets, so somewhere in your cmake path there might "
16      "be a custom Findglog.cmake file that got triggered. We will make a "
17      "best effort to create the new style glog target for you.")
18  add_library(glog::glog UNKNOWN IMPORTED)
19  set_property(
20      TARGET glog::glog PROPERTY IMPORTED_LOCATION ${GLOG_LIBRARY})
21  set_property(
22      TARGET glog::glog PROPERTY INTERFACE_INCLUDE_DIRECTORIES
23      ${GLOG_INCLUDE_DIR})
24else()
25  message(STATUS "Caffe2: Cannot find glog automatically. Using legacy find.")
26
27  # - Try to find Glog
28  #
29  # The following variables are optionally searched for defaults
30  #  GLOG_ROOT_DIR: Base directory where all GLOG components are found
31  #
32  # The following are set after configuration is done:
33  #  GLOG_FOUND
34  #  GLOG_INCLUDE_DIRS
35  #  GLOG_LIBRARIES
36  #  GLOG_LIBRARYRARY_DIRS
37
38  include(FindPackageHandleStandardArgs)
39  set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog")
40  if(NOT WIN32)
41      find_path(GLOG_INCLUDE_DIR glog/logging.h
42          PATHS ${GLOG_ROOT_DIR})
43  endif()
44
45  find_library(GLOG_LIBRARY glog
46      PATHS ${GLOG_ROOT_DIR}
47      PATH_SUFFIXES lib lib64)
48
49  find_package_handle_standard_args(glog DEFAULT_MSG GLOG_INCLUDE_DIR GLOG_LIBRARY)
50
51  if(GLOG_FOUND)
52    message(STATUS
53        "Caffe2: Found glog (include: ${GLOG_INCLUDE_DIR}, "
54        "library: ${GLOG_LIBRARY})")
55    add_library(glog::glog UNKNOWN IMPORTED)
56    set_property(
57        TARGET glog::glog PROPERTY IMPORTED_LOCATION ${GLOG_LIBRARY})
58    set_property(
59        TARGET glog::glog PROPERTY INTERFACE_INCLUDE_DIRECTORIES
60        ${GLOG_INCLUDE_DIR})
61  endif()
62endif()
63
64# After above, we should have the glog::glog target now.
65if(NOT TARGET glog::glog)
66  message(WARNING
67      "Caffe2: glog cannot be found. Depending on whether you are building "
68      "Caffe2 or a Caffe2 dependent library, the next warning / error will "
69      "give you more info.")
70endif()
71