Giter VIP home page Giter VIP logo

Comments (7)

mcuee avatar mcuee commented on August 27, 2024 1

getopt for msvc from libusb project for your reference.
https://github.com/libusb/libusb/tree/master/msvc

from hidpp.

cvuchener avatar cvuchener commented on August 27, 2024

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.

mcuee avatar mcuee commented on August 27, 2024

No issues to build under MSYS2.

  350  mkdir build
  351  cd build
  352  cmake .. -G "MinGW Makefiles"
  353  mingw32-make

from hidpp.

mrubli2 avatar mrubli2 commented on August 27, 2024

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.

cvuchener avatar cvuchener commented on August 27, 2024

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.

mrubli2 avatar mrubli2 commented on August 27, 2024

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.

cvuchener avatar cvuchener commented on August 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.