Skip to content
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

[cppwinrt] port rewrite to use cppwint.exe tool from NuGet Gallery #24967

Merged
merged 23 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ports/cppwinrt/cppwinrt-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
set(CppWinRT_FOUND TRUE)

if(NOT TARGET Microsoft::CppWinRT)
get_filename_component(cppwinrt_root "${CMAKE_CURRENT_LIST_DIR}" PATH)
get_filename_component(cppwinrt_root "${cppwinrt_root}" PATH)

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/cppwinrt_fast_forwarder.lib"
)
unset(cppwinrt_root)
endif()
72 changes: 66 additions & 6 deletions ports/cppwinrt/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,70 @@
find_path(CPPWINRT_BASE_H
NAMES winrt/base.h
PATHS $ENV{INCLUDE}
set(CPPWINRT_VERSION 2.0.220418.1)
walbourn marked this conversation as resolved.
Show resolved Hide resolved

vcpkg_download_distfile(ARCHIVE
URLS "https://www.nuget.org/api/v2/package/Microsoft.Windows.CppWinRT/${CPPWINRT_VERSION}"
FILENAME "cppwinrt.${CPPWINRT_VERSION}.zip"
SHA512 67738587f7b1ca98a7c2c2c0733dd09612deb5ef6bcfa788ca0bcccbbfde2c706a675316085a41e79ab2c8796a0dd3bdba87d5c996dc0b6f76b438b5d75d2567
)

vcpkg_extract_source_archive_ex(
OUT_SOURCE_PATH src
ARCHIVE ${ARCHIVE}
NO_REMOVE_ONE_LEVEL
)

if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
set(CPPWINRT_ARCH win32)
else()
set(CPPWINRT_ARCH ${VCPKG_TARGET_ARCHITECTURE})
endif()

set(CPPWINRT_TOOL "${src}/bin/cppwinrt.exe")

#--- Find Windows SDK Version
if (NOT EXISTS "$ENV{WindowsSDKDir}/Lib/$ENV{WindowsSDKVersion}.")
message(FATAL_ERROR "ERROR: Cannot locate the Windows SDK. Please define %WindowsSDKDir% and %WindowsSDKVersion%.
(Expected file to exist: $ENV{WindowsSDKDir}/Lib/$ENV{WindowsSDKVersion})")
endif()
if (NOT EXISTS "$ENV{WindowsSDKDir}References/$ENV{WindowsSDKVersion}Windows.Foundation.FoundationContract")
message(FATAL_ERROR "ERROR: The Windows SDK is too old (needs 14393 or later, found $ENV{WindowsSDKVersion}).")
endif()

file(TO_CMAKE_PATH "$ENV{WindowsSDKDir}References/$ENV{WindowsSDKVersion}" winsdk)

file(GLOB winmds "${winsdk}/*/*/*.winmd")

#--- Create response file
set(args "")
foreach(winmd IN LISTS winmds)
string(APPEND args "-input \"${winmd}\"\n")
endforeach()

file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}")
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}")
vcpkg_execute_required_process(
COMMAND "${CPPWINRT_TOOL}"
"@${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}/cppwinrt.rsp"
-output "${CURRENT_PACKAGES_DIR}/include"
-verbose
WORKING_DIRECTORY "${CURRENT_PACKAGES_DIR}"
LOGNAME "cppwinrt-generate-${TARGET_TRIPLET}"
)

if(NOT CPPWINRT_BASE_H)
message(FATAL_ERROR "Unable to locate cppwinrt. Please install Windows SDK version 10.0.17134.0 or newer.")
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")
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")

SET(VCPKG_POLICY_EMPTY_PACKAGE enabled)
configure_file("${src}/LICENSE" "${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright" COPYONLY)
4 changes: 4 additions & 0 deletions ports/cppwinrt/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cppwinrt provides CMake targets:

find_package(cppwinrt CONFIG REQUIRED)
target_link_libraries(main PRIVATE Microsoft::CppWinRT)
6 changes: 4 additions & 2 deletions ports/cppwinrt/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "cppwinrt",
"version-string": "windows-sdk",
"version": "2.0.220418.1",
"description": "C++/WinRT is a standard C++ language projection for the Windows Runtime.",
"homepage": "https://github.com/Microsoft/cppwinrt",
"homepage": "https://github.com/microsoft/cppwinrt",
"documentation": "https://docs.microsoft.com/windows/uwp/cpp-and-winrt-apis/",
"license": "MIT",
"supports": "windows"
}
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@
"port-version": 2
},
"cppwinrt": {
"baseline": "windows-sdk",
"baseline": "2.0.220418.1",
"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": "d4e517abedddb8d20362bc9cbae6716ecf3a7f62",
"version": "2.0.220418.1",
"port-version": 0
},
{
"git-tree": "191643fbd9c127658cf1724216a3b393951bd68e",
"version-string": "windows-sdk",
Expand Down