Browse Source

Attempt to fix nanodbc library build using VS2015.
Disable URHO3D_DATABASE_ODBC build option when MSVC compiler version is less than 14.0 (VS2015).
[skip travis]

Yao Wei Tjong 姚伟忠 9 years ago
parent
commit
ce434a5057

+ 1 - 1
CMake/Modules/Urho3D-CMake-common.cmake

@@ -175,7 +175,7 @@ if (CMAKE_PROJECT_NAME STREQUAL Urho3D)
     option (URHO3D_DOCS "Generate documentation as part of normal build")
     option (URHO3D_DOCS "Generate documentation as part of normal build")
     option (URHO3D_DOCS_QUIET "Generate documentation as part of normal build, suppress generation process from sending anything to stdout")
     option (URHO3D_DOCS_QUIET "Generate documentation as part of normal build, suppress generation process from sending anything to stdout")
     option (URHO3D_PCH "Enable PCH support" TRUE)
     option (URHO3D_PCH "Enable PCH support" TRUE)
-    cmake_dependent_option (URHO3D_DATABASE_ODBC "Enable Database support with ODBC, requires vendor-specific ODBC driver" FALSE "NOT IOS AND NOT ANDROID AND NOT WEB" FALSE)
+    cmake_dependent_option (URHO3D_DATABASE_ODBC "Enable Database support with ODBC, requires vendor-specific ODBC driver" FALSE "NOT IOS AND NOT ANDROID AND NOT WEB;NOT MSVC OR NOT COMPILER_VERSION VERSION_LESS 14.0" FALSE)
     option (URHO3D_DATABASE_SQLITE "Enable Database support with SQLite embedded")
     option (URHO3D_DATABASE_SQLITE "Enable Database support with SQLite embedded")
     cmake_dependent_option (URHO3D_MINIDUMPS "Enable minidumps on crash (VS only)" TRUE "MSVC" FALSE)
     cmake_dependent_option (URHO3D_MINIDUMPS "Enable minidumps on crash (VS only)" TRUE "MSVC" FALSE)
     option (URHO3D_FILEWATCHER "Enable filewatcher support" TRUE)
     option (URHO3D_FILEWATCHER "Enable filewatcher support" TRUE)

+ 14 - 4
Source/ThirdParty/nanodbc/src/nanodbc.cpp

@@ -211,8 +211,13 @@ namespace
             #if defined(_MSC_VER) && (_MSC_VER == 1900)
             #if defined(_MSC_VER) && (_MSC_VER == 1900)
                 // Workaround for confirmed bug in VS2015.
                 // Workaround for confirmed bug in VS2015.
                 // See: https://social.msdn.microsoft.com/Forums/en-US/8f40dcd8-c67f-4eba-9134-a19b9178e481/vs-2015-rc-linker-stdcodecvt-error
                 // See: https://social.msdn.microsoft.com/Forums/en-US/8f40dcd8-c67f-4eba-9134-a19b9178e481/vs-2015-rc-linker-stdcodecvt-error
-                auto p = reinterpret_cast<wide_char_t const*>(in.data());
-                out = std::wstring_convert<NANODBC_CODECVT_TYPE<wide_char_t>, wide_char_t>().to_bytes(p, p + in.size());
+                #ifdef NANODBC_USE_IODBC_WIDE_STRINGS
+                    auto p = reinterpret_cast<int32_t const*>(in.data());
+                    out = std::wstring_convert<NANODBC_CODECVT_TYPE<int32_t>, int32_t>().to_bytes(p, p + in.size());
+                #else
+                    auto p = reinterpret_cast<int16_t const*>(in.data());
+                    out = std::wstring_convert<NANODBC_CODECVT_TYPE<int16_t>, int16_t>().to_bytes(p, p + in.size());
+                #endif
             #else
             #else
                 out = std::wstring_convert<NANODBC_CODECVT_TYPE<wide_char_t>, wide_char_t>().to_bytes(in);
                 out = std::wstring_convert<NANODBC_CODECVT_TYPE<wide_char_t>, wide_char_t>().to_bytes(in);
             #endif
             #endif
@@ -228,8 +233,13 @@ namespace
             #elif defined(_MSC_VER) && (_MSC_VER == 1900)
             #elif defined(_MSC_VER) && (_MSC_VER == 1900)
                 // Workaround for confirmed bug in VS2015.
                 // Workaround for confirmed bug in VS2015.
                 // See: https://social.msdn.microsoft.com/Forums/en-US/8f40dcd8-c67f-4eba-9134-a19b9178e481/vs-2015-rc-linker-stdcodecvt-error
                 // See: https://social.msdn.microsoft.com/Forums/en-US/8f40dcd8-c67f-4eba-9134-a19b9178e481/vs-2015-rc-linker-stdcodecvt-error
-                auto s = std::wstring_convert<NANODBC_CODECVT_TYPE<wide_char_t>, wide_char_t>().from_bytes(in);
-                auto p = reinterpret_cast<wide_char_t const*>(s.data());
+                #ifdef NANODBC_USE_IODBC_WIDE_STRINGS
+                    auto s = std::wstring_convert<NANODBC_CODECVT_TYPE<int32_t>, int32_t>().from_bytes(in);
+                    auto p = reinterpret_cast<int32_t const*>(s.data());
+                #else
+                    auto s = std::wstring_convert<NANODBC_CODECVT_TYPE<int16_t>, int16_t>().from_bytes(in);
+                    auto p = reinterpret_cast<int16_t const*>(s.data());
+                #endif
                 out.assign(p, p + s.size());
                 out.assign(p, p + s.size());
             #else
             #else
                 out = std::wstring_convert<NANODBC_CODECVT_TYPE<wide_char_t>, wide_char_t>().from_bytes(in);
                 out = std::wstring_convert<NANODBC_CODECVT_TYPE<wide_char_t>, wide_char_t>().from_bytes(in);