From 3bf6fd4baa153386bdb68a8f41fb8815a8689e5c Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Tue, 29 Oct 2024 02:08:35 -0700 Subject: [PATCH] [gameinput] Add port to use Microsoft.GameInput from nuget.org (#41762) Co-authored-by: WangWeiLin-MV <156736127+WangWeiLin-MV@users.noreply.github.com> --- ports/gameinput/gameinput-config.cmake.in | 12 ++++ ports/gameinput/portfile.cmake | 69 +++++++++++++++++++++++ ports/gameinput/usage | 6 ++ ports/gameinput/vcpkg.json | 8 +++ versions/baseline.json | 4 ++ versions/g-/gameinput.json | 9 +++ 6 files changed, 108 insertions(+) create mode 100644 ports/gameinput/gameinput-config.cmake.in create mode 100644 ports/gameinput/portfile.cmake create mode 100644 ports/gameinput/usage create mode 100644 ports/gameinput/vcpkg.json create mode 100644 versions/g-/gameinput.json diff --git a/ports/gameinput/gameinput-config.cmake.in b/ports/gameinput/gameinput-config.cmake.in new file mode 100644 index 0000000000..96a0a9cd13 --- /dev/null +++ b/ports/gameinput/gameinput-config.cmake.in @@ -0,0 +1,12 @@ +get_filename_component(_gameinput_root "${CMAKE_CURRENT_LIST_DIR}" PATH) +get_filename_component(_gameinput_root "${_gameinput_root}" PATH) + +set(_gameinput_root_lib "${_gameinput_root}/lib/gameinput.lib") + +add_library(Microsoft::GameInput INTERFACE IMPORTED) +set_target_properties(Microsoft::GameInput PROPERTIES + INTERFACE_LINK_LIBRARIES "${_gameinput_root_lib}" + INTERFACE_INCLUDE_DIRECTORIES "${_gameinput_root}/include") + +unset(_gameinput_root_lib) +unset(_gameinput_root) diff --git a/ports/gameinput/portfile.cmake b/ports/gameinput/portfile.cmake new file mode 100644 index 0000000000..2d69ead384 --- /dev/null +++ b/ports/gameinput/portfile.cmake @@ -0,0 +1,69 @@ +if(VCPKG_TARGET_IS_XBOX) + + cmake_path(SET GRDKLatest "$ENV{GRDKLatest}") + cmake_path(SET GXDKLatest "$ENV{GXDKLatest}") + + find_file(GAMEINPUT_H + NAMES GameInput.h + PATHS "${GRDKLatest}/gameKit/Include" + "${GXDKLatest}/gameKit/Include" + NO_DEFAULT_PATH + ) + + find_library(GAMEINPUT_LIB + NAMES GameInput.lib + PATHS "${GRDKLatest}/gameKit/Lib/amd64" + "${GXDKLatest}/gameKit/Lib/amd64" + NO_DEFAULT_PATH + ) + + if(NOT (GAMEINPUT_H AND GAMEINPUT_LIB)) + message(FATAL_ERROR "Ensure you have installed the Microsoft GDK with Xbox Extensions installed. See https://aka.ms/gdkx.") + endif() + + # Output user-friendly status message for installed edition. + if(${GXDKLatest} MATCHES ".*/([0-9][0-9])([0-9][0-9])([0-9][0-9])/.*") + set(_months "null" "January" "February" "March" "April" "May" "June" "July" "August" "September" "October" "November" "December") + list(GET _months ${CMAKE_MATCH_2} month) + set(update "") + if(${CMAKE_MATCH_3} GREATER 0) + set(update " Update ${CMAKE_MATCH_3}") + endif() + message(STATUS "Found the Microsoft GDK with Xbox Extensions (${month} 20${CMAKE_MATCH_1}${update})") + endif() + + file(INSTALL ${GAMEINPUT_H} DESTINATION "${CURRENT_PACKAGES_DIR}/include") + file(INSTALL ${GAMEINPUT_LIB} DESTINATION "${CURRENT_PACKAGES_DIR}/lib") + file(INSTALL ${GAMEINPUT_LIB} DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib") + + set(VCPKG_POLICY_SKIP_COPYRIGHT_CHECK enabled) + +else() + + vcpkg_download_distfile(ARCHIVE + URLS "https://www.nuget.org/api/v2/package/Microsoft.GameInput/${VERSION}" + FILENAME "gameinput.${VERSION}.zip" + SHA512 4ad0e8a2ff14e498632557c64cdcd967c6b166b405b2c60427578a5f8b32b925184a1c74bce95a7a73a129e61edddbec030c4abe4ada287a2ce9ae50178cdcea + ) + + vcpkg_extract_source_archive( + PACKAGE_PATH + ARCHIVE ${ARCHIVE} + NO_REMOVE_ONE_LEVEL + ) + + file(INSTALL "${PACKAGE_PATH}/native/include/gameinput.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include") + file(INSTALL "${PACKAGE_PATH}/native/lib/${VCPKG_TARGET_ARCHITECTURE}/gameinput.lib" DESTINATION "${CURRENT_PACKAGES_DIR}/lib") + file(INSTALL "${PACKAGE_PATH}/native/lib/${VCPKG_TARGET_ARCHITECTURE}/gameinput.lib" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib") + + file(INSTALL "${PACKAGE_PATH}/redist/GameInputRedist.msi" DESTINATION "${CURRENT_PACKAGES_DIR}/tools") + + vcpkg_install_copyright(FILE_LIST "${PACKAGE_PATH}/LICENSE.txt") + +endif() + +configure_file("${CMAKE_CURRENT_LIST_DIR}/gameinput-config.cmake.in" + "${CURRENT_PACKAGES_DIR}/share/${PORT}/${PORT}-config.cmake" + COPYONLY) + +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") diff --git a/ports/gameinput/usage b/ports/gameinput/usage new file mode 100644 index 0000000000..0ce34f4b4b --- /dev/null +++ b/ports/gameinput/usage @@ -0,0 +1,6 @@ +The GameInput package provides CMake targets: + + find_package(gameinput CONFIG REQUIRED) + target_link_libraries(main PRIVATE Microsoft::GameInput) + +Note that the GameInputRedist.msi must be installed on the target system for Windows. diff --git a/ports/gameinput/vcpkg.json b/ports/gameinput/vcpkg.json new file mode 100644 index 0000000000..c062127a37 --- /dev/null +++ b/ports/gameinput/vcpkg.json @@ -0,0 +1,8 @@ +{ + "name": "gameinput", + "version": "0.2303.22621.3038", + "description": "GameInput", + "homepage": "https://aka.ms/gameinput", + "license": null, + "supports": "windows & x64 & !uwp" +} diff --git a/versions/baseline.json b/versions/baseline.json index b1a3340d68..f3a50b8628 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -2984,6 +2984,10 @@ "baseline": "1.2.0", "port-version": 0 }, + "gameinput": { + "baseline": "0.2303.22621.3038", + "port-version": 0 + }, "gamenetworkingsockets": { "baseline": "1.4.1", "port-version": 1 diff --git a/versions/g-/gameinput.json b/versions/g-/gameinput.json new file mode 100644 index 0000000000..17bf6d38c5 --- /dev/null +++ b/versions/g-/gameinput.json @@ -0,0 +1,9 @@ +{ + "versions": [ + { + "git-tree": "b71fb62174fb92b8fe4fa6a87311d202349bee72", + "version": "0.2303.22621.3038", + "port-version": 0 + } + ] +}