diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f2f7ef7cc..0c04d83175 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 @@ -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 diff --git a/exporters/jaeger/CMakeLists.txt b/exporters/jaeger/CMakeLists.txt index c3704c6661..030c7e77bb 100644 --- a/exporters/jaeger/CMakeLists.txt +++ b/exporters/jaeger/CMakeLists.txt @@ -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 diff --git a/tools/setup-buildtools.cmd b/tools/setup-buildtools.cmd index 7a215fc3cf..7819aaf792 100644 --- a/tools/setup-buildtools.cmd +++ b/tools/setup-buildtools.cmd @@ -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