Skip to content

Commit

Permalink
cmake: add cmake Find<package>.cmake for thrift
Browse files Browse the repository at this point in the history
In some cases, when using jaeger-cpp-client, we use thrift provided from
distro packages, these does not contain thriftConfig.cmake.
For such scenarios, we pivot to do not make find_package CONFIG mode as
default, instead we use basic signature[0]. We make use of
`CMAKE_MODULE_PATH` to search for FindThrift.cmake, which will find and
set all thrift::thrift's target properties.

[0] https://cmake.org/cmake/help/latest/command/find_package.html
The command arguments determine which of the above modes is used. When
the basic signature is used, the command searches in Module mode first.
If the package is not found, the search falls back to Config mode.

Signed-off-by: Deepika Upadhyay <[email protected]>
  • Loading branch information
Deepika Upadhyay committed Oct 19, 2021
1 parent 5aa7365 commit 4dceddc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ function(install_windows_deps)
endfunction()

if(WITH_JAEGER)
find_package(Thrift QUIET CONFIG)
find_package(Thrift QUIET)
if(NOT Thrift_FOUND)
# Install Thrift and propagate via vcpkg toolchain file
if(WIN32 AND (NOT DEFINED CMAKE_TOOLCHAIN_FILE))
Expand Down
31 changes: 31 additions & 0 deletions cmake/FindThrift.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This module defines Thrift_LIBRARIES, libraries to link Thrift_INCLUDE_DIR,
# Thrift_FOUND, If false, do not try to use it.

# prefer the Thrift version supplied in Thrift_HOME (cmake -DThrift_HOME then
# environment)
find_path(
Thrift_INCLUDE_DIR
NAMES thrift/Thrift.h
HINTS ${Thrift_HOME} ENV Thrift_HOME /usr/local /opt/local
PATH_SUFFIXES include)

# prefer the Thrift version supplied in Thrift_HOME
find_library(
Thrift_LIBRARIES
NAMES thrift libthrift
HINTS ${Thrift_HOME} ENV Thrift_HOME /usr/local /opt/local
PATH_SUFFIXES lib lib64)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Thrift DEFAULT_MSG Thrift_LIBRARIES
Thrift_INCLUDE_DIR)
mark_as_advanced(Thrift_LIBRARIES Thrift_INCLUDE_DIR)


if(Thrift_FOUND AND NOT (TARGET thrift::thrift))
add_library(thrift::thrift UNKNOWN IMPORTED)
set_target_properties(
thrift::thrift
PROPERTIES IMPORTED_LOCATION ${thrift_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${thrift_INCLUDE_DIR})
endif()
2 changes: 1 addition & 1 deletion exporters/jaeger/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ target_include_directories(
target_link_libraries(
opentelemetry_exporter_jaeger_trace
PUBLIC opentelemetry_resources http_client_curl
PRIVATE thrift::thrift)
INTERFACE thrift::thrift)

if(MSVC)
target_compile_definitions(opentelemetry_exporter_jaeger_trace
Expand Down

0 comments on commit 4dceddc

Please sign in to comment.