Skip to content

Commit 438d065

Browse files
authored
windows: don't mark with dllexport in static build (#507)
Don't mark API functions with __declspec(dllexport) when building a static library on Windows. Enforced by CMake builds. For other builds a compile definition is available. Related: #480
1 parent eecbe74 commit 438d065

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

hidapi/hidapi.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
libusb/hidapi Team
99
10-
Copyright 2022, All Rights Reserved.
10+
Copyright 2023, All Rights Reserved.
1111
1212
At the discretion of the user of this library,
1313
this software may be licensed under the terms of the
@@ -30,10 +30,15 @@
3030
#include <wchar.h>
3131

3232
#ifdef _WIN32
33+
/* #480: this is to be refactored properly for v1.0 */
34+
#ifndef HID_API_EXPORT
3335
#define HID_API_EXPORT __declspec(dllexport)
36+
#endif
3437
#define HID_API_CALL
3538
#else
39+
#ifndef HID_API_EXPORT
3640
#define HID_API_EXPORT /**< API export macro */
41+
#endif
3742
#define HID_API_CALL /**< API call macro */
3843
#endif
3944

windows/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ target_link_libraries(hidapi_winapi
2020
PUBLIC hidapi_include
2121
)
2222

23+
if(NOT BUILD_SHARED_LIBS)
24+
target_compile_definitions(hidapi_winapi
25+
# prevent marking functions as __declspec(dllexport) for static library build
26+
# #480: this should be refactored for v1.0
27+
PUBLIC HID_API_EXPORT
28+
)
29+
endif()
30+
2331
set_target_properties(hidapi_winapi
2432
PROPERTIES
2533
EXPORT_NAME "winapi"

0 commit comments

Comments
 (0)