diff --git a/build/android/Makefile b/build/android/Makefile index 0a3c00cb9..81869814b 100644 --- a/build/android/Makefile +++ b/build/android/Makefile @@ -812,7 +812,7 @@ clean_iconv : apk: $(PATHCFGFILE) assets $(IRRLICHT_LIB) $(CURL_LIB) $(LEVELDB_TARGET) \ $(OPENAL_LIB) $(OGG_LIB) prep_srcdir $(ROOT)/jni/src/android_version.h \ - $(MSGPACK_TARGET) $(ICONV_LIB) \ + $(MSGPACK_TARGET) \ sqlite3_download @export NDEBUG=$$NDEBUG; $(MAKE) manifest; \ export PATH=$$PATH:${SDKFOLDER}/platform-tools:${ANDROID_NDK}; \ diff --git a/build/android/jni/Android.mk b/build/android/jni/Android.mk index d3ca30516..17485145e 100644 --- a/build/android/jni/Android.mk +++ b/build/android/jni/Android.mk @@ -49,10 +49,10 @@ LOCAL_MODULE := crypto LOCAL_SRC_FILES := deps/openssl/libcrypto.a include $(PREBUILT_STATIC_LIBRARY) -include $(CLEAR_VARS) -LOCAL_MODULE := iconv -LOCAL_SRC_FILES := deps/libiconv/lib/.libs/libiconv.a -include $(PREBUILT_STATIC_LIBRARY) +#include $(CLEAR_VARS) +#LOCAL_MODULE := iconv +#LOCAL_SRC_FILES := deps/libiconv/lib/.libs/libiconv.a +#include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := msgpack @@ -105,7 +105,6 @@ endif LOCAL_C_INCLUDES := \ jni/src/enet/include \ deps/msgpack/include \ - deps/libiconv/include \ deps/msgpack/src \ jni/src jni/src/sqlite \ jni/src/script \ @@ -119,9 +118,10 @@ LOCAL_C_INCLUDES := \ deps/libvorbis-libogg-android/jni/include \ deps/leveldb/include \ deps/sqlite/ +# deps/libiconv/include \ + LOCAL_SRC_FILES := \ - jni/src/util/utf8.cpp \ jni/src/gsmapper.cpp \ jni/src/guiTextInputMenu.cpp \ jni/src/FMColoredString.cpp \ @@ -367,8 +367,8 @@ LOCAL_SRC_FILES += \ jni/src/enet/protocol.c \ jni/src/enet/unix.c -LOCAL_STATIC_LIBRARIES += iconv msgpack - +LOCAL_STATIC_LIBRARIES += msgpack +# iconv ifeq ($(HAVE_LEVELDB), 1) LOCAL_STATIC_LIBRARIES += LevelDB diff --git a/cmake/Modules/FindIconv.cmake b/cmake/Modules/FindIconv.cmake new file mode 100644 index 000000000..a2fa9963b --- /dev/null +++ b/cmake/Modules/FindIconv.cmake @@ -0,0 +1,16 @@ +mark_as_advanced(ICONV_INCLUDE_DIR ICONV_LIBRARY) +find_path(ICONV_INCLUDE_DIR iconv.h) + +if(APPLE) + find_library(ICONV_LIBRARY + NAMES libiconv.dylib + PATHS "/usr/lib" + DOC "IConv library") +endif(APPLE) + +if(${CMAKE_SYSTEM_NAME} MATCHES "BSD") + FIND_LIBRARY(ICONV_LIBRARY NAMES iconv) +endif() + +#include(FindPackageHandleStandardArgs) +#find_package_handle_standard_args(iconv DEFAULT_MSG ICONV_INCLUDE_DIR) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index df2064aa2..c9ba0877f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -231,6 +231,14 @@ else() mark_as_advanced(CLEAR CURL_LIBRARY CURL_INCLUDE_DIR) endif() +find_package(Iconv) +if(ICONV_INCLUDE_DIR) +set(USE_ICONV 1) +message(STATUS "iconv.h found: ${ICONV_INCLUDE_DIR}") +else() +set(USE_ICONV 0) +message(STATUS "iconv.h NOT found") +endif() if(BUILD_CLIENT) OPTION(ENABLE_GETTEXT "Use GetText for internationalization" TRUE) @@ -255,7 +263,6 @@ else() message(STATUS "GetText disabled.") endif() - if(BUILD_CLIENT) option(ENABLE_SOUND "Enable sound" TRUE) else() diff --git a/src/cmake_config.h.in b/src/cmake_config.h.in index b7d4af1d0..29cc28790 100644 --- a/src/cmake_config.h.in +++ b/src/cmake_config.h.in @@ -32,6 +32,7 @@ #cmakedefine01 ENABLE_THREADS #cmakedefine01 MINETEST_PROTO #cmakedefine01 STATIC_BUILD +#cmakedefine01 USE_ICONV #endif diff --git a/src/util/string.cpp b/src/util/string.cpp index 94848fbaf..738b7ec35 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -34,13 +34,34 @@ along with Freeminer. If not, see . #include "../config.h" -#ifndef _WIN32 -#include -#else -#include -#endif +#if defined(_WIN32) + +#include + +std::wstring narrow_to_wide(const std::string &input) { + size_t outbuf_size = input.size() + 1; + wchar_t *outbuf = new wchar_t[outbuf_size]; + memset(outbuf, 0, outbuf_size * sizeof(wchar_t)); + MultiByteToWideChar(CP_UTF8, 0, input.c_str(), input.size(), outbuf, outbuf_size); + std::wstring out(outbuf); + delete[] outbuf; + return out; +} + +std::string wide_to_narrow(const std::wstring &input) { + size_t outbuf_size = (input.size() + 1) * 6; + char *outbuf = new char[outbuf_size]; + memset(outbuf, 0, outbuf_size); + WideCharToMultiByte(CP_UTF8, 0, input.c_str(), input.size(), outbuf, outbuf_size, NULL, NULL); + std::string out(outbuf); + delete[] outbuf; + return out; +} + +#elif USE_ICONV + +#include -#ifndef _WIN32 size_t convert(const char *to, const char *from, char *outbuf, size_t outbuf_size, char *inbuf, size_t inbuf_size) { iconv_t cd = iconv_open(to, from); @@ -57,7 +78,6 @@ size_t convert(const char *to, const char *from, char *outbuf, size_t outbuf_siz return 0; } -#ifndef __ANDROID__ std::wstring narrow_to_wide(const std::string &input) { size_t inbuf_size = input.length() + 1; // maximum possible size, every character is sizeof(wchar_t) bytes @@ -95,13 +115,16 @@ std::string wide_to_narrow(const std::wstring &input) { return out; } + #else +#include "utf8.cpp" + std::wstring narrow_to_wide(const std::string &input) { size_t outbuf_size = input.size() + 1; wchar_t *outbuf = new wchar_t[outbuf_size]; memset(outbuf, 0, outbuf_size * sizeof(wchar_t)); - irr::core::utf8ToWchar(input.c_str(), outbuf, outbuf_size * sizeof(wchar_t)); + /* irr::core:: */ utf8ToWchar(input.c_str(), outbuf, outbuf_size * sizeof(wchar_t)); std::wstring out(outbuf); delete[] outbuf; return out; @@ -114,34 +137,13 @@ std::string wide_to_narrow(const std::wstring &input) { size_t inbuf_size = (input.length() + 1); wchar_t *inbuf = new wchar_t[inbuf_size]; memcpy(inbuf, input.c_str(), inbuf_size * sizeof(wchar_t)); - irr::core::wcharToUtf8(inbuf, outbuf, outbuf_size); + /* irr::core:: */ wcharToUtf8(inbuf, outbuf, outbuf_size); std::string out(outbuf); delete[] outbuf; delete[] inbuf; return out; } -#endif -#else -std::wstring narrow_to_wide(const std::string &input) { - size_t outbuf_size = input.size() + 1; - wchar_t *outbuf = new wchar_t[outbuf_size]; - memset(outbuf, 0, outbuf_size * sizeof(wchar_t)); - MultiByteToWideChar(CP_UTF8, 0, input.c_str(), input.size(), outbuf, outbuf_size); - std::wstring out(outbuf); - delete[] outbuf; - return out; -} - -std::string wide_to_narrow(const std::wstring &input) { - size_t outbuf_size = (input.size() + 1) * 6; - char *outbuf = new char[outbuf_size]; - memset(outbuf, 0, outbuf_size); - WideCharToMultiByte(CP_UTF8, 0, input.c_str(), input.size(), outbuf, outbuf_size, NULL, NULL); - std::string out(outbuf); - delete[] outbuf; - return out; -} #endif #include diff --git a/src/util/utf8.cpp b/src/util/utf8.cpp index 184e0be39..41db56d02 100644 --- a/src/util/utf8.cpp +++ b/src/util/utf8.cpp @@ -13,13 +13,14 @@ now used only for android // This file is part of the "Irrlicht Engine". The UTF-8 functions are from physfs, // under the zlib license, reproduced below. -#include "irrTypes.h" -#include "irrString.h" +//#include +//#include +#include "../irrlichttypes.h" -namespace irr -{ -namespace core -{ +//namespace irr +//{ +//namespace core +//{ /* Copyright (c) 2001-2011 Ryan C. Gordon and others. @@ -386,6 +387,6 @@ void wcharToUtf8(const wchar_t *in, char *out, const u64 len) #endif } -} // end namespace core -} // end namespace irr +//} // end namespace core +//} // end namespace irr