Comments (7)
getopt for msvc from libusb project for your reference.
https://github.com/libusb/libusb/tree/master/msvc
from hidpp.
I don't consider windows builds to be simple. I've only built this using msys2, it is very similar to the linux way of building things.
- The cmake script use pkg-config to find tinyxml. I have never used pkg-config on windows outside of msys2. Cmake will first need to find pkg-config (CMAKE_PREFIX_PATH cmake option may help cmake find it). Then pkg-config will need to find the tinyxml2.pc file from you tinyxml2 installation (on Linux, I use the PKG_CONFIG_PATH envvar if it is in a non-standard path, I am not sure about windows).
- Cmake can use different generators. For example if you used a visual studio generator, it will create a sln file that you can build with msbuild or open in your IDE. By the way, I did not try to build with MSVC and I may have used GNU extensions, so it may not work.
Since this project only have command line tools, I would recommend to use msys2 anyway. Install tinyxml2 using pacman and cmake should work without any extra parameter.
Also, this was developed with Linux in mind. The windows port came later, as a a kind of challenge and to decide if I would abandon any attempt at portability and make it depend more on Linux. It is far from perfect and there is a known issue with unifying receivers (but it works fine with my corded mice). And, as you have seen it, the cmake script is not really designed for Windows.
Be careful, this is not newbie friendly, it won't prevent you from doing stupid thing like disabling all your mouse buttons. It should not brick any device and Logitech software will be able to restore a sane configuration in the worst case, but it can be difficult to do so with malfunctioning input devices.
from hidpp.
No issues to build under MSYS2.
350 mkdir build
351 cd build
352 cmake .. -G "MinGW Makefiles"
353 mingw32-make
from hidpp.
It's actually possible to build hidpp natively with Visual Studio and presumably also with Visual Studio Code.
The patch below happens to be against the current report-descriptor
branch (2ec1282) but it shows the idea.
The main problem are the tools which not only have a dependency on getopt (all of them) but also use Linux file I/O instead of standard C (some of them). The patch at least allows building hidpp-list-devices
(without command line parsing) as a proof-of-concept. Once we're done with #12 I'll whip up a proper PR with this.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index df4a0ad..abcb6f2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,14 +14,10 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
else()
message(WARNING "System is not supported")
endif()
+
set(HID_BACKEND "${DEFAULT_HID_BACKEND}" CACHE STRING "Backend used for accessing HID devices")
set_property(CACHE HID_BACKEND PROPERTY STRINGS linux windows)
-
-find_package(Threads REQUIRED)
-find_package(PkgConfig REQUIRED)
-pkg_check_modules(TINYXML2 tinyxml2)
if("${HID_BACKEND}" STREQUAL "linux")
- pkg_check_modules(LIBUDEV libudev REQUIRED)
elseif("${HID_BACKEND}" STREQUAL "windows")
add_definitions(-DUNICODE -D_UNICODE)
add_definitions(-D_WIN32_WINNT=0x0600) # Use vista or later
@@ -29,6 +25,23 @@ else()
message(FATAL_ERROR "HID_BACKEND is invalid.")
endif()
+# Universal dependencies
+find_package(Threads REQUIRED)
+
+# Dependencies that we look for either using pkg-config or CMake's native method
+find_package(PkgConfig)
+if(PKGCONFIG_FOUND)
+ pkg_check_modules(TINYXML2 tinyxml2)
+ if("${HID_BACKEND}" STREQUAL "linux")
+ pkg_check_modules(LIBUDEV libudev REQUIRED)
+ endif()
+else()
+ find_package(tinyxml2)
+ if("${HID_BACKEND}" STREQUAL "linux")
+ find_package(LIBUDEV REQUIRED)
+ endif()
+endif()
+
add_subdirectory(src/libhidpp)
add_subdirectory(src/tools)
add_subdirectory(doc/libhidpp)
diff --git a/CMakeSettings.json b/CMakeSettings.json
new file mode 100644
index 0000000..dff902e
--- /dev/null
+++ b/CMakeSettings.json
@@ -0,0 +1,49 @@
+{
+ "configurations": [
+ {
+ "name": "x64-Debug",
+ "generator": "Ninja",
+ "configurationType": "Debug",
+ "inheritEnvironments": [ "msvc_x64_x64" ],
+ "buildRoot": "${projectDir}\\out\\build\\${name}",
+ "installRoot": "${projectDir}\\out\\install\\${name}",
+ "cmakeCommandArgs": "",
+ "buildCommandArgs": "",
+ "ctestCommandArgs": ""
+ },
+ {
+ "name": "x64-Release",
+ "generator": "Ninja",
+ "configurationType": "RelWithDebInfo",
+ "buildRoot": "${projectDir}\\out\\build\\${name}",
+ "installRoot": "${projectDir}\\out\\install\\${name}",
+ "cmakeCommandArgs": "",
+ "buildCommandArgs": "",
+ "ctestCommandArgs": "",
+ "inheritEnvironments": [ "msvc_x64_x64" ]
+ },
+ {
+ "name": "x86-Debug",
+ "generator": "Ninja",
+ "configurationType": "Debug",
+ "buildRoot": "${projectDir}\\out\\build\\${name}",
+ "installRoot": "${projectDir}\\out\\install\\${name}",
+ "cmakeCommandArgs": "",
+ "buildCommandArgs": "",
+ "ctestCommandArgs": "",
+ "inheritEnvironments": [ "msvc_x86" ]
+ },
+ {
+ "name": "x86-Release",
+ "generator": "Ninja",
+ "configurationType": "RelWithDebInfo",
+ "buildRoot": "${projectDir}\\out\\build\\${name}",
+ "installRoot": "${projectDir}\\out\\install\\${name}",
+ "cmakeCommandArgs": "",
+ "buildCommandArgs": "",
+ "ctestCommandArgs": "",
+ "inheritEnvironments": [ "msvc_x86" ],
+ "variables": []
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/libhidpp/CMakeLists.txt b/src/libhidpp/CMakeLists.txt
index 3b82504..b7498a5 100644
--- a/src/libhidpp/CMakeLists.txt
+++ b/src/libhidpp/CMakeLists.txt
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 2.8)
project(libhidpp)
+option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
+
set(LIBHIDPP_SOURCES
misc/Log.cpp
misc/CRC.cpp
@@ -67,7 +69,7 @@ if("${HID_BACKEND}" STREQUAL "windows")
endif()
include_directories(.)
-add_library(hidpp SHARED ${LIBHIDPP_SOURCES})
+add_library(hidpp ${LIBHIDPP_SOURCES})
if("${HID_BACKEND}" STREQUAL "linux")
target_include_directories(hidpp PUBLIC ${LIBUDEV_INCLUDE_DIRECTORIES})
target_link_libraries(hidpp ${LIBUDEV_LIBRARIES})
diff --git a/src/libhidpp/hid/windows/DeviceData.cpp b/src/libhidpp/hid/windows/DeviceData.cpp
index 19c4f5c..25d728b 100644
--- a/src/libhidpp/hid/windows/DeviceData.cpp
+++ b/src/libhidpp/hid/windows/DeviceData.cpp
@@ -16,6 +16,8 @@
*
*/
+#include <tuple>
+
#include "DeviceData.h"
#include "error_category.h"
diff --git a/src/libhidpp/hidpp/Dispatcher.h b/src/libhidpp/hidpp/Dispatcher.h
index 4b251df..cf8b0ee 100644
--- a/src/libhidpp/hidpp/Dispatcher.h
+++ b/src/libhidpp/hidpp/Dispatcher.h
@@ -23,6 +23,7 @@
#include <memory>
#include <map>
#include <functional>
+#include <string>
namespace HIDPP
{
diff --git a/src/libhidpp/hidpp/Report.h b/src/libhidpp/hidpp/Report.h
index d78b1a5..c5098bf 100644
--- a/src/libhidpp/hidpp/Report.h
+++ b/src/libhidpp/hidpp/Report.h
@@ -91,6 +91,8 @@ public:
*/
static constexpr std::size_t MaxDataLength = 19;
+ Report () = default;
+
/**
* Build the report by copying the raw data.
*
diff --git a/src/libhidpp/hidpp10/defs.h b/src/libhidpp/hidpp10/defs.h
index 6629bf6..e6241e1 100644
--- a/src/libhidpp/hidpp10/defs.h
+++ b/src/libhidpp/hidpp10/defs.h
@@ -19,6 +19,7 @@
#ifndef LIBHIDPP_HIDPP10_DEFS_H
#define LIBHIDPP_HIDPP10_DEFS_H
+#include <cstddef>
#include <cstdint>
namespace HIDPP10
diff --git a/src/libhidpp/misc/Log.cpp b/src/libhidpp/misc/Log.cpp
index 7974254..30a63e1 100644
--- a/src/libhidpp/misc/Log.cpp
+++ b/src/libhidpp/misc/Log.cpp
@@ -64,6 +64,7 @@ Log::Category Log::Debug ("debug");
std::mutex Log::_mutex;
Log::Log ():
+ std::ostream (nullptr),
_buf ("null")
{
}
diff --git a/src/libhidpp/misc/Log.h b/src/libhidpp/misc/Log.h
index 664e71c..fdf6201 100644
--- a/src/libhidpp/misc/Log.h
+++ b/src/libhidpp/misc/Log.h
@@ -102,7 +102,10 @@ public:
static inline Log debug (const char *sub = nullptr) { return log (&Debug, sub); }
void printf (const char *format, ...)
- __attribute__ ((format (printf, 2, 3)));
+#ifdef __GNUC__
+ __attribute__ ((format (printf, 2, 3)))
+#endif
+ ;
template <class InputIterator>
void printBytes (const std::string &prefix,
diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt
index b7c09d0..d108b3a 100644
--- a/src/tools/CMakeLists.txt
+++ b/src/tools/CMakeLists.txt
@@ -3,32 +3,33 @@ project(hidpp_tools)
include_directories(../libhidpp)
-add_library(common OBJECT
- common/common.cpp
- common/Option.cpp
- common/CommonOptions.cpp)
+#add_library(common OBJECT
+ #common/common.cpp
+ #common/Option.cpp
+ #common/CommonOptions.cpp
+#)
-add_executable(hidpp-check-device
- hidpp-check-device.cpp
- $<TARGET_OBJECTS:common>)
-target_link_libraries(hidpp-check-device hidpp ${CMAKE_THREAD_LIBS_INIT})
-install(TARGETS hidpp-check-device RUNTIME DESTINATION bin)
+#add_executable(hidpp-check-device
+# hidpp-check-device.cpp
+# $<TARGET_OBJECTS:common>)
+#target_link_libraries(hidpp-check-device hidpp ${CMAKE_THREAD_LIBS_INIT})
+#install(TARGETS hidpp-check-device RUNTIME DESTINATION bin)
set(TOOLS
hidpp-list-devices
- hidpp-list-features
- hidpp-mouse-resolution
- hidpp10-dump-page
- hidpp10-write-page
- hidpp10-raw-command
- hidpp10-active-profile
- hidpp20-call-function
- hidpp20-onboard-profiles-get-description
- hidpp20-reprog-controls
- hidpp20-led-control
- hidpp20-dump-page
- hidpp20-write-page
- hidpp20-write-data
+ #hidpp-list-features
+ #hidpp-mouse-resolution
+ #hidpp10-dump-page
+ #hidpp10-write-page
+ #hidpp10-raw-command
+ #hidpp10-active-profile
+ #hidpp20-call-function
+ #hidpp20-onboard-profiles-get-description
+ #hidpp20-reprog-controls
+ #hidpp20-led-control
+ #hidpp20-dump-page
+ #hidpp20-write-page
+ #hidpp20-write-data
)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(TOOLS ${TOOLS}
@@ -40,7 +41,8 @@ endif()
foreach(TOOL_NAME ${TOOLS})
add_executable(${TOOL_NAME}
${TOOL_NAME}.cpp
- $<TARGET_OBJECTS:common>)
+# $<TARGET_OBJECTS:common>
+ )
target_link_libraries(${TOOL_NAME}
hidpp
${CMAKE_THREAD_LIBS_INIT}
@@ -60,7 +62,8 @@ if(TINYXML2_FOUND)
add_executable(${TOOL_NAME}
${TOOL_NAME}.cpp
$<TARGET_OBJECTS:profile>
- $<TARGET_OBJECTS:common>)
+# $<TARGET_OBJECTS:common>
+ )
target_include_directories(${TOOL_NAME}
PUBLIC ${TINYXML2_INCLUDE_DIRECTORIES})
target_link_libraries(${TOOL_NAME}
diff --git a/src/tools/hidpp-list-devices.cpp b/src/tools/hidpp-list-devices.cpp
index 2447f5d..85e8285 100644
--- a/src/tools/hidpp-list-devices.cpp
+++ b/src/tools/hidpp-list-devices.cpp
@@ -26,9 +26,9 @@
#include <hidpp10/Error.h>
#include <hidpp20/Error.h>
-#include "common/common.h"
-#include "common/Option.h"
-#include "common/CommonOptions.h"
+//#include "common/common.h"
+//#include "common/Option.h"
+//#include "common/CommonOptions.h"
class DevicePrinter: public HID::DeviceMonitor
{
@@ -94,6 +94,7 @@ protected:
int main (int argc, char *argv[])
{
+#if 0
std::vector<Option> options = {
VerboseOption (),
};
@@ -108,6 +109,7 @@ int main (int argc, char *argv[])
fprintf (stderr, "%s", getUsage (argv[0], "", &options).c_str ());
return EXIT_FAILURE;
}
+#endif
(DevicePrinter ()).enumerate ();
from hidpp.
I don't remember why I used pkg-config. Maybe cmake scripts were missing at the time I wrote it, but they seem to work now.
About getopt, isn't it possible to find a getopt implementation that works with msvc? Or do I need to find another option parser library?
from hidpp.
Getopt does exist for Windows, I even remember using gengetopt years ago. I just haven't looked around yet for a clean replacement. For when I do: Do you prefer something in-tree or an external dependency? This came out near the top of a web search: https://github.com/snsinfu/cxx-getopt
I also have a side-branch where I started replacing the Linux file I/O code with POSIX but it'll need a bit of cleanup and, especially, testing. Some of the more obscure utilities I won't be able to test myself, so I'm counting on your help for that.
Are you okay with delaying this until after #12 is resolved? It saves us a bit of branch juggling.
from hidpp.
I'm trying to build with MSVC, and there is an issue with std::promise not supporting types that are not default constructible. The bug was reported a few years ago but
We’ve investigated this issue and found that fixing it will break our ABI. To preserve binary compatibility, we don’t allow ABI breakages within the current release of the library. So we’ve fixed it in our ABI breaking branch.
However, at this point we don’t have a concrete timeline for when the ABI breaking release will happen.
I guess it is not happening soon. A workaround may be needed.
from hidpp.
Related Issues (19)
- Hidpp list features explanation HOT 16
- Some HID++ devices not recognized HOT 24
- How to specify the hid device index? HOT 4
- Error while asking receiver for infos: Unknown device HOT 7
- macOS support HOT 71
- hidpp-list-features crashes with g700s HOT 8
- compile errors with gcc 11.2.1 HOT 2
- non-connected devices give error HOT 5
- turning on debug logging HOT 1
- Minor compiler warnings under Linux HOT 1
- How can I get the device_path on Windows HOT 1
- Issue compiling on gentoo HOT 8
- Request for help implementing HID protocol in BrailleTouch project
- Report's answer comes as INTERRUPT, not as SET_REPORT response HOT 1
- Can't get it to build HOT 4
- Unifying receiver stops working after a short while with Thunderbolt dock HOT 4
- Device fails when writing a profile with <=2 dpi modes and DPI index <=2 HOT 4
- Duplicated buttons info with hidpp-persistent-profiles HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hidpp.