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

Use namespaces for exported targets. #278

Merged
merged 1 commit into from
Oct 3, 2023
Merged

Conversation

Hoikas
Copy link
Member

@Hoikas Hoikas commented Oct 3, 2023

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 to target_link_libraries(). If an imported library is not namespaced (eg HSPlasma), 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. An ALIAS has been added for the old exported target names to ensure backwards compatibility.

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 to `target_link_libraries()`. If an
imported library is *not* namespaced (eg `HSPlasma`), 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. An `ALIAS` has been added for the old exported target names to
ensure backwards compatibility.
@zrax zrax merged commit aa32355 into H-uru:master Oct 3, 2023
8 checks passed
@Hoikas Hoikas deleted the namespace_library branch June 23, 2024 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants