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

MSVC compatibility #19

Merged
merged 15 commits into from
Aug 25, 2021
Merged

MSVC compatibility #19

merged 15 commits into from
Aug 25, 2021

Conversation

cvuchener
Copy link
Owner

fix #5

still missing import/export symbol for shared library and getopt configuration

I can build using vcpkg's getopt but it does not have a cmake find_package script. I am using the following changes:

diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt
index 262d63e..bd2ec17 100644
--- a/src/tools/CMakeLists.txt
+++ b/src/tools/CMakeLists.txt
@@ -1,12 +1,19 @@
 cmake_minimum_required(VERSION 3.12)
 project(hidpp_tools)

+add_library(getopt SHARED IMPORTED)
+set_target_properties(getopt PROPERTIES
+       IMPORTED_LOCATION "D:\\vcpkg\\packages\\getopt-win32_x64-windows\\bin\\getopt.dll"
+       IMPORTED_IMPLIB "D:\\vcpkg\\packages\\getopt-win32_x64-windows\\lib\\getopt.lib"
+       INTERFACE_INCLUDE_DIRECTORIES "D:\\vcpkg\\packages\\getopt-win32_x64-windows\\include")
+
 include_directories(../libhidpp)

 add_library(common OBJECT
        common/common.cpp
        common/Option.cpp
        common/CommonOptions.cpp)
+target_link_libraries(common PUBLIC getopt)

 add_executable(hidpp-check-device hidpp-check-device.cpp)
 target_link_libraries(hidpp-check-device hidpp common Threads::Threads)
diff --git a/src/tools/common/Option.cpp b/src/tools/common/Option.cpp
index ebf3ee7..73dabf0 100644
--- a/src/tools/common/Option.cpp
+++ b/src/tools/common/Option.cpp
@@ -1,11 +1,12 @@
 #include "Option.h"

+#include <sstream>
+#include <map>
+
 extern "C" {
 #include <getopt.h>
 }

-#include <sstream>
-#include <map>

 Option::Option (char short_opt,
                const char *long_opt,
@@ -67,7 +68,7 @@ bool Option::processOptions (int argc, char *argv[],
                longopt.val = 256 + i;
                longopts.push_back (longopt);
        }
-       longopts.emplace_back ((struct option) {});
+       longopts.emplace_back (struct option {});

        int opt;
        while (-1 != (opt = getopt_long (argc, argv,

I obviously cannot keep an imported target like that. For some reason including getopt before the standard library headers breaks them.

@mcuee
Copy link

mcuee commented Aug 14, 2021

Is it possible to include getopt and not to rely on vcpkg. That way you have more control and will not encounter support issues in the future.

@cvuchener
Copy link
Owner Author

I don't mind replacing getopt with another library. If I have to add a dependency, I might as well use a better parser. I looked at boost's program_options, but I don't like it. CLI11 is much better, but I'm missing a way to mimic getopt's optional arguments (mainly used for -v --verbose). I may have to change the syntax if I use it.

@mcuee
Copy link

mcuee commented Aug 20, 2021

The latest commits seems to be good, tested with VS2019 and CMake 3.20.2.

Only problem: if I enable shared dll build, the tools build will fail, something like the following.

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK1181	cannot open input file '..\libhidpp\Release\hidpp.lib'	hidpp-check-device	C:\work\hid\hidpp_msvc\build\src\tools\LINK	1	

@cvuchener
Copy link
Owner Author

I know shared library is not working.

still missing import/export symbol for shared library

You could try -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON but it is not enough, some symbols are still missing. I tried using GenerateExportHeader and exporting the missing symbols explicitly but it is breaking MSYS2's mingw builds.

@cvuchener cvuchener changed the title MSVC compatibility (WIP) MSVC compatibility Aug 25, 2021
@cvuchener
Copy link
Owner Author

I'm abandoning the support for MSVC shared library with this PR. MSVC users will have to be content with static linking for now. At least you don't have the copy the dll to compensate the lack of rpath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiling on Windows
2 participants