From 8e6be0084fab1936e34dd4092d96855967e63ad1 Mon Sep 17 00:00:00 2001 From: Nathan White Date: Thu, 30 Apr 2026 17:14:38 -0700 Subject: [PATCH] [cppwinrt] Guard `add_library` to avoid "another target with the same name already exists" CMake error (#49767) Co-authored-by: Kai Pastor --- ports/cppwinrt/cppwinrt-config.cmake.in | 27 +++++++++---------------- ports/cppwinrt/vcpkg.json | 1 + versions/baseline.json | 2 +- versions/c-/cppwinrt.json | 5 +++++ 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/ports/cppwinrt/cppwinrt-config.cmake.in b/ports/cppwinrt/cppwinrt-config.cmake.in index bacfdb6e65..c6cb1ff549 100644 --- a/ports/cppwinrt/cppwinrt-config.cmake.in +++ b/ports/cppwinrt/cppwinrt-config.cmake.in @@ -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) diff --git a/ports/cppwinrt/vcpkg.json b/ports/cppwinrt/vcpkg.json index 764f6fca11..fb6019fdc4 100644 --- a/ports/cppwinrt/vcpkg.json +++ b/ports/cppwinrt/vcpkg.json @@ -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/", diff --git a/versions/baseline.json b/versions/baseline.json index 2e86a30ff0..1dd2fd25a5 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -2134,7 +2134,7 @@ }, "cppwinrt": { "baseline": "2.0.250303.1", - "port-version": 0 + "port-version": 1 }, "cppxaml": { "baseline": "0.0.16", diff --git a/versions/c-/cppwinrt.json b/versions/c-/cppwinrt.json index f6fbf2a929..2ef8057627 100644 --- a/versions/c-/cppwinrt.json +++ b/versions/c-/cppwinrt.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "756cf03e3e64f2c511996cc06e6b08378e4e0c25", + "version": "2.0.250303.1", + "port-version": 1 + }, { "git-tree": "2b7e34cd0c66a4a4645fd872a27972448f69e134", "version": "2.0.250303.1",