@@ -22,11 +22,53 @@ target_link_libraries(hidapi_libusb PRIVATE Threads::Threads)
22
22
if (HIDAPI_NO_ICONV)
23
23
target_compile_definitions (hidapi_libusb PRIVATE NO_ICONV)
24
24
else ()
25
- if (NOT ANDROID AND NOT CMAKE_VERSION VERSION_LESS 3.11)
26
- find_package (Iconv REQUIRED)
25
+ if (NOT ANDROID)
27
26
include (CheckCSourceCompiles)
28
- target_link_libraries (hidapi_libusb PRIVATE Iconv::Iconv)
29
- set (CMAKE_REQUIRED_LIBRARIES "Iconv::Iconv" )
27
+
28
+ if (NOT CMAKE_VERSION VERSION_LESS 3.11)
29
+ message (STATUS "Check for Iconv" )
30
+ find_package (Iconv)
31
+ if (Iconv_FOUND)
32
+ if (NOT Iconv_IS_BUILT_IN)
33
+ target_link_libraries (hidapi_libusb PRIVATE Iconv::Iconv)
34
+ set (CMAKE_REQUIRED_LIBRARIES "Iconv::Iconv" )
35
+ if (NOT BUILD_SHARED_LIBS )
36
+ set (HIDAPI_NEED_EXPORT_ICONV TRUE PARENT_SCOPE)
37
+ endif ()
38
+ endif ()
39
+ else ()
40
+ message (STATUS "Iconv Explicitly check '-liconv'" )
41
+ # Sometime the build environment is not setup
42
+ # in a way CMake can find Iconv on its own by default.
43
+ # But if we simply link against iconv (-liconv), the build may succeed
44
+ # due to other compiler/link flags.
45
+ set (CMAKE_REQUIRED_LIBRARIES "iconv" )
46
+ check_c_source_compiles("
47
+ #include <stddef.h>
48
+ #include <iconv.h>
49
+ int main() {
50
+ char *a, *b;
51
+ size_t i, j;
52
+ iconv_t ic;
53
+ ic = iconv_open(\" to\" , \" from\" );
54
+ iconv(ic, &a, &i, &b, &j);
55
+ iconv_close(ic);
56
+ }
57
+ "
58
+ Iconv_EXPLICITLY_AT_ENV)
59
+ if (Iconv_EXPLICITLY_AT_ENV)
60
+ message (STATUS "Iconv Explicitly check '-liconv' - Available" )
61
+ target_link_libraries (hidapi_libusb PRIVATE iconv)
62
+ else ()
63
+ message (FATAL_ERROR "Iconv is not found, make sure to provide it in the build environment" )
64
+ endif ()
65
+ endif ()
66
+ else ()
67
+ # otherwise there is 2 options:
68
+ # 1) iconv is provided by Standard C library and the build will be just fine
69
+ # 2) The _user_ has to provide additiona compilation options for this project/target
70
+ endif ()
71
+
30
72
# check for error: "conflicting types for 'iconv'"
31
73
check_c_source_compiles("#include<iconv.h>
32
74
extern size_t iconv (iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
@@ -35,11 +77,9 @@ else()
35
77
if (HIDAPI_ICONV_CONST)
36
78
target_compile_definitions (hidapi_libusb PRIVATE "ICONV_CONST=const" )
37
79
endif ()
80
+ else ()
81
+ # On Android Iconv is disabled on the code level anyway, so no issue;
38
82
endif ()
39
- # otherwise there is 3 options:
40
- # 1) On Android Iconv is disabled on the code level anyway, so no issue;
41
- # 2) iconv is provided by Standard C library and the build will be just fine;
42
- # 4) The _user_ has to provide additiona compilation options for this project/target.
43
83
endif ()
44
84
45
85
set_target_properties (hidapi_libusb
0 commit comments