Skip to content

Commit

Permalink
fix detection and dep on glog::glog when building via cmake
Browse files Browse the repository at this point in the history
Summary:
folly exports a dependency on `glog::glog`.  That causes dependent packages to also depend implicitly on glog::glog with no way to resolve what that means, resulting in errors like this:

```
CMake Error at CMakeLists.txt:106 (add_library):
  Target "wangle" links to target "glog::glog" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
```

We cannot rely on `glog` having installed its configuration for a simple `find_package(glog CONFIG)`; the version of `glog` provided by some versions of ubuntu doesn't install a `.cmake` file for this.

That means that we need to detect it for ourselves.

This diff enhances the `FindGlog.cmake` script to define a `glog::glog` target so that we can consistently depend upon it throughout the set of related packages.

It is unfortunate that we have duplication of the `FindGlog.cmake` files across these projects; a follow up diff could place these in eg: fbcode_builder and arrange to have shipit to copy them to the right place at shipit time.

Reviewed By: strager

Differential Revision: D13482288

fbshipit-source-id: d19716871edce29019114030e4c82911ac345adb
  • Loading branch information
wez authored and facebook-github-bot committed Jan 22, 2019
1 parent f4c3e03 commit 2c95930
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ endif(compiler_only OR build_all)

# Find required dependencies for thrift/lib
if(lib_only OR build_all)
find_package(folly CONFIG REQUIRED)
find_package(GFlags REQUIRED)
find_package(Glog REQUIRED)
find_package(folly CONFIG REQUIRED)
find_package(Yarpl)
find_package(fizz CONFIG REQUIRED)
find_package(wangle CONFIG REQUIRED)
Expand Down
46 changes: 24 additions & 22 deletions thrift/cmake/FindGlog.cmake
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
# Find Glog
# - Try to find Glog
# Once done, this will define
#
# This will define:
# GLOG_FOUND
# GLOG_INCLUDE_DIRS
# GLOG_LIBRARIES
# GLOG_FOUND - system has Glog
# GLOG_INCLUDE_DIRS - the Glog include directories
# GLOG_LIBRARIES - link these to use Glog

find_path(
GLOG_INCLUDE_DIRS glog/logging.h
HINTS
$ENV{GLOG_ROOT}/include
${GLOG_ROOT}/include
)
include(FindPackageHandleStandardArgs)

find_library(
GLOG_LIBRARIES glog
HINTS
$ENV{GLOG_ROOT}/src
${GLOG_ROOT}/src
)
find_library(GLOG_LIBRARY glog
PATHS ${GLOG_LIBRARYDIR})

mark_as_advanced(GLOG_INCLUDE_DIRS GLOG_LIBRARIES)
find_path(GLOG_INCLUDE_DIR glog/logging.h
PATHS ${GLOG_INCLUDEDIR})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Glog GLOG_INCLUDE_DIRS GLOG_LIBRARIES)
find_package_handle_standard_args(glog DEFAULT_MSG
GLOG_LIBRARY
GLOG_INCLUDE_DIR)

mark_as_advanced(
GLOG_LIBRARY
GLOG_INCLUDE_DIR)

set(GLOG_LIBRARIES ${GLOG_LIBRARY})
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR})

if(GLOG_FOUND AND NOT GLOG_FIND_QUIETLY)
message(STATUS "GLOG: ${GLOG_INCLUDE_DIRS}")
if (NOT TARGET glog::glog)
add_library(glog::glog UNKNOWN IMPORTED)
set_target_properties(glog::glog PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GLOG_INCLUDE_DIRS}")
set_target_properties(glog::glog PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION "${GLOG_LIBRARIES}")
endif()

0 comments on commit 2c95930

Please sign in to comment.