Skip to content

[INSTALL] Unify cmake install functions and dynamically set component dependencies #3368

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 Apr 18, 2025

Fixes #3293 as followup to #3220

Changes

  • Unifies the cmake install commands into functions
    • otel_add_component()
      • Create a component with targets and optional files for install
    • otel_install_components()
      • Install all components created
    • otel_install_cmake_config()
      • Installs the opentelemetry-cpp-config.cmake` and version files.
    • otel_install_thirdparty_definitions()
      • Installs the third-party definitions file (cmake search modes and built-with versions)
  • Removes the static component definitions and mappings
    • component to target, component to component, and component to thirdparty dependency mappings are now determined dynamically based on the CMake target properties LINK_LIBRARIES and INTERFACE_LINK_LIBRARIES.
  • Adds opentelemetry-cpp:: alias targets to support install and unify the public cmake interface to opentelemetry-cpp
    • The same opentelemetry-cpp::<target> names imported with find_package can now be used when opentelmetry-cpp is built directly as a submodule (add_subdirectory) in a larger project.
    • Adds a test in ci to verify the alias targets are created for the api and sdk components when using CMake's FetchContent module.
    • Updates the INSTALL documentation to add notes on FetchContent usage

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 Apr 18, 2025

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

Name Link
🔨 Latest commit 94dff15
🔍 Latest deploy log https://app.netlify.com/sites/opentelemetry-cpp-api-docs/deploys/681e4e993bd80e0008b472e7

Copy link

codecov bot commented Apr 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.05%. Comparing base (1e33bb5) to head (94dff15).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3368   +/-   ##
=======================================
  Coverage   90.05%   90.05%           
=======================================
  Files         212      212           
  Lines        6932     6932           
=======================================
  Hits         6242     6242           
  Misses        690      690           
🚀 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 April 19, 2025 00:09
@dbarker dbarker requested a review from a team as a code owner April 19, 2025 00:09
@dbarker
Copy link
Contributor Author

dbarker commented Apr 27, 2025

Hi @owent, This PR is based on your requests for followup to #3220. Can you take a look and give some feedback?

@owent
Copy link
Member

owent commented Apr 29, 2025

Hi @owent, This PR is based on your requests for followup to #3220. Can you take a look and give some feedback?

Sorry for the delay. I will review it some time later.

Copy link
Member

@owent owent left a comment

Choose a reason for hiding this comment

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

Great job. I have a few questions after a quick look.
It's a big PR and I will test it locally later.

endforeach()

configure_file(
"${CMAKE_SOURCE_DIR}/cmake/templates/thirdparty-dependency-definitions.cmake.in"
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's better to use the simular path as below? ("${CMAKE_CURRENT_LIST_DIR}/templates/thirdparty-dependency-definitions.cmake.in")

Copy link
Contributor Author

@dbarker dbarker Apr 29, 2025

Choose a reason for hiding this comment

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

Good catch. Your change is right. It should use CMAKE_CURRENT_LIST_DIR to ensure the project builds/installs correctly if used as a submodule.

Copy link
Contributor Author

@dbarker dbarker Apr 29, 2025

Choose a reason for hiding this comment

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

I've pushed a commit to use PROJECT_SOURCE_DIR here and where we set/get properties used for install. That should work better when this project is used as a submodule/subdirectory in a larger project.

…d package. Use PROJECT_SOURCE_DIR for storing properties and configuring files
@owent
Copy link
Member

owent commented May 1, 2025

I'm on holiday these days.Can I continue to review several day's later

@dbarker
Copy link
Contributor Author

dbarker commented May 7, 2025

@owent - for when you get back from holiday :)

I've added a new test using CMake's FetchContent module and updated INSTALL documentation to include this as a supported approach to incorporate opentelemetry-cpp as a sub-module/sub-directory in an external CMake project.

…. Clean up cmake script debug and error messages
# COMPONENT to TARGET lists
# ----------------------------------------------------------------------

@OTEL_COMPONENTS_TARGETS_BLOCK@
Copy link
Member

Choose a reason for hiding this comment

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

Can we also generate the target list comments in cmake/templates/opentelemetry-cpp-config.cmake.in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. That is a good idea. What do you think about just removing the current comments listing targets and components then adding a comment pointing to the component-definitions.cmake file installed? That file contains all the information - just not in an .rst format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a follow up issue. #3398

Copy link
Member

@owent owent left a comment

Choose a reason for hiding this comment

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

Excellent job. I have already tested in my project. It works well.

@marcalff
Copy link
Member

Excellent job. I have already tested in my project. It works well.

This says it all. Ok to merge.

@owent
Copy link
Member

owent commented May 13, 2025

Excellent job. I have already tested in my project. It works well.

This says it all. Ok to merge.

Yes, LGTM. I think we can continue to work on generating document comments in another PR.

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, thanks for the fix.

@marcalff marcalff merged commit 546fcd7 into open-telemetry:main May 14, 2025
67 checks passed
@dbarker dbarker deleted the feature_unify_component_install_commands branch May 15, 2025 03:35
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.

Unify cmake install functions and use cmake properties to define dependencies
5 participants