-
Notifications
You must be signed in to change notification settings - Fork 500
[CMAKE] Address the vcpkg opentelemetry-cpp port CMake patches #3518
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
Merged
marcalff
merged 7 commits into
open-telemetry:main
from
dbarker:cmake_vcpkg_otelcpp_port_fixes
Jul 9, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2ee4957
Find or fetch opentracing-cpp. Support the shared or static library t…
dbarker ce3b5c0
Don't force cmake to prefer CONFIG searches. Don't include the vcpkg …
dbarker 23ffbfd
unset BUILD_TESTING from the cache if it was not set before
dbarker 396f1b5
Test builting the opentracing-shim against the static opentracing lib…
dbarker e2ea986
Fix iwyu failure by disabling the unneeded MockTracer build from Open…
dbarker ac57c9e
update install test for opentracing-shim to also check for the opentr…
dbarker 2bd4c95
Merge branch 'main' into cmake_vcpkg_otelcpp_port_fixes
dbarker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,11 +36,6 @@ project(opentelemetry-cpp) | |
# Mark variables as used so cmake doesn't complain about them | ||
mark_as_advanced(CMAKE_TOOLCHAIN_FILE) | ||
|
||
# Note: CMAKE_FIND_PACKAGE_PREFER_CONFIG requires cmake 3.15. Prefer cmake | ||
# CONFIG search mode to find dependencies. This is important to properly find | ||
# protobuf versions 3.22.0 and above due to the abseil-cpp dependency. | ||
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) | ||
|
||
# Don't use customized cmake modules if vcpkg is used to resolve dependence. | ||
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) | ||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") | ||
|
@@ -79,10 +74,6 @@ if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) | |
CACHE STRING "") | ||
endif() | ||
|
||
if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE) | ||
include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") | ||
endif() | ||
|
||
option(WITH_ABI_VERSION_1 "ABI version 1" ON) | ||
option(WITH_ABI_VERSION_2 "EXPERIMENTAL: ABI version 2 preview" OFF) | ||
|
||
|
@@ -497,6 +488,14 @@ if((NOT WITH_API_ONLY) AND USE_NLOHMANN_JSON) | |
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/nlohmann-json.cmake") | ||
endif() | ||
|
||
# | ||
# Do we need OpenTracing ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The official vcpkg port still supports it as |
||
# | ||
|
||
if(WITH_OPENTRACING) | ||
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/opentracing-cpp.cmake") | ||
endif() | ||
|
||
if(OTELCPP_MAINTAINER_MODE) | ||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
message(STATUS "Building with gcc in maintainer mode.") | ||
|
@@ -703,6 +702,10 @@ endif() | |
if(prometheus-cpp_FOUND) | ||
message(STATUS "prometheus-cpp: ${prometheus-cpp_VERSION}") | ||
endif() | ||
if(WITH_OPENTRACING) | ||
marcalff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
message( | ||
STATUS "opentracing-cpp: ${OpenTracing_VERSION} (${OpenTracing_PROVIDER})") | ||
endif() | ||
message(STATUS "---------------------------------------------") | ||
|
||
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/otel-install-functions.cmake") | ||
|
@@ -726,30 +729,6 @@ endif() | |
add_subdirectory(api) | ||
|
||
if(WITH_OPENTRACING) | ||
find_package(OpenTracing CONFIG QUIET) | ||
if(NOT OpenTracing_FOUND) | ||
set(OPENTRACING_DIR "third_party/opentracing-cpp") | ||
message(STATUS "Trying to use local ${OPENTRACING_DIR} from submodule") | ||
if(EXISTS "${PROJECT_SOURCE_DIR}/${OPENTRACING_DIR}/.git") | ||
set(SAVED_BUILD_TESTING ${BUILD_TESTING}) | ||
set(BUILD_TESTING OFF) | ||
set(SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE | ||
${CMAKE_CXX_INCLUDE_WHAT_YOU_USE}) | ||
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "") | ||
add_subdirectory(${OPENTRACING_DIR}) | ||
set(BUILD_TESTING ${SAVED_BUILD_TESTING}) | ||
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE | ||
${SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}) | ||
else() | ||
message( | ||
FATAL_ERROR | ||
"\nopentracing-cpp package was not found. Please either provide it manually or clone with submodules. " | ||
"To initialize, fetch and checkout any nested submodules, you can use the following command:\n" | ||
"git submodule update --init --recursive") | ||
endif() | ||
else() | ||
message(STATUS "Using external opentracing-cpp") | ||
endif() | ||
add_subdirectory(opentracing-shim) | ||
endif() | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
find_package(OpenTracing CONFIG QUIET) | ||
set(OpenTracing_PROVIDER "find_package") | ||
|
||
if(NOT OpenTracing_FOUND) | ||
set(_OPENTRACING_SUBMODULE_DIR "${opentelemetry-cpp_SOURCE_DIR}/third_party/opentracing-cpp") | ||
if(EXISTS "${_OPENTRACING_SUBMODULE_DIR}/.git") | ||
FetchContent_Declare( | ||
"opentracing" | ||
SOURCE_DIR "${_OPENTRACING_SUBMODULE_DIR}" | ||
) | ||
set(OpenTracing_PROVIDER "fetch_source") | ||
else() | ||
FetchContent_Declare( | ||
"opentracing" | ||
GIT_REPOSITORY "https://github.com/opentracing/opentracing-cpp.git" | ||
GIT_TAG "${opentracing-cpp_GIT_TAG}" | ||
) | ||
set(OpenTracing_PROVIDER "fetch_repository") | ||
endif() | ||
|
||
# OpenTracing uses the BUILD_TESTING variable directly and we must force the cached value to OFF. | ||
# save the current state of BUILD_TESTING | ||
if(DEFINED BUILD_TESTING) | ||
set(_SAVED_BUILD_TESTING ${BUILD_TESTING}) | ||
endif() | ||
|
||
# Set the cache variables for the opentracing build | ||
set(BUILD_TESTING OFF CACHE BOOL "" FORCE) | ||
set(BUILD_MOCKTRACER OFF CACHE BOOL "" FORCE) | ||
|
||
FetchContent_MakeAvailable(opentracing) | ||
|
||
# Restore the saved state of BUILD_TESTING | ||
if(DEFINED _SAVED_BUILD_TESTING) | ||
set(BUILD_TESTING ${_SAVED_BUILD_TESTING} CACHE BOOL "" FORCE) | ||
else() | ||
unset(BUILD_TESTING CACHE) | ||
endif() | ||
|
||
# Patch the opentracing targets to set missing includes, add namespaced alias targets, disable iwyu and clang-tidy. | ||
foreach(_target opentracing opentracing-static) | ||
if(TARGET ${_target}) | ||
# Add missing include directories | ||
target_include_directories(${_target} PUBLIC | ||
"$<BUILD_INTERFACE:${opentracing_SOURCE_DIR}/include>" | ||
"$<BUILD_INTERFACE:${opentracing_SOURCE_DIR}/3rd_party/include>" | ||
"$<BUILD_INTERFACE:${opentracing_BINARY_DIR}/include>" | ||
) | ||
# Disable CXX_INCLUDE_WHAT_YOU_USE and CXX_CLANG_TIDY | ||
set_target_properties(${_target} | ||
PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" CXX_CLANG_TIDY "") | ||
# Create alias targets | ||
if(NOT TARGET OpenTracing::${_target}) | ||
add_library(OpenTracing::${_target} ALIAS ${_target}) | ||
endif() | ||
endif() | ||
endforeach() | ||
|
||
# Set the OpenTracing_VERSION variable from the git tag. | ||
string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" OpenTracing_VERSION "${opentracing-cpp_GIT_TAG}") | ||
endif(NOT OpenTracing_FOUND) | ||
|
||
if(NOT TARGET OpenTracing::opentracing AND NOT TARGET OpenTracing::opentracing-static) | ||
message(FATAL_ERROR "No OpenTracing targets (OpenTracing::opentracing or OpenTracing::opentracing-static) were imported") | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this now that GTest, Protobuf, and gRPC are found with the CONFIG search mode explicitly.