diff --git a/CMakeLists.txt b/CMakeLists.txt index a102e138..cd716e35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY) # do not inherit include directories from the parent project SET_PROPERTY(DIRECTORY PROPERTY INCLUDE_DIRECTORIES) FOREACH(V WITH_MYSQLCOMPAT WITH_MSI WITH_SIGNCODE WITH_RTC WITH_UNIT_TESTS - WITH_DYNCOL WITH_EXTERNAL_ZLIB WITH_CURL WITH_SQLITE WITH_SSL + WITH_DYNCOL WITH_EXTERNAL_ZLIB WITH_CURL WITH_SQLITE WITH_SSL WITH_ICONV INSTALL_LAYOUT WITH_TEST_SRCPKG) SET(${V} ${${OPT}${V}}) ENDFOREACH() @@ -57,6 +57,7 @@ ELSE() ADD_OPTION(WITH_MSI "Build MSI installation package" OFF) ADD_OPTION(WITH_SIGNCODE "digitally sign files" OFF) ADD_OPTION(WITH_RTC "enables run time checks for debug builds" OFF) + ADD_OPTION(WITH_ICONV "enables character set conversion" OFF) ENDIF() ADD_OPTION(WITH_UNIT_TESTS "build test suite" ON) @@ -343,8 +344,10 @@ ELSEIF (NOT ENABLED_LOCAL_INFILE MATCHES "^(ON|OFF|AUTO)$") MESSAGE(FATAL_ERROR "ENABLED_LOCAL_INFILE must be one of OFF, ON, AUTO") ENDIF() -IF(NOT WIN32) - INCLUDE(${CC_SOURCE_DIR}/cmake/FindIconv.cmake) +IF(WITH_ICONV) + IF(NOT WIN32) + INCLUDE(${CC_SOURCE_DIR}/cmake/FindIconv.cmake) + ENDIF() ENDIF() CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake index ea0e5f33..dbc7369b 100644 --- a/cmake/FindIconv.cmake +++ b/cmake/FindIconv.cmake @@ -58,6 +58,7 @@ if (ICONV_FOUND) return 0; } " ICONV_SECOND_ARGUMENT_IS_CONST ) + ADD_DEFINITIONS(-DHAVE_ICONV) endif (ICONV_FOUND) set (CMAKE_REQUIRED_INCLUDES) diff --git a/libmariadb/ma_charset.c b/libmariadb/ma_charset.c index d2bca7c7..51146289 100644 --- a/libmariadb/ma_charset.c +++ b/libmariadb/ma_charset.c @@ -53,11 +53,13 @@ #include #include +#ifdef HAVE_ICONV #ifdef _WIN32 #include "../win-iconv/iconv.h" #else #include #endif +#endif #if defined(HAVE_NL_LANGINFO) && defined(HAVE_SETLOCALE) @@ -1385,7 +1387,7 @@ int madb_get_windows_cp(const char *charset) #endif /* }}} */ - +#ifdef HAVE_ICONV /* {{{ map_charset_name Changing charset name into something iconv understands, if necessary. Another purpose it to avoid BOMs in result string, adding BE if necessary @@ -1413,6 +1415,7 @@ static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffe } } /* }}} */ +#endif /* {{{ mariadb_convert_string Converts string from one charset to another, and writes converted string to given buffer @@ -1426,9 +1429,17 @@ static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffe @return -1 in case of error, bytes used in the "to" buffer, otherwise */ -size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, MARIADB_CHARSET_INFO *from_cs, - char *to, size_t *to_len, MARIADB_CHARSET_INFO *to_cs, int *errorcode) +size_t STDCALL mariadb_convert_string(const char *from __attribute__((unused)), + size_t *from_len __attribute__((unused)), + MARIADB_CHARSET_INFO *from_cs __attribute__((unused)), + char *to __attribute__((unused)), + size_t *to_len __attribute__((unused)), + MARIADB_CHARSET_INFO *to_cs __attribute__((unused)), int *errorcode) { +#ifndef HAVE_ICONV + *errorcode= ENOTSUP; + return -1; +#else iconv_t conv= 0; size_t rc= -1; size_t save_len= *to_len; @@ -1462,6 +1473,7 @@ error: if (conv != (iconv_t)-1) iconv_close(conv); return rc; +#endif } /* }}} */ diff --git a/unittest/libmariadb/charset.c b/unittest/libmariadb/charset.c index 969991e0..38b85c97 100644 --- a/unittest/libmariadb/charset.c +++ b/unittest/libmariadb/charset.c @@ -661,6 +661,10 @@ static int test_bug_54100(MYSQL *mysql) static int test_utf16_utf32_noboms(MYSQL *mysql __attribute__((unused))) { +#ifndef HAVE_ICONV + diag("MariaDB Connector/C was built without iconv support"); + return SKIP; +#else const char *csname[]= {"utf16", "utf16le", "utf32", "utf8"}; MARIADB_CHARSET_INFO *csinfo[sizeof(csname)/sizeof(char*)]; @@ -724,6 +728,7 @@ static int test_utf16_utf32_noboms(MYSQL *mysql __attribute__((unused))) } return OK; +#endif } static int charset_auto(MYSQL *my __attribute__((unused)))