Use namespaces for exported targets. #278
Merged
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.
There is a major GOTCHA for exported targets. If an imported library is namespaced (eg
HSPlasma::HSPlasma
), CMake will ensure that the library exists when it is used in a call totarget_link_libraries()
. If an imported library is not namespaced (egHSPlasma
), then, if the target doesn't exist, CMake will simply pass that library name to the linker and hope for the best. This can lead to confusing errors where, when a non-namespaced imported target is used, configuration can "succeed" but HSPlasma is not actually found correctly. The error doesn't actually emerge until the downstream project attempts to link against the nonexistent HSPlasma.This change allows downstream users to link against
HSPlasma::HSPlasma
and get a free configure-time check that libHSPlasma has been properly found. AnALIAS
has been added for the old exported target names to ensure backwards compatibility.