-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[cppwinrt] Guard add_library to avoid "another target with the same name already exists" CMake error
#49767
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
base: master
Are you sure you want to change the base?
Conversation
dg0yt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it is not your fault, apart from theCPPWINRT_TOOL item. I just comment what I see.
|
|
||
| set(_cppwinrt_exe "${_cppwinrt_root}/@tool_path@") | ||
| if (EXISTS "${_cppwinrt_exe}") | ||
| if (NOT TARGET Microsoft::CppWinRT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guarding add_library is right, but
| else() | ||
|
|
||
| set(cppwinrt_FOUND FALSE) | ||
| if (EXISTS "${_cppwinrt_exe}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is pointless. The executable is always installed by the port.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but I would like to leave the number of changes I'm making minimal
| ) | ||
|
|
||
| set(cppwinrt_FOUND TRUE) | ||
| set(CPPWINRT_TOOL ${_cppwinrt_exe}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It must always set CPPWINRT_TOOL in the local scope, regardless of the library target.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate why please?
| INTERFACE_LINK_LIBRARIES "${_cppwinrt_root}/lib/@lib_name@" | ||
| ) | ||
|
|
||
| set(cppwinrt_FOUND TRUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is handled by CMake if the call is spelled find_package(cppwinrt ...).
|
|
||
| else() | ||
|
|
||
| set(cppwinrt_FOUND FALSE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't happen when lib and exe are installed.
Fixes #49720.
Guards the
add_librarycall so that consumers of the package can callfind_packagewithout needing to guard to avoid the CMake build: