From 6b3c2ec3aed7b68ac025ff4dc9a86dc12ac52c9f Mon Sep 17 00:00:00 2001 From: Michel Lind Date: Tue, 15 Sep 2026 18:06:13 +0100 Subject: [PATCH] cmake: prefer glog's own CMake config over the FindGlog module glog >= 0.7 requires consumers to define GLOG_USE_GLOG_EXPORT, which its exported glog::glog target carries as an INTERFACE_COMPILE_DEFINITION. Our FindGlog module constructs its own imported glog::glog target from find_library/find_path results and never sets that definition, so on a distro shipping glog 0.7 (Fedora 44 has 0.7.1) every cachelib translation unit fails with: /usr/include/glog/logging.h:1228:30: error: expected primary-expression before 'public' folly/io/Cursor.h:834:5: error: 'LogMessageFatal' is not a member of 'google' Try find_package(glog CONFIG) first and only fall back to the manual search when no config file is installed. getdeps' from-source glog also ships a config file, so the fallback now only matters for glog builds installed without CMake support. The module's documented outputs are still honoured on the config path: GLOG_INCLUDE_DIR(S) is taken from the target's interface include directories and GLOG_LIBRARIES is set to glog::glog itself, so a consumer that links through the variable rather than the target still inherits the GLOG_USE_GLOG_EXPORT definition. In-tree callers all use the target directly. Tested on Fedora 44 in a single `getdeps.py --allow-system-packages build --no-tests cachelib` run together with the Fedora rpm mappings from facebook/CacheLib#488 and the manifest change that honours --no-tests for cachelib (#490); the build succeeds against glog-devel 0.7.1 with glog_DIR=/usr/lib64/cmake/glog in the CMake cache. A probe project using only ${GLOG_LIBRARIES}/${GLOG_INCLUDE_DIRS} compiles and links against glog 0.7.1 on the config path, and the fallback path (with CMAKE_DISABLE_FIND_PACKAGE_glog=TRUE) still yields GLOG_LIBRARIES=/usr/lib64/libglog.so and GLOG_INCLUDE_DIRS=/usr/include. Co-Authored-By: Claude Fable 5.1 Signed-off-by: Michel Lind --- cachelib/cmake/FindGlog.cmake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cachelib/cmake/FindGlog.cmake b/cachelib/cmake/FindGlog.cmake index dd25c90a1f..d98e89c944 100644 --- a/cachelib/cmake/FindGlog.cmake +++ b/cachelib/cmake/FindGlog.cmake @@ -18,9 +18,23 @@ # GLOG_FOUND - system has Glog # GLOG_INCLUDE_DIRS - the Glog include directories # GLOG_LIBRARIES - link these to use Glog +# glog::glog - imported target, preferred over the variables above include(FindPackageHandleStandardArgs) +# glog >= 0.7 only compiles when consumers see its exported target, which +# carries the GLOG_USE_GLOG_EXPORT definition. Prefer the upstream config and +# derive this module's documented variables from it; GLOG_LIBRARIES names the +# target so that linking through the variable still picks up the definition. +find_package(glog CONFIG QUIET) +if (TARGET glog::glog) + get_target_property(GLOG_INCLUDE_DIR glog::glog INTERFACE_INCLUDE_DIRECTORIES) + set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR}) + set(GLOG_LIBRARIES glog::glog) + set(GLOG_FOUND TRUE) + return() +endif() + find_library(GLOG_LIBRARY glog PATHS ${GLOG_LIBRARYDIR})