Skip to content

Commit

Permalink
Allow to build WITH_JAEGER in Visual Studio 2019 + CMake (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgolov authored Jun 2, 2021
1 parent 5767f8e commit 1c70f0e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ cmake_policy(SET CMP0057 NEW)

project(opentelemetry-cpp)

# Mark variables as used so cmake doesn't complain about them
mark_as_advanced(CMAKE_TOOLCHAIN_FILE)

# Autodetect vcpkg toolchain
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE
"$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()

if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
endif()

file(READ "${CMAKE_CURRENT_LIST_DIR}/api/include/opentelemetry/version.h"
OPENTELEMETRY_CPP_HEADER_VERSION_H)
if(OPENTELEMETRY_CPP_HEADER_VERSION_H MATCHES
Expand Down Expand Up @@ -92,6 +106,7 @@ option(WITH_JAEGER "Whether to include the Jaeger exporter" OFF)

option(BUILD_TESTING "Whether to enable tests" ON)
if(WIN32)
add_definitions(-DNOMINMAX)
if(BUILD_TESTING)
if(MSVC)
# GTest bug: https://github.com/google/googletest/issues/860
Expand Down Expand Up @@ -135,6 +150,16 @@ function(install_windows_deps)
PARENT_SCOPE)
endfunction()

if(WITH_JAEGER)
find_package(Thrift QUIET CONFIG)
if(NOT Thrift_FOUND)
# Install Thrift and propagate via vcpkg toolchain file
if(WIN32 AND (NOT DEFINED CMAKE_TOOLCHAIN_FILE))
install_windows_deps()
endif()
endif()
endif()

if(MSVC)
# Options for Visual C++ compiler: /Zc:__cplusplus - report an updated value
# for recent C++ language standards. Without this option MSVC returns the
Expand Down
3 changes: 3 additions & 0 deletions exporters/jaeger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
include_directories(thrift-gen)

find_package(Thrift REQUIRED)
# vcpkg config recipe points to THRIFT_INCLUDE_DIR=...\thrift . Ensure that the
# include dir for thrift-gen code is 1 level-up from that:
include_directories(SYSTEM ${THRIFT_INCLUDE_DIR}/..)

set(JAEGER_THRIFT_GENCPP_SOURCES
thrift-gen/Agent.cpp thrift-gen/jaeger_types.cpp thrift-gen/Collector.cpp
Expand Down
1 change: 1 addition & 0 deletions tools/setup-buildtools.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ vcpkg install protobuf:%ARCH%-windows
vcpkg install gRPC:%ARCH%-windows
vcpkg install prometheus-cpp:%ARCH%-windows
vcpkg install curl:%ARCH%-windows
vcpkg install thrift:%ARCH%-windows
popd
exit /b 0

0 comments on commit 1c70f0e

Please sign in to comment.