-
Notifications
You must be signed in to change notification settings - Fork 500
[CMAKE] Add CMake script to find or fetch prometheus-cpp #3522
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 3 commits into
open-telemetry:main
from
dbarker:cmake_find_or_fetch_prometheus_cpp
Jul 9, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Import prometheus-cpp targets (prometheus-cpp::core and prometheus-cpp::pull) | ||
# 1. Find an installed prometheus-cpp package | ||
# 2. Use FetchContent to build prometheus-cpp from a git submodule | ||
# 3. Use FetchContent to fetch and build prometheus-cpp from GitHub | ||
|
||
find_package(prometheus-cpp CONFIG QUIET) | ||
set(prometheus-cpp_PROVIDER "find_package") | ||
|
||
if(NOT prometheus-cpp_FOUND) | ||
set(_PROMETHEUS_SUBMODULE_DIR "${opentelemetry-cpp_SOURCE_DIR}/third_party/prometheus-cpp") | ||
if(EXISTS "${_PROMETHEUS_SUBMODULE_DIR}/.git") | ||
FetchContent_Declare( | ||
"prometheus-cpp" | ||
SOURCE_DIR "${_PROMETHEUS_SUBMODULE_DIR}" | ||
) | ||
set(prometheus-cpp_PROVIDER "fetch_source") | ||
else() | ||
FetchContent_Declare( | ||
"prometheus-cpp" | ||
GIT_REPOSITORY "https://github.com/jupp0r/prometheus-cpp.git" | ||
GIT_TAG "${prometheus-cpp_GIT_TAG}" | ||
GIT_SUBMODULES "3rdparty/civetweb" | ||
) | ||
set(prometheus-cpp_PROVIDER "fetch_repository") | ||
endif() | ||
|
||
if(DEFINED ENABLE_TESTING) | ||
set(_SAVED_ENABLE_TESTING ${ENABLE_TESTING}) | ||
endif() | ||
|
||
set(ENABLE_TESTING OFF CACHE BOOL "" FORCE) | ||
set(ENABLE_PUSH OFF CACHE BOOL "" FORCE) | ||
set(USE_THIRDPARTY_LIBRARIES ON CACHE BOOL "" FORCE) | ||
|
||
FetchContent_MakeAvailable(prometheus-cpp) | ||
|
||
if(DEFINED _SAVED_ENABLE_TESTING) | ||
set(ENABLE_TESTING ${_SAVED_ENABLE_TESTING} CACHE BOOL "" FORCE) | ||
else() | ||
unset(ENABLE_TESTING CACHE) | ||
endif() | ||
|
||
# Set the prometheus-cpp_VERSION variable from the git tag. | ||
string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" prometheus-cpp_VERSION "${prometheus-cpp_GIT_TAG}") | ||
|
||
# Disable iwyu and clang-tidy | ||
foreach(_prometheus_target core pull civetweb) | ||
set_target_properties(${_prometheus_target} PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" | ||
CXX_CLANG_TIDY "") | ||
endforeach() | ||
endif() | ||
|
||
if(NOT TARGET prometheus-cpp::core OR | ||
NOT TARGET prometheus-cpp::pull) | ||
message(FATAL_ERROR "A required prometheus-cpp target (prometheus-cpp::core or prometheus-cpp::pull) was not 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
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.
Uh oh!
There was an error while loading. Please reload this page.