Skip to content

[CMAKE] Add support for CMake component deprecation and update the policy#4272

Open
dbarker wants to merge 9 commits into
open-telemetry:mainfrom
dbarker:cmake_support_component_deprecation
Open

[CMAKE] Add support for CMake component deprecation and update the policy#4272
dbarker wants to merge 9 commits into
open-telemetry:mainfrom
dbarker:cmake_support_component_deprecation

Conversation

@dbarker

@dbarker dbarker commented Jul 21, 2026

Copy link
Copy Markdown
Member

Fixes # (issue)

The project provides CMake components in the installed package for use with find_package(opentelemetry-cpp COMPONENTS ...). The names of the components and targets they import are user facing and need a path for deprecation as things change.

Some use cases for this include:

  • merging components:
    The config builder components can be merged with the exporter components they depend on since they bring in no new dependencies.
  • moving components to opentelemetry-cpp-contrib.

This PR adds support to the otel_install_component CMake function for renaming and merging components while deprecating old component names. Users who call find_package on a deprecated component name will see a deprecation warning while the old component name resolves to the new component name.

This change is a part of #4240 and tested in that PR.

Changes

  • update CMake install scripts in ./cmake/
    • Add DEPRECATED_NAMES and DEPRECATED fields to the otel_install_component function
  • update the installed CMake template files to support resolving deprecated component names to the new component names.
  • update the deprecation policy to include CMake components.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@dbarker
dbarker marked this pull request as ready for review July 21, 2026 18:56
@dbarker
dbarker requested a review from a team as a code owner July 21, 2026 18:56
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.24%. Comparing base (cf62199) to head (1b861d9).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4272      +/-   ##
==========================================
- Coverage   81.25%   81.24%   -0.01%     
==========================================
  Files         446      446              
  Lines       18872    18872              
==========================================
- Hits        15332    15330       -2     
- Misses       3540     3542       +2     

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lalitb

lalitb commented Jul 23, 2026

Copy link
Copy Markdown
Member

Thanks @dbarker. This makes sense for #4240 and lets us merge the builder components without breaking existing users. Just wondering if we should keep this PR focused on on DEPRECATED_NAMES, add a small test here, and leave the unfinished DEPRECATED support for later when we have a real use case.

Comment thread cmake/find-package-support-functions.cmake
…ake file. Add test for component deprecation. Update ci scripts to support running the tests. Add the tests to the cmake.install CI workflow. Address review feedback - set old_component_FOUND when the new name is resolved
@dbarker

dbarker commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

Thanks @dbarker. This makes sense for #4240 and lets us merge the builder components without breaking existing users. Just wondering if we should keep this PR focused on on DEPRECATED_NAMES, add a small test here, and leave the unfinished DEPRECATED support for later when we have a real use case.

Thanks @lalitb. I've addressed the feedback. To add the small test I've moved the existing install "usage tests" into an install_functions_test folder and created new ci script targets for cmake.install_functions.test. This test injects a mock deprecated component into the build and verifies it is resolved correctly through find_package. I've also added setting the deprecated components _FOUND flag. Let me know if you spot anything else.

get_property(_REPLACEMENT_COMPONENT DIRECTORY ${PROJECT_SOURCE_DIR}
PROPERTY OTEL_COMPONENT_REPLACEMENT_${_DEPRECATED_COMPONENT})
message(STATUS " Deprecated COMPONENT ${_DEPRECATED_COMPONENT}")
if(_REPLACEMENT_COMPONENT)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alias resolver is single-pass over the original request list: foreach(_COMPONENT IN LISTS ${requested_components_inout}) iterates the input, and the replacement is only list(APPEND)-ed to _result, so a replacement that is itself deprecated is never resolved further. That makes this a one-hop lookup rather than a resolve-to-final.

function(resolve_deprecated_components requested_components_inout)
set(_result ${${requested_components_inout}})
foreach(_COMPONENT IN LISTS ${requested_components_inout})
if(${_COMPONENT} IN_LIST OTEL_DEPRECATED_COMPONENTS_LIST)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if() re-dereferences an unquoted left operand that names a defined variable, so if(${_COMPONENT} IN_LIST ...) can take the wrong branch.

endif()

# Test components added:
set(TEST_COMPONENT_TARGETS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants