Skip to content

Commit

Permalink
[cppwinrt] Update port for January 2024 release (#37452)
Browse files Browse the repository at this point in the history
This updates the cppwinrt port to use the latest
Microsoft.Windows.CppWinRT package from NuGet. Includes clean up of the
portfile for modern best practices.

This also cleans up the cmake integration:

* Uses `cppwinrt_FOUND` instead of the nonstandard `CppWinRT_FOUND`
* Provides `CPPWINRT_TOOL` for being able to generate C++/WinRT headers
from .winmd files as custom commands
  • Loading branch information
walbourn committed Mar 14, 2024
1 parent 4aa53df commit 3a7cb34
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 30 deletions.
14 changes: 0 additions & 14 deletions ports/cppwinrt/cppwinrt-config.cmake

This file was deleted.

24 changes: 24 additions & 0 deletions ports/cppwinrt/cppwinrt-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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)

endif()

unset(_cppwinrt_root)
unset(_cppwinrt_exe)
29 changes: 16 additions & 13 deletions ports/cppwinrt/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
vcpkg_download_distfile(ARCHIVE
URLS "https://www.nuget.org/api/v2/package/Microsoft.Windows.CppWinRT/${VERSION}"
FILENAME "cppwinrt.${VERSION}.zip"
SHA512 6ce0764c3558d94b0ec72daa6d6d139df3942d33f51d1f3a670b888fbba2b556e35df831fa9eea42d4fc9a0a1f0ca94abef1c4013dcc9b51053bffe2af4dfd85
SHA512 c6c38b81640d7d96d3ca76c321289d6f92eec9bb593a11824640c7dc3651dc69cce1e85ca0324396b4a4d55f790f2c16f835da261e7821137de1eb491b52ffc8
)

vcpkg_extract_source_archive(
Expand Down Expand Up @@ -43,7 +43,8 @@ file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}")
file(WRITE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/cppwinrt.rsp" "${args}")

#--- Generate headers
message(STATUS "Generating headers for Windows SDK $ENV{WindowsSDKVersion}")
string(REGEX MATCH "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" SDKVersion $ENV{WindowsSDKVersion})
message(STATUS "Generating headers for Windows SDK ${SDKVersion}")
vcpkg_execute_required_process(
COMMAND "${CPPWINRT_TOOL}"
"@${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/cppwinrt.rsp"
Expand All @@ -54,16 +55,18 @@ vcpkg_execute_required_process(
)

set(CPPWINRT_LIB "${src}/build/native/lib/${CPPWINRT_ARCH}/cppwinrt_fast_forwarder.lib")
file(COPY "${CPPWINRT_LIB}" DESTINATION "${CURRENT_PACKAGES_DIR}/lib")
if(NOT VCPKG_BUILD_TYPE)
file(COPY "${CPPWINRT_LIB}" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib")
file(INSTALL "${CPPWINRT_LIB}" DESTINATION "${CURRENT_PACKAGES_DIR}/lib")
if(NOT DEFINED VCPKG_BUILD_TYPE)
file(INSTALL "${CPPWINRT_LIB}" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib")
endif()
file(COPY
"${CPPWINRT_TOOL}"
DESTINATION "${CURRENT_PACKAGES_DIR}/tools/cppwinrt")
file(COPY
"${CMAKE_CURRENT_LIST_DIR}/cppwinrt-config.cmake"
"${CMAKE_CURRENT_LIST_DIR}/usage"
DESTINATION "${CURRENT_PACKAGES_DIR}/share/cppwinrt")
file(INSTALL "${CPPWINRT_TOOL}" DESTINATION "${CURRENT_PACKAGES_DIR}/tools/cppwinrt")

configure_file("${src}/LICENSE" "${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright" COPYONLY)
set(tool_path "tools/cppwinrt/cppwinrt.exe")
set(lib_name "cppwinrt_fast_forwarder.lib")

configure_file("${CMAKE_CURRENT_LIST_DIR}/cppwinrt-config.cmake.in"
"${CURRENT_PACKAGES_DIR}/share/${PORT}/${PORT}-config.cmake"
@ONLY)

file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_install_copyright(FILE_LIST "${src}/LICENSE")
4 changes: 3 additions & 1 deletion ports/cppwinrt/usage
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
cppwinrt provides CMake targets:
The C++/WinRT package provides CMake targets:

find_package(cppwinrt CONFIG REQUIRED)
target_link_libraries(main PRIVATE Microsoft::CppWinRT)

The CMake variable CPPWINRT_TOOL is also set to point to the .winmd to header command-line tool.
2 changes: 1 addition & 1 deletion ports/cppwinrt/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cppwinrt",
"version": "2.0.230207.1",
"version": "2.0.240111.5",
"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/",
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@
"port-version": 3
},
"cppwinrt": {
"baseline": "2.0.230207.1",
"baseline": "2.0.240111.5",
"port-version": 0
},
"cppxaml": {
Expand Down
5 changes: 5 additions & 0 deletions versions/c-/cppwinrt.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "a2cf04c5162520cb5b3784e0cf09da9416929ab4",
"version": "2.0.240111.5",
"port-version": 0
},
{
"git-tree": "a3c57356ebb8b59a5f12468f180728751d16581b",
"version": "2.0.230207.1",
Expand Down

0 comments on commit 3a7cb34

Please sign in to comment.