[cppwinrt] Guard `add_library` to avoid "another target with the same name already exists" CMake error (#49767)

Co-authored-by: Kai Pastor <dg0yt@darc.de>
This commit is contained in:
Nathan White 2026-04-30 17:14:38 -07:00 committed by GitHub
parent 4cf671c303
commit 8e6be0084f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 19 deletions

View File

@ -1,24 +1,15 @@
get_filename_component(_cppwinrt_root "${CMAKE_CURRENT_LIST_DIR}" PATH)
get_filename_component(_cppwinrt_root "${_cppwinrt_root}" PATH)
set(_cppwinrt_exe "${_cppwinrt_root}/@tool_path@")
if (EXISTS "${_cppwinrt_exe}")
add_library(Microsoft::CppWinRT INTERFACE IMPORTED)
set_target_properties(Microsoft::CppWinRT PROPERTIES
INTERFACE_COMPILE_FEATURES cxx_std_17
INTERFACE_INCLUDE_DIRECTORIES "${_cppwinrt_root}/include"
INTERFACE_LINK_LIBRARIES "${_cppwinrt_root}/lib/@lib_name@"
)
set(cppwinrt_FOUND TRUE)
set(CPPWINRT_TOOL ${_cppwinrt_exe})
else()
set(cppwinrt_FOUND FALSE)
if (NOT TARGET Microsoft::CppWinRT)
add_library(Microsoft::CppWinRT INTERFACE IMPORTED)
set_target_properties(Microsoft::CppWinRT PROPERTIES
INTERFACE_COMPILE_FEATURES cxx_std_17
INTERFACE_INCLUDE_DIRECTORIES "${_cppwinrt_root}/include"
INTERFACE_LINK_LIBRARIES "${_cppwinrt_root}/lib/@lib_name@"
)
endif()
set(CPPWINRT_TOOL "${_cppwinrt_root}/@tool_path@")
unset(_cppwinrt_root)
unset(_cppwinrt_exe)

View File

@ -1,6 +1,7 @@
{
"name": "cppwinrt",
"version": "2.0.250303.1",
"port-version": 1,
"description": "C++/WinRT is a standard C++ language projection for the Windows Runtime.",
"homepage": "https://github.com/microsoft/cppwinrt",
"documentation": "https://docs.microsoft.com/windows/uwp/cpp-and-winrt-apis/",

View File

@ -2134,7 +2134,7 @@
},
"cppwinrt": {
"baseline": "2.0.250303.1",
"port-version": 0
"port-version": 1
},
"cppxaml": {
"baseline": "0.0.16",

View File

@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "756cf03e3e64f2c511996cc06e6b08378e4e0c25",
"version": "2.0.250303.1",
"port-version": 1
},
{
"git-tree": "2b7e34cd0c66a4a4645fd872a27972448f69e134",
"version": "2.0.250303.1",