-
Notifications
You must be signed in to change notification settings - Fork 513
[CMAKE] Add CMake scripts to find or fetch curl and find zlib #3526
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 4 commits into
open-telemetry:main
from
dbarker:cmake_cleanup_curl_and_zlib
Jul 15, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4b91ec0
Add cmake script to find or fetch curl. Add cmake script to find zlib…
dbarker d1a2485
fix curl version parsing from the git tag and logging when curl is fe…
dbarker e942ad8
Merge branch 'main' into cmake_cleanup_curl_and_zlib
dbarker da13a6d
Merge branch 'main' into cmake_cleanup_curl_and_zlib
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
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,76 @@ | ||
| # Copyright The OpenTelemetry Authors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Import the curl target (CURL::libcurl). | ||
| # 1. Find an installed curl package | ||
| # 2. Use FetchContent to fetch and build curl from GitHub | ||
|
|
||
| # Find the curl package with the default search mode | ||
| find_package(CURL QUIET) | ||
| set(CURL_PROVIDER "find_package") | ||
|
|
||
| if(NOT CURL_FOUND) | ||
| FetchContent_Declare( | ||
| "curl" | ||
| GIT_REPOSITORY "https://github.com/curl/curl.git" | ||
| GIT_TAG "${curl_GIT_TAG}" | ||
| ) | ||
| set(CURL_PROVIDER "fetch_repository") | ||
|
|
||
| if(OPENTELEMETRY_INSTALL) | ||
| set(_CURL_DISABLE_INSTALL OFF) | ||
| else() | ||
| set(_CURL_DISABLE_INSTALL ON) | ||
| endif() | ||
|
|
||
| if(DEFINED BUILD_SHARED_LIBS) | ||
| set(_SAVED_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) | ||
| endif() | ||
|
|
||
| set(CURL_DISABLE_INSTALL ${_CURL_DISABLE_INSTALL} CACHE BOOL "" FORCE) | ||
| set(CURL_USE_LIBPSL OFF CACHE BOOL "" FORCE) | ||
| set(BUILD_CURL_EXE OFF CACHE BOOL "" FORCE) | ||
| set(BUILD_LIBCURL_DOCS OFF CACHE BOOL "" FORCE) | ||
| set(BUILD_MISC_DOCS OFF CACHE BOOL "" FORCE) | ||
| set(ENABLE_CURL_MANUAL OFF CACHE BOOL "" FORCE) | ||
| set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE) | ||
|
|
||
| FetchContent_MakeAvailable(curl) | ||
|
|
||
| # Restore BUILD_SHARED_LIBS | ||
| if(DEFINED _SAVED_BUILD_SHARED_LIBS) | ||
| set(BUILD_SHARED_LIBS ${_SAVED_BUILD_SHARED_LIBS} CACHE BOOL "" FORCE) | ||
| else() | ||
| unset(BUILD_SHARED_LIBS CACHE) | ||
| endif() | ||
|
|
||
| # Set the CURL_VERSION variable from the git tag. | ||
| string(REGEX REPLACE "^curl-([0-9]+)_([0-9]+)_([0-9]+)$" "\\1.\\2.\\3" CURL_VERSION "${curl_GIT_TAG}") | ||
dbarker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # disable iwyu and clang-tidy | ||
| foreach(_curl_target libcurl_shared libcurl_static) | ||
| if(TARGET ${_curl_target}) | ||
| set_target_properties(${_curl_target} PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" | ||
| CXX_CLANG_TIDY "") | ||
| endif() | ||
| endforeach() | ||
| endif() | ||
|
|
||
| # Set the CURL_VERSION from the legacy CURL_VERSION_STRING Required for CMake | ||
| # versions below 4.0 | ||
| if(NOT CURL_VERSION AND CURL_VERSION_STRING) | ||
| set(CURL_VERSION ${CURL_VERSION_STRING}) | ||
| endif() | ||
|
|
||
| # Add the main CURL::libcurl alias target if missing. Prefer the shared target followed by the static target | ||
| if(NOT TARGET CURL::libcurl) | ||
| if(TARGET libcurl_shared) | ||
| add_library(CURL::libcurl ALIAS libcurl_shared) | ||
| elseif(TARGET libcurl_static) | ||
| add_library(CURL::libcurl ALIAS libcurl_static) | ||
marcalff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| endif() | ||
| endif() | ||
|
|
||
| if(NOT TARGET CURL::libcurl) | ||
| message(FATAL_ERROR "The required curl target (CURL::libcurl) 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright The OpenTelemetry Authors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # ZLIB must be found as an installed package for now. | ||
| # Fetching ZLIB and building in-tree is not supported. | ||
| # Protobuf, gRPC, prometheus-cpp, civetweb, CURL, and other dependencies require ZLIB and import its target. | ||
| # When ZLIB::ZLIB is an alias of the shared library then inconsistent linking may occur. | ||
|
|
||
| find_package(ZLIB REQUIRED) | ||
| set(ZLIB_PROVIDER "find_package") | ||
|
|
||
| # Set the ZLIB_VERSION from the legacy ZLIB_VERSION_STRING Required for CMake | ||
| # versions below 3.26 | ||
| if(NOT ZLIB_VERSION AND ZLIB_VERSION_STRING) | ||
| set(ZLIB_VERSION ${ZLIB_VERSION_STRING}) | ||
| endif() | ||
|
|
||
| if(NOT TARGET ZLIB::ZLIB) | ||
| message(FATAL_ERROR "The required zlib target (ZLIB::ZLIB) 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
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
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
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.