Skip to content

Commit

Permalink
Support finding CppWinRT through vcpkg (#1073)
Browse files Browse the repository at this point in the history
vcpkg provides a packaged version of CppWinRT with its own CMake target,
so if that's available then we can use it directly rather than trying to
install it from NuGet.

This resolves issues building for UWP within vcpkg, because vcpkg uses
Ninja internally and that doesn't pick up the props definition from the
NuGet package.
  • Loading branch information
dpogue authored Nov 26, 2024
1 parent e015f62 commit 01f9c23
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1431,21 +1431,26 @@ else()
${MATH_LIB})

if(ALSOFT_UWP)
set(ALSOFT_CPPWINRT_VERSION "2.0.230706.1" CACHE STRING "The soft-oal default cppwinrt version")

find_program(NUGET_EXE NAMES nuget)
if(NOT NUGET_EXE)
message("NUGET.EXE not found.")
message(FATAL_ERROR "Please install this executable, and run CMake again.")
endif()
find_package(cppwinrt CONFIG)
if (TARGET Microsoft::CppWinRT)
target_link_libraries(${IMPL_TARGET} PRIVATE Microsoft::CppWinRT)
else()
set(ALSOFT_CPPWINRT_VERSION "2.0.230706.1" CACHE STRING "The soft-oal default cppwinrt version")

exec_program(${NUGET_EXE}
ARGS install "Microsoft.Windows.CppWinRT" -Version ${ALSOFT_CPPWINRT_VERSION} -ExcludeVersion -OutputDirectory "\"${CMAKE_BINARY_DIR}/packages\"")
find_program(NUGET_EXE NAMES nuget)
if(NOT NUGET_EXE)
message("NUGET.EXE not found.")
message(FATAL_ERROR "Please install this executable, and run CMake again.")
endif()

set_target_properties(${IMPL_TARGET} PROPERTIES
VS_PROJECT_IMPORT ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT/build/native/Microsoft.Windows.CppWinRT.props
)
target_link_libraries(${IMPL_TARGET} PRIVATE ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT/build/native/Microsoft.Windows.CppWinRT.targets)
exec_program(${NUGET_EXE}
ARGS install "Microsoft.Windows.CppWinRT" -Version ${ALSOFT_CPPWINRT_VERSION} -ExcludeVersion -OutputDirectory "\"${CMAKE_BINARY_DIR}/packages\"")

set_target_properties(${IMPL_TARGET} PROPERTIES
VS_PROJECT_IMPORT ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT/build/native/Microsoft.Windows.CppWinRT.props
)
target_link_libraries(${IMPL_TARGET} PRIVATE ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT/build/native/Microsoft.Windows.CppWinRT.targets)
endif()
endif()

if(NOT WIN32 AND NOT APPLE)
Expand Down

0 comments on commit 01f9c23

Please sign in to comment.