Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ else()
add_library(reflectcpp STATIC)
endif()

add_library(reflectcpp::reflectcpp ALIAS reflectcpp)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This is a great addition for improving the consumer experience! However, adding this alias unconditionally could break builds for users who have already implemented the workaround described in the pull request description (i.e., they have their own add_library(reflectcpp::reflectcpp ALIAS reflectcpp)).

To make this change more robust and backward-compatible, it's a good practice to check if the target already exists before creating the alias.

if(NOT TARGET reflectcpp::reflectcpp)
    add_library(reflectcpp::reflectcpp ALIAS reflectcpp)
endif()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@gemini-code-assist Will not work if alias library is declared after add_subdirectory or FetchContentMakeAvailable. So even with that a breaking change.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You raise a valid point, BestITUserEUW. The if(NOT TARGET reflectcpp::reflectcpp) check primarily prevents redefinition errors if the target were to be defined within the reflectcpp project's own CMake processing or if a user's workaround was placed before the reflectcpp project's inclusion in their top-level CMakeLists.txt.

However, you are correct that if a user has an add_library(reflectcpp::reflectcpp ALIAS reflectcpp) workaround in their own CMakeLists.txt that is processed after reflectcpp's CMakeLists.txt (which now defines this alias), it will indeed lead to a redefinition error. This is an unavoidable consequence of the library now officially providing the reflectcpp::reflectcpp target.

The intent of this PR is to standardize the availability of reflectcpp::reflectcpp. When a library starts providing a target that was previously a common workaround, users who implemented that workaround will need to remove it from their build scripts. While this might require a minor adjustment for some existing users, it ultimately leads to a more consistent and robust build experience for everyone consuming reflectcpp.


if (MSVC)
target_compile_options(reflectcpp PRIVATE $<$<CONFIG:Debug>:-Wall>)
else()
Expand Down
Loading