From 5e363fb6a437ffb28f537dd6d1109c37dafd717e Mon Sep 17 00:00:00 2001 From: Deepika Upadhyay Date: Tue, 19 Oct 2021 17:54:00 +0530 Subject: [PATCH] cmake: add cmake Find.cmake for thrift 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. This appends cmake/modules dir to CMAKE_MODULE_PATH, which is used as all modules requiring find_package mode with basic_signature. [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 --- CMakeLists.txt | 4 +++- cmake/modules/FindThrift.cmake | 31 +++++++++++++++++++++++++++++++ exporters/jaeger/CMakeLists.txt | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 cmake/modules/FindThrift.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 272e10927b..fa780cba85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,8 @@ project(opentelemetry-cpp) # Mark variables as used so cmake doesn't complain about them mark_as_advanced(CMAKE_TOOLCHAIN_FILE) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") + if(DEFINED ENV{ARCH}) # Architecture may be specified via ARCH environment variable set(ARCH $ENV{ARCH}) @@ -219,7 +221,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)) diff --git a/cmake/modules/FindThrift.cmake b/cmake/modules/FindThrift.cmake new file mode 100644 index 0000000000..848754c949 --- /dev/null +++ b/cmake/modules/FindThrift.cmake @@ -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() diff --git a/exporters/jaeger/CMakeLists.txt b/exporters/jaeger/CMakeLists.txt index 0ae9162c61..966b3d476c 100644 --- a/exporters/jaeger/CMakeLists.txt +++ b/exporters/jaeger/CMakeLists.txt @@ -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