Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[CMAKE] remove global include_directories usage and rely on target properties #3426

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

Conversation

dbarker
Copy link
Contributor

@dbarker dbarker commented May 20, 2025

More cmake cleanup.

Changes

  • Remove more global include_directories calls in favor of target_include_directories. Make sure the targets relying on these global includes link/include what they need.
  • Make the api target an interface link to the sdk target
  • Remove usage of the sdk headers in the foo_* example libraries (These example libraries should link to the api only)

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

Copy link

netlify bot commented May 20, 2025

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit 37b0364
🔍 Latest deploy log https://app.netlify.com/projects/opentelemetry-cpp-api-docs/deploys/682ccf1fd4dfd800081d05b9

@dbarker dbarker changed the title remove global include_directories usage and rely on target properties [CMAKE] remove global include_directories usage and rely on target properties May 20, 2025
Copy link

codecov bot commented May 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.04%. Comparing base (29ac517) to head (37b0364).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3426   +/-   ##
=======================================
  Coverage   90.04%   90.04%           
=======================================
  Files         212      212           
  Lines        6937     6937           
=======================================
  Hits         6246     6246           
  Misses        691      691           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbarker dbarker marked this pull request as ready for review May 20, 2025 18:52
@dbarker dbarker requested a review from a team as a code owner May 20, 2025 18:52
Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

LGTM

@marcalff marcalff merged commit 165983a into open-telemetry:main May 20, 2025
67 checks passed
@ThomsonTan
Copy link
Contributor

Seems this is a breaking change if the user relies on the include_directories() behavior?

@dbarker dbarker deleted the fix_cmake_target_properties_cleanup branch May 21, 2025 17:12
@dbarker
Copy link
Contributor Author

dbarker commented May 21, 2025

Seems this is a breaking change if the user relies on the include_directories() behavior?

@ThomsonTan I don't expect any breaking changes to users. The scope of the include_directories call covers all targets defined in the same CMakeLists.txt file and the sub directories it adds. User code shouldn't be included in this scope.

@ThomsonTan
Copy link
Contributor

Seems this is a breaking change if the user relies on the include_directories() behavior?

@ThomsonTan I don't expect any breaking changes to users. The scope of the include_directories call covers all targets defined in the same CMakeLists.txt file and the sub directories it adds. User code shouldn't be included in this scope.

FYI, here is one case which relied on include_directories() to work, but needs to switch to target_link_libraries() now.

open-telemetry/opentelemetry-cpp-contrib#551

@dbarker
Copy link
Contributor Author

dbarker commented May 21, 2025

Seems this is a breaking change if the user relies on the include_directories() behavior?

@ThomsonTan I don't expect any breaking changes to users. The scope of the include_directories call covers all targets defined in the same CMakeLists.txt file and the sub directories it adds. User code shouldn't be included in this scope.

FYI, here is one case which relied on include_directories() to work, but needs to switch to target_link_libraries() now.

open-telemetry/opentelemetry-cpp-contrib#551

That is a good catch. One of the drawbacks with the global include_directories (and why it is good to move towards target_include_directories) is that it can hide issues like this since the global includes are not transitive with the targets. The fix you made in open-telemetry/opentelemetry-cpp-contrib#551 is a good one.

Another instance where issues were hidden is with the foo_* library examples. They had included the sdk headers but did not link to the sdk targets (and shouldn't have). If a user copied those examples and the cmake files to build in their project - they would have previously failed to find the sdk headers at compile time.

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