8000 Alias CMake Targets. Fixes #921 by jwillikers · Pull Request #926 · google/benchmark · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Alias CMake Targets. Fixes #921 #926

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
merged 6 commits into from
Jan 14, 2020
Merged

Alias CMake Targets. Fixes #921 #926

merged 6 commits into from
Jan 14, 2020

Conversation

jwillikers
Copy link
Contributor
@jwillikers jwillikers commented Jan 14, 2020

This adds two CMake alias targets benchmark::benchmark and benchmark::benchmark_main to facilitate more convenient / less error-prone linking within CMake. See issue #921

I updated targets to link to the aliased targets internally, so as to take advantaged of the added safety CMake provides when linking against namespaced targets.

Additionally, I added a section according to the suggestion from @keith-bennett-gbg describing how to use 'find_package' and 'add_subdirectory' to incorporate the CMake project.

Fixes #921

Provide aliased CMake targets for the benchmark and benchmark_main targets.
The alias targets are namespaced under benchmark::, which is the namespace when they are exported.
I chose not to use either the PROJECT_NAME or the namespace variable but to hard-code the namespace.
This is because the benchmark and benchmark_main targets are hard-coded by name themselves.
Hard-coding the namespace is also much cleaner and easier to read.
It is safer to link against namespaced targets because of how CMake interprets the double colon.
Typo's will be caught by CMake at configuration-time instead of during compile / link time.
This section covers linking against the alias/import CMake targets and including them using either find_package or add_subdirectory.
@coveralls
Copy link
coveralls commented Jan 14, 2020

Coverage Status

Coverage remained the same at 92.041% when pulling ef9aa75 on jwillikers:cmake-interface-targets into 5ce2429 on google:master.

@LebedevRI LebedevRI changed the title Alias CMake Targets Alias CMake Targets. Fixes #921 Jan 14, 2020
@LebedevRI LebedevRI self-assigned this Jan 14, 2020
@keith-bennett-gbg
Copy link

👍 builds on my machine
🎉 README addition

Copy link
Collaborator
@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

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

Marking as reviewed pending readme fixes

Added a newline after the "Usage with CMake" section header.
Dropped the header level of the section by one to make it a direct subsection of the "Usage" section.
Wrapped lines to be no longer than 80 characters in length.
Copy link
Collaborator
@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

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

Waiting for CI to cycle, looks good otherwise, thank you.

@jwillikers
Copy link
Contributor Author

Your welcome. Thanks for the review 😁

@LebedevRI LebedevRI merged commit daff5fe into google:master Jan 14, 2020
@jwillikers jwillikers deleted the cmake-interface-targets branch January 14, 2020 23:28
@LebedevRI LebedevRI removed their assignment Aug 18, 2020
JBakamovic pushed a commit to JBakamovic/benchmark that referenced this pull request Sep 11, 2020
* add Jordan Williams to both CONTRIBUTORS and AUTHORS

* alias benchmark libraries

Provide aliased CMake targets for the benchmark and benchmark_main targets.
The alias targets are namespaced under benchmark::, which is the namespace when they are exported.
I chose not to use either the PROJECT_NAME or the namespace variable but to hard-code the namespace.
This is because the benchmark and benchmark_main targets are hard-coded by name themselves.
Hard-coding the namespace is also much cleaner and easier to read.

* link to aliased benchmark targets

It is safer to link against namespaced targets because of how CMake interprets the double colon.
Typo's will be caught by CMake at configuration-time instead of during compile / link time.

* document the provided alias targets

* add "Usage with CMake" section in documentation

This section covers linking against the alias/import CMake targets and including them using either find_package or add_subdirectory.

* format the "Usage with CMake" README section

Added a newline after the "Usage with CMake" section header.
Dropped the header level of the section by one to make it a direct subsection of the "Usage" section.
Wrapped lines to be no longer than 80 characters in length.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide benchmark:: Aliased CMake Library
5 participants
0