From 1aba77ae3b0f766eeea91888f4c4fa082e16d9ea Mon Sep 17 00:00:00 2001
From: Phoebe <20694052+PhoebeHui@users.noreply.github.com>
Date: Tue, 5 Jan 2021 12:42:29 -0800
Subject: [PATCH] [hidapi] Support static build (#15437)
* [hidapi] Support static build
* Update portfile.cmake
---
ports/hidapi/CONTROL | 4 ---
ports/hidapi/portfile.cmake | 50 ++++++++++++++++++++++++++-----------
ports/hidapi/vcpkg.json | 8 ++++++
3 files changed, 44 insertions(+), 18 deletions(-)
delete mode 100644 ports/hidapi/CONTROL
create mode 100644 ports/hidapi/vcpkg.json
diff --git a/ports/hidapi/CONTROL b/ports/hidapi/CONTROL
deleted file mode 100644
index 80f18b4935..0000000000
--- a/ports/hidapi/CONTROL
+++ /dev/null
@@ -1,4 +0,0 @@
-Source: hidapi
-Version: 2019-08-30
-Description: A Simple library for communicating with USB and Bluetooth HID devices on Linux, Mac and Windows.
-Homepage: https://github.com/libusb/hidapi
diff --git a/ports/hidapi/portfile.cmake b/ports/hidapi/portfile.cmake
index ec7abb495e..ea2cd092bf 100644
--- a/ports/hidapi/portfile.cmake
+++ b/ports/hidapi/portfile.cmake
@@ -1,3 +1,5 @@
+vcpkg_fail_port_install(ON_ARCH "arm" "arm64" ON_TARGET "linux" "osx" "uwp")
+
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO libusb/hidapi
@@ -7,26 +9,46 @@ vcpkg_from_github(
)
if(VCPKG_TARGET_IS_WINDOWS)
- if(TRIPLET_SYSTEM_ARCH MATCHES "arm")
- message(FATAL_ERROR "ARM builds are currently not supported!")
- elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL WindowsStore)
- message(FATAL_ERROR "UWP builds are currently not supported!")
+ file(READ "${SOURCE_PATH}/windows/hidapi.vcxproj" _contents)
+ if(${VCPKG_CRT_LINKAGE} STREQUAL "dynamic")
+ string(REGEX REPLACE
+ "MultiThreadedDebug"
+ "MultiThreadedDebugDLL"
+ _contents "${_contents}")
+ string(REGEX REPLACE
+ "MultiThreaded"
+ "MultiThreadedDLL"
+ _contents "${_contents}")
+ else()
+ string(REGEX REPLACE
+ "MultiThreadedDebugDLL"
+ "MultiThreadedDebug"
+ _contents "${_contents}")
+ string(REGEX REPLACE
+ "MultiThreadedDLL"
+ "MultiThreaded"
+ _contents "${_contents}")
endif()
+ if(${VCPKG_LIBRARY_LINKAGE} STREQUAL "dynamic")
+ string(REPLACE
+ "StaticLibrary"
+ "DynamicLibrary"
+ _contents "${_contents}")
+ else()
+ string(REPLACE
+ "DynamicLibrary"
+ "StaticLibrary"
+ _contents "${_contents}")
+ endif()
+ file(WRITE "${SOURCE_PATH}/windows/hidapi.vcxproj" "${_contents}")
+
vcpkg_install_msbuild(
SOURCE_PATH ${SOURCE_PATH}
- PROJECT_SUBPATH windows/hidapi.sln
+ PROJECT_SUBPATH windows/hidapi.vcxproj
INCLUDES_SUBPATH hidapi ALLOW_ROOT_INCLUDES
LICENSE_SUBPATH LICENSE-bsd.txt # use BSD license
)
- file(COPY
- ${CMAKE_CURRENT_LIST_DIR}/hidapi-config.cmake
- DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})
-
- if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
- file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin)
- endif()
-else()
- message(FATAL_ERROR "Non-Windows builds are currently not supported!")
+ file(COPY ${CMAKE_CURRENT_LIST_DIR}/hidapi-config.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})
endif()
diff --git a/ports/hidapi/vcpkg.json b/ports/hidapi/vcpkg.json
new file mode 100644
index 0000000000..f73f97f2ea
--- /dev/null
+++ b/ports/hidapi/vcpkg.json
@@ -0,0 +1,8 @@
+{
+ "name": "hidapi",
+ "version-string": "2019-08-30",
+ "port-version": 1,
+ "description": "A Simple library for communicating with USB and Bluetooth HID devices on Linux, Mac and Windows.",
+ "homepage": "https://github.com/libusb/hidapi",
+ "supports": "windows & !(arm | arm64 | uwp)"
+}