Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: add Find<package>.cmake find module method for thrift #1020

Merged
merged 2 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -223,7 +225,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/modules/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()