| 1 |
# Copyright (c) Facebook, Inc. and its affiliates. |
| 2 |
# Find libgflags. |
| 3 |
# There's a lot of compatibility cruft going on in here, both |
| 4 |
# to deal with changes across the FB consumers of this and also |
| 5 |
# to deal with variances in behavior of cmake itself. |
| 6 |
# |
| 7 |
# Since this file is named FindGflags.cmake the cmake convention |
| 8 |
# is for the module to export both GFLAGS_FOUND and Gflags_FOUND. |
| 9 |
# The convention expected by consumers is that we export the |
| 10 |
# following variables, even though these do not match the cmake |
| 11 |
# conventions: |
| 12 |
# |
| 13 |
# LIBGFLAGS_INCLUDE_DIR - where to find gflags/gflags.h, etc. |
| 14 |
# LIBGFLAGS_LIBRARY - List of libraries when using libgflags. |
| 15 |
# LIBGFLAGS_FOUND - True if libgflags found. |
| 16 |
# |
| 17 |
# We need to be able to locate gflags both from an installed |
| 18 |
# cmake config file and just from the raw headers and libs, so |
| 19 |
# test for the former and then the latter, and then stick |
| 20 |
# the results together and export them into the variables |
| 21 |
# listed above. |
| 22 |
# |
| 23 |
# For forwards compatibility, we export the following variables: |
| 24 |
# |
| 25 |
# gflags_INCLUDE_DIR - where to find gflags/gflags.h, etc. |
| 26 |
# gflags_TARGET / GFLAGS_TARGET / gflags_LIBRARIES |
| 27 |
# - List of libraries when using libgflags. |
| 28 |
# gflags_FOUND - True if libgflags found. |
| 29 |
# |
| 30 |
|
| 31 |
IF (LIBGFLAGS_INCLUDE_DIR) |
| 32 |
# Already in cache, be silent |
| 33 |
SET(Gflags_FIND_QUIETLY TRUE) |
| 34 |
ENDIF () |
| 35 |
|
| 36 |
find_package(gflags CONFIG QUIET) |
| 37 |
if (gflags_FOUND) |
| 38 |
if (NOT Gflags_FIND_QUIETLY) |
| 39 |
message(STATUS "Found gflags from package config ${gflags_CONFIG}") |
| 40 |
endif() |
| 41 |
# Re-export the config-specified libs with our local names |
| 42 |
set(LIBGFLAGS_LIBRARY ${gflags_LIBRARIES}) |
| 43 |
set(LIBGFLAGS_INCLUDE_DIR ${gflags_INCLUDE_DIR}) |
| 44 |
if(NOT EXISTS "${gflags_INCLUDE_DIR}") |
| 45 |
# The gflags-devel RPM on recent RedHat-based systems is somewhat broken. |
| 46 |
# RedHat symlinks /lib64 to /usr/lib64, and this breaks some of the |
| 47 |
# relative path computation performed in gflags-config.cmake. The package |
| 48 |
# config file ends up being found via /lib64, but the relative path |
| 49 |
# computation it does only works if it was found in /usr/lib64. |
| 50 |
# If gflags_INCLUDE_DIR does not actually exist, simply default it to |
| 51 |
# /usr/include on these systems. |
| 52 |
set(LIBGFLAGS_INCLUDE_DIR "/usr/include") |
| 53 |
set(GFLAGS_INCLUDE_DIR "/usr/include") |
| 54 |
endif() |
| 55 |
set(LIBGFLAGS_FOUND ${gflags_FOUND}) |
| 56 |
# cmake module compat |
| 57 |
set(GFLAGS_FOUND ${gflags_FOUND}) |
| 58 |
set(Gflags_FOUND ${gflags_FOUND}) |
| 59 |
else() |
| 60 |
FIND_PATH(LIBGFLAGS_INCLUDE_DIR gflags/gflags.h) |
| 61 |
|
| 62 |
FIND_LIBRARY(LIBGFLAGS_LIBRARY_DEBUG NAMES gflagsd gflags_staticd) |
| 63 |
FIND_LIBRARY(LIBGFLAGS_LIBRARY_RELEASE NAMES gflags gflags_static) |
| 64 |
|
| 65 |
INCLUDE(SelectLibraryConfigurations) |
| 66 |
SELECT_LIBRARY_CONFIGURATIONS(LIBGFLAGS) |
| 67 |
|
| 68 |
# handle the QUIETLY and REQUIRED arguments and set LIBGFLAGS_FOUND to TRUE if |
| 69 |
# all listed variables are TRUE |
| 70 |
INCLUDE(FindPackageHandleStandardArgs) |
| 71 |
FIND_PACKAGE_HANDLE_STANDARD_ARGS(gflags DEFAULT_MSG LIBGFLAGS_LIBRARY LIBGFLAGS_INCLUDE_DIR) |
| 72 |
# cmake module compat |
| 73 |
set(Gflags_FOUND ${GFLAGS_FOUND}) |
| 74 |
# compat with some existing FindGflags consumers |
| 75 |
set(LIBGFLAGS_FOUND ${GFLAGS_FOUND}) |
| 76 |
|
| 77 |
# Compat with the gflags CONFIG based detection |
| 78 |
set(gflags_FOUND ${GFLAGS_FOUND}) |
| 79 |
set(gflags_INCLUDE_DIR ${LIBGFLAGS_INCLUDE_DIR}) |
| 80 |
set(gflags_LIBRARIES ${LIBGFLAGS_LIBRARY}) |
| 81 |
set(GFLAGS_TARGET ${LIBGFLAGS_LIBRARY}) |
| 82 |
set(gflags_TARGET ${LIBGFLAGS_LIBRARY}) |
| 83 |
|
| 84 |
MARK_AS_ADVANCED(LIBGFLAGS_LIBRARY LIBGFLAGS_INCLUDE_DIR) |
| 85 |
endif() |
| 86 |
|
| 87 |
# Compat with the gflags CONFIG based detection |
| 88 |
if (LIBGFLAGS_FOUND AND NOT TARGET gflags) |
| 89 |
add_library(gflags UNKNOWN IMPORTED) |
| 90 |
if(TARGET gflags-shared) |
| 91 |
# If the installed gflags CMake package config defines a gflags-shared |
| 92 |
# target but not gflags, just make the gflags target that we define |
| 93 |
# depend on the gflags-shared target. |
| 94 |
target_link_libraries(gflags INTERFACE gflags-shared) |
| 95 |
# Export LIBGFLAGS_LIBRARY as the gflags-shared target in this case. |
| 96 |
set(LIBGFLAGS_LIBRARY gflags-shared) |
| 97 |
else() |
| 98 |
set_target_properties( |
| 99 |
gflags |
| 100 |
PROPERTIES |
| 101 |
IMPORTED_LINK_INTERFACE_LANGUAGES "C" |
| 102 |
IMPORTED_LOCATION "${LIBGFLAGS_LIBRARY}" |
| 103 |
INTERFACE_INCLUDE_DIRECTORIES "${LIBGFLAGS_INCLUDE_DIR}" |
| 104 |
) |
| 105 |
endif() |
| 106 |
endif() |