Alias CMake Targets. Fixes #921#926
Merged
LebedevRI merged 6 commits intogoogle:masterfrom Jan 14, 2020
jwillikers:cmake-interface-targets
Merged
Alias CMake Targets. Fixes #921#926LebedevRI merged 6 commits intogoogle:masterfrom jwillikers:cmake-interface-targets
LebedevRI merged 6 commits intogoogle:masterfrom
jwillikers:cmake-interface-targets
Conversation
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.
LebedevRI
reviewed
Jan 14, 2020
|
👍 builds on my machine |
LebedevRI
requested changes
Jan 14, 2020
Collaborator
LebedevRI
left a comment
There was a problem hiding this comment.
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.
LebedevRI
approved these changes
Jan 14, 2020
Collaborator
LebedevRI
left a comment
There was a problem hiding this comment.
Waiting for CI to cycle, looks good otherwise, thank you.
Contributor
Author
|
Your welcome. Thanks for the review 😁 |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds two CMake alias targets
benchmark::benchmarkandbenchmark::benchmark_mainto facilitate more convenient / less error-prone linking within CMake. See issue #921I 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