xref: /aosp_15_r20/external/pytorch/cmake/public/gflags.cmake (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1# ---[ gflags
2
3# We will try to use the config mode first, and then manual find.
4find_package(gflags CONFIG QUIET)
5if(NOT TARGET gflags)
6  find_package(gflags MODULE QUIET)
7endif()
8
9if(TARGET gflags)
10  message(STATUS "Caffe2: Found gflags with new-style gflags target.")
11elseif(GFLAGS_FOUND)
12  message(STATUS "Caffe2: Found gflags with old-style gflag starget.")
13  add_library(gflags UNKNOWN IMPORTED)
14  set_property(
15      TARGET gflags PROPERTY IMPORTED_LOCATION ${GFLAGS_LIBRARY})
16  set_property(
17      TARGET gflags PROPERTY INTERFACE_INCLUDE_DIRECTORIES
18      ${GFLAGS_INCLUDE_DIR})
19else()
20  message(STATUS
21      "Caffe2: Cannot find gflags automatically. Using legacy find.")
22
23  # - Try to find GFLAGS in the legacy way.
24  #
25  # The following variables are optionally searched for defaults
26  #  GFLAGS_ROOT_DIR: Base directory where all GFLAGS components are found
27  #
28  # The following are set after configuration is done:
29  #  GFLAGS_FOUND
30  #  GFLAGS_INCLUDE_DIRS
31  #  GFLAGS_LIBRARIES
32  #  GFLAGS_LIBRARYRARY_DIRS
33  include(FindPackageHandleStandardArgs)
34  set(GFLAGS_ROOT_DIR "" CACHE PATH "Folder contains Gflags")
35
36  # We are testing only a couple of files in the include directories
37  if(WIN32)
38    find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
39        PATHS ${GFLAGS_ROOT_DIR}/src/windows)
40  else()
41    find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
42        PATHS ${GFLAGS_ROOT_DIR})
43  endif()
44
45  if(WIN32)
46    find_library(GFLAGS_LIBRARY_RELEASE
47        NAMES libgflags
48        PATHS ${GFLAGS_ROOT_DIR}
49        PATH_SUFFIXES Release)
50
51    find_library(GFLAGS_LIBRARY_DEBUG
52        NAMES libgflags-debug
53        PATHS ${GFLAGS_ROOT_DIR}
54        PATH_SUFFIXES Debug)
55    set(GFLAGS_LIBRARY optimized ${GFLAGS_LIBRARY_RELEASE} debug ${GFLAGS_LIBRARY_DEBUG})
56  else()
57    find_library(GFLAGS_LIBRARY gflags)
58  endif()
59
60  find_package_handle_standard_args(
61      gflags DEFAULT_MSG GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY)
62
63  if(GFLAGS_FOUND)
64    message(
65        STATUS
66        "Caffe2: Found gflags  (include: ${GFLAGS_INCLUDE_DIR}, "
67        "library: ${GFLAGS_LIBRARY})")
68    add_library(gflags UNKNOWN IMPORTED)
69    set_property(
70        TARGET gflags PROPERTY IMPORTED_LOCATION ${GFLAGS_LIBRARY})
71    set_property(
72        TARGET gflags PROPERTY INTERFACE_INCLUDE_DIRECTORIES
73        ${GFLAGS_INCLUDE_DIR})
74  endif()
75endif()
76
77# After above, we should have the gflags target now.
78if(NOT TARGET gflags)
79  message(WARNING
80      "Caffe2: gflags cannot be found. Depending on whether you are building "
81      "Caffe2 or a Caffe2 dependent library, the next warning / error will "
82      "give you more info.")
83endif()
84