Skip to content

Commit

Permalink
windows: don't mark with dllexport in static build (#507)
Browse files Browse the repository at this point in the history
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: signal11#480
  • Loading branch information
Youw authored Feb 22, 2023
1 parent eecbe74 commit 438d065
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hidapi/hidapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
libusb/hidapi Team
Copyright 2022, All Rights Reserved.
Copyright 2023, All Rights Reserved.
At the discretion of the user of this library,
this software may be licensed under the terms of the
Expand All @@ -30,10 +30,15 @@
#include <wchar.h>

#ifdef _WIN32
/* #480: this is to be refactored properly for v1.0 */
#ifndef HID_API_EXPORT
#define HID_API_EXPORT __declspec(dllexport)
#endif
#define HID_API_CALL
#else
#ifndef HID_API_EXPORT
#define HID_API_EXPORT /**< API export macro */
#endif
#define HID_API_CALL /**< API call macro */
#endif

Expand Down
8 changes: 8 additions & 0 deletions windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ target_link_libraries(hidapi_winapi
PUBLIC hidapi_include
)

if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(hidapi_winapi
# prevent marking functions as __declspec(dllexport) for static library build
# #480: this should be refactored for v1.0
PUBLIC HID_API_EXPORT
)
endif()

set_target_properties(hidapi_winapi
PROPERTIES
EXPORT_NAME "winapi"
Expand Down

0 comments on commit 438d065

Please sign in to comment.