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 18 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
131 changes: 131 additions & 0 deletions ports/cppwinrt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
cmake_minimum_required (VERSION 3.20)

if(NOT DEFINED CPPWINRT_VERSION)
message(FATAL_ERROR "Requires CPPWINRT_VERSION value")
endif()

project(CppWinRT
VERSION ${CPPWINRT_VERSION}
DESCRIPTION "C++/WinRT vcpkg support"
HOMEPAGE_URL "https://github.com/Microsoft/cppwinrt"
LANGUAGES CXX)

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

message(STATUS "Targeting ${CPPWINRT_ARCH}")

include(GNUInstallDirs)

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

set(CPPWINRT_LIB "${CMAKE_CURRENT_SOURCE_DIR}/build/native/lib/${CPPWINRT_ARCH}/cppwinrt_fast_forwarder.lib")

#--- Find Windows SDK Version
if(NOT DEFINED WindowsSDKDir)
if(EXISTS "$ENV{WindowsSDKDir}" AND (NOT "$ENV{WindowsSDKDir}" STREQUAL ""))
get_filename_component(WindowsSDKDir "$ENV{WindowsSDKDir}" ABSOLUTE)
else()
set(WindowsSDKDir "$ENV{ProgramFiles\(x86\)}/Windows Kits/10")
endif()
endif()

if (NOT (EXISTS "${WindowsSDKDir}"))
message(FATAL_ERROR "ERROR: Cannot locate the Windows SDK")
endif()

if (CMAKE_SYSTEM_VERSION MATCHES "^10\\.0\\.[0-9]+\\.0$")
set(WindowsSDKVersion ${CMAKE_SYSTEM_VERSION})
elseif(CMAKE_SYSTEM_VERSION MATCHES "^10\\.0\\.[0-9]+$")
set(WindowsSDKVersion "${CMAKE_SYSTEM_VERSION}.0")
endif()

if(NOT DEFINED WindowsSDKVersion)
if(NOT ("$ENV{WindowsSDKVersion}" STREQUAL ""))
set(WindowsSDKVersion $ENV{WindowsSDKVersion})
if (EXISTS "${WindowsSDKDir}/References/${WindowsSDKVersion}")
message(STATUS "Found Windows SDK and version from environment variables")
string(REPLACE "\\" "" WindowsSDKVersion ${WindowsSDKVersion})
else()
set(WindowsSDKVersion "")
endif()
endif()
endif()

set(WINDOWS_SDK_VERSIONS
10.0.22000.0 # Windows SDK for Windows 11
10.0.20348.0 # Windows SDK, version 2104
10.0.19041.0 # Windows 10 "20H1" SDK
10.0.18362.0 # Windows 10 May 2019 Update SDK
10.0.17763.0 # Windows 10 October 2018 Update SDK
10.0.17134.0 # Windows 10 April 2018 Update SDK
10.0.16299.0 # Windows 10 Fall Creators Update SDK
10.0.15063.0 # Windows 10 Creators Update SDK
10.0.14393.0 # Windows 10 Anniversary Update SDK
)

if (NOT (EXISTS "${WindowsSDKDir}/References/${WindowsSDKVersion}/Windows.Foundation.FoundationContract"))
set(WindowsSDKVersion "")
foreach(sdkver IN LISTS WINDOWS_SDK_VERSIONS)
if (EXISTS "${WindowsSDKDir}/References/${sdkver}/Windows.Foundation.FoundationContract")
cmake_path(CONVERT "${WindowsSDKDir}/References/${sdkver}" TO_CMAKE_PATH_LIST WinMDRoot NORMALIZE)
set(WindowsSDKVersion ${sdkver})
break()
endif()
endforeach()

if ("${WindowsSDKVersion}" STREQUAL "")
message(FATAL_ERROR "ERROR: Cannot locate the Windows SDK (14393) or later.")
endif()
endif()

message(STATUS "Using .winmd files from ${WindowsSDKVersion} in ${WindowsSDKDir}")

#--- Generate headers
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/winrt/base.h"
COMMENT "Generating C++/WinRT headers for SDK ${WindowsSDKVersion}"
COMMAND ${CPPWINRT_TOOL} -in ${WindowsSDKVersion} -out ${CMAKE_CURRENT_BINARY_DIR}
USES_TERMINAL)

add_library(${PROJECT_NAME} INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/winrt/base.h")

target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Inc>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/cppwinrt>)

#--- Package
include(CMakePackageConfigHelpers)

string(TOLOWER ${PROJECT_NAME} PACKAGE_NAME)

write_basic_package_version_file(
${PACKAGE_NAME}-config-version.cmake
VERSION ${CPPWINRT_VERSION}
COMPATIBILITY AnyNewerVersion)

install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME})

install(EXPORT ${PROJECT_NAME}-targets
FILE ${PROJECT_NAME}-targets.cmake
NAMESPACE Microsoft::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME})

install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/winrt
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME})

install(FILES ${CPPWINRT_LIB}
DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME})
23 changes: 23 additions & 0 deletions ports/cppwinrt/CppWinRT-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@PACKAGE_INIT@

include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake)
walbourn marked this conversation as resolved.
Show resolved Hide resolved

get_filename_component(_cppwinrt_root "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_cppwinrt_root "${_cppwinrt_root}" PATH)
get_filename_component(_cppwinrt_root "${_cppwinrt_root}" PATH)

set(_cppwinrt_root_lib "${_cppwinrt_root}/lib/cppwinrt_fast_forwarder.lib")
if (EXISTS "${_cppwinrt_root_lib}")

set_target_properties(Microsoft::CppWinRT PROPERTIES
walbourn marked this conversation as resolved.
Show resolved Hide resolved
INTERFACE_LINK_LIBRARIES "${_cppwinrt_root_lib}")

endif()

set_target_properties(Microsoft::CppWinRT PROPERTIES
INTERFACE_COMPILE_FEATURES cxx_std_17)

walbourn marked this conversation as resolved.
Show resolved Hide resolved
unset(_cppwinrt_root_lib)
unset(_cppwinrt_root)

check_required_components(cppwinrt)
41 changes: 34 additions & 7 deletions ports/cppwinrt/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
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 SOURCE_PATH
ARCHIVE ${ARCHIVE}
NO_REMOVE_ONE_LEVEL
)

file(COPY
"${CMAKE_CURRENT_LIST_DIR}/CppWinRT-config.cmake.in"
"${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt"
DESTINATION "${SOURCE_PATH}"
)

if(NOT CPPWINRT_BASE_H)
message(FATAL_ERROR "Unable to locate cppwinrt. Please install Windows SDK version 10.0.17134.0 or newer.")
endif()
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS -DCPPWINRT_VERSION=${CPPWINRT_VERSION}
)

vcpkg_cmake_install()
vcpkg_cmake_config_fixup()

file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/cppwinrt/")

file(INSTALL
"${SOURCE_PATH}/bin/cppwinrt.exe"
DESTINATION "${CURRENT_PACKAGES_DIR}/tools/cppwinrt")

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

SET(VCPKG_POLICY_EMPTY_PACKAGE enabled)
file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
18 changes: 15 additions & 3 deletions ports/cppwinrt/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
{
"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",
"supports": "windows"
"homepage": "https://github.com/microsoft/cppwinrt",
"documentation": "https://docs.microsoft.com/windows/uwp/cpp-and-winrt-apis/",
"license": "MIT",
"supports": "windows",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}
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": "0f76bed14360d1ab8ad5b476dfc87f1afae77b5a",
"version": "2.0.220418.1",
"port-version": 0
},
{
"git-tree": "191643fbd9c127658cf1724216a3b393951bd68e",
"version-string": "windows-sdk",
Expand Down