Skip to content

Avoid Creating Alias Target If It Already Exists #41

@threeal

Description

@threeal

This issue addresses the lines of code that create an alias target for a specific namespace:

# we want to automatically add :: to our namespace, so only append if a namespace was given in the
# first place we also provide an alias to ensure that local and installed versions have the same
# name
if(DEFINED PROJECT_NAMESPACE)
if(PROJECT_CPACK)
set(CPACK_PACKAGE_NAMESPACE ${PROJECT_NAMESPACE})
endif()
set(PROJECT_NAMESPACE ${PROJECT_NAMESPACE}::)
add_library(${PROJECT_NAMESPACE}${PROJECT_NAME} ALIAS ${PROJECT_NAME})
endif()

It is suggested to create the alias target only if the alias does not already exist; otherwise, it may cause issues as highlighted in boost-ext/ut#564.

Before CMake 3.18, this may not have caused an issue because any new alias target would replace the old alias. However, the behavior has changed since then (see also).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions