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 an alias target for the root add_library #3

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

azeey
Copy link
Collaborator

@azeey azeey commented Apr 22, 2024

Without this patch, doing find_package(gz-utils) (or any vendor package) multiple times in a single CMakeLists file fails with an error indicating that cmake cannot create the imported target because another target with the same name already exists.

Test:

cmake_minimum_required(VERSION 3.10)
project(test_gz_vendor)

find_package(gz_utils_vendor REQUIRED)
find_package(gz-utils REQUIRED)
find_package(gz-utils REQUIRED)

Once approved, I'll apply the change to the template and regenerate all vendor packages.

Without this patch, doing `find_package(gz-utils)` (or any vendor
package) multiple times in a single CMakeLists file fails with an
error indicating that cmake cannot create the imported target
because another target with the same name already exists.

Signed-off-by: Addisu Z. Taddese <[email protected]>
@azeey azeey requested a review from mjcarroll April 22, 2024 22:09
Copy link
Contributor

@mjcarroll mjcarroll left a comment

Choose a reason for hiding this comment

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

To prevent future issues, we could also wrap the whole thing in the CMake if (NOT defined $FOO) set(FOO TRUE) endif() pattern, but this seems safe for now, provided we don't add more.

@azeey
Copy link
Collaborator Author

azeey commented Apr 23, 2024

To prevent future issues, we could also wrap the whole thing in the CMake if (NOT defined $FOO) set(FOO TRUE) endif() pattern, but this seems safe for now, provided we don't add more.

I didn't want to do it wholesale like that, if possible, because the requested components might be different between the two invocations of find_package. I thought about checking if each target existed before creating the alias, but that doesn't seem to be necessary for aliases.

@azeey azeey merged commit fe25d2e into rolling Apr 23, 2024
@azeey azeey deleted the use_alias_for_root_lib branch April 23, 2024 14:11
@azeey azeey mentioned this pull request Apr 24, 2024
9 tasks
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 this pull request may close these issues.

2 participants