Skip to content
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

Allow building as a header-only library with CMake #751

Closed
lidavidm opened this issue May 14, 2021 · 4 comments · Fixed by #778
Closed

Allow building as a header-only library with CMake #751

lidavidm opened this issue May 14, 2021 · 4 comments · Fixed by #778

Comments

@lidavidm
Copy link
Contributor

I'm working on integrating OpenTelemetry in a CMake-based project using ExternalProject. I want my project to be able to use OpenTelemetry as a header-only library, using just api/, or optionally directly linking to OpenTelemetry (libopentelemetry_trace etc). In the former case, I'd like to not build any of the static libraries to save build time, however, there's not a good way to do this.

Is your feature request related to a problem?
No

Describe the solution you'd like
Being able to disable the build of the ext/sdk/exporters subprojects would be ideal, e.g. -DWITH_SDK=OFF -DWITH_EXT=OFF -DWITH_EXPORTERS=OFF.

Describe alternatives you've considered
CMake kind of lets you do something like this:

  externalproject_add_step(opentelemetry_ep install-headers
                           COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --target api/install
                           LOG true)
  externalproject_add_steptargets(opentelemetry_ep install-headers configure)
  externalproject_add_stepdependencies(opentelemetry_ep install-headers
                                       opentelemetry_ep-configure)

However, that --target is specific to the Ninja CMake generator - if you're using Makefiles, it instead has to be --build <BINARY_DIR>/api --target install not --build <BINARY_DIR> --target api/install. Trying to embed all this logic is brittle and I'd rather have the option to configure the build itself. Is this reasonable?

Additional context
N/A

@lalitb
Copy link
Member

lalitb commented May 14, 2021

That would be a common scenario, and it would make sense to support building only the api project.

@lalitb
Copy link
Member

lalitb commented May 18, 2021

@lidavidm Solution suggested by you looks good - basically adding cmake options to enable/disable building projects selectively. Or just to add WITH_API_ONLY to enable building only API project ( as this would be required for building instrumentation libraries). Wanted to check if you have plans to contribute on this, else we can let someone pick this up :)

@lidavidm
Copy link
Contributor Author

@lalitb Sorry for the delay - I would like to but I'm still working with my org to make sure I can sign the CLA. I'm hoping that'll be in the next couple days, else someone else can of course take a look.

@lalitb
Copy link
Member

lalitb commented May 18, 2021

Thank you @lidavidm for your willingness to contribute. There is no immediate hurry, you can pick it up once CLA is signed :)

lidavidm added a commit to lidavidm/opentelemetry-cpp that referenced this issue May 20, 2021
This enables easily building/using OpenTelemetry as a header-only
library. When enabled, SDK/EXT/examples are not built.

Fixes open-telemetry#751
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 a pull request may close this issue.

2 participants