From c3bf414ad5d80a1ffcae0f19357753f0ef26a00f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 4 Nov 2017 19:25:32 +0300 Subject: Add workaround for fix compilation with tinyxml2 from master branch. In tinyxml2 was unversioned api breakage in master branch. --- configure.ac | 57 ++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 7 ++++++ src/utils/xml/tinyxml2.cpp | 7 ++++++ 3 files changed, 71 insertions(+) diff --git a/configure.ac b/configure.ac index 30a72e891..12c19328c 100755 --- a/configure.ac +++ b/configure.ac @@ -444,15 +444,72 @@ if test "$xmllib" == "pugixml"; then AC_MSG_ERROR([ *** pugixml library found but cannot find headers (http://pugixml.org/)])) fi +# hack for support unversioned api change in tinyxml2 (master branch) +tinyxml2_old=yes if test "$xmllib" == "tinyxml2"; then if test "$skip_check_lib" == "no"; then AC_CHECK_LIB([tinyxml2], [main], , AC_MSG_ERROR([ *** Unable to find tinyxml2 library (http://grinninglizard.com/tinyxml2/)])) + AC_MSG_CHECKING([whether tinyxml supports old error api]) + AC_COMPILE_IFELSE( + [AC_LANG_SOURCE([ + #ifndef GCC_VERSION + #define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + #endif // GCC_VERSION + #ifdef __clang__ + #ifndef CLANG_VERSION + #define CLANG_VERSION (__clang_major__ * 10000 \ + + __clang_minor__ * 100 \ + + __clang_patchlevel__) + #endif // CLANG_VERSION + #endif // __clang__ + #if GCC_VERSION >= 49000 + #define PRAGMA49(str) _Pragma(#str) + #else // GCC_VERSION > 49000 + #define PRAGMA49(str) + #endif // GCC_VERSION > 49000 + #if GCC_VERSION >= 40600 + #define PRAGMACLANG6GCC(str) _Pragma(#str) + #elif defined(__clang__) && CLANG_VERSION >= 30800 + #define PRAGMACLANG6GCC(str) _Pragma(#str) + #else // __clang__ + #define PRAGMACLANG6GCC(str) + #endif // __clang__ + + PRAGMA49(GCC diagnostic push) + PRAGMA49(GCC diagnostic ignored "-Wzero-as-null-pointer-constant") + PRAGMA49(GCC diagnostic ignored "-Wsuggest-override") + PRAGMACLANG6GCC(GCC diagnostic push) + PRAGMACLANG6GCC(GCC diagnostic ignored "-Wold-style-cast") + #include + PRAGMACLANG6GCC(GCC diagnostic pop) + PRAGMA49(GCC diagnostic pop) + + int main(int, char **) + { + tinyxml2::XMLDocument doc; + const char *str = doc.ErrorStr(); + return !str; + } + ])], + [ + AC_MSG_RESULT([no]) + tinyxml2_old=no + ], + [ + AC_MSG_RESULT([yes]) + tinyxml2_old=yes + ] + ) fi AC_CHECK_HEADERS([tinyxml2.h], , AC_MSG_ERROR([ *** tinyxml2 library found but cannot find headers (http://grinninglizard.com/tinyxml2/)])) fi +AM_CONDITIONAL(USE_TINYXML_OLD, test x$tinyxml2_old = xyes) + if test "$skip_check_lib" == "no"; then AC_CHECK_LIB(png, png_write_info, , AC_MSG_ERROR([ *** Unable to find png library])) diff --git a/src/Makefile.am b/src/Makefile.am index 9674e0e2b..d5a37af0f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -95,6 +95,10 @@ endif if ENABLE_TINYXML2 manaplus_CXXFLAGS += -DENABLE_TINYXML2 dyecmd_CXXFLAGS += -DENABLE_TINYXML2 +if USE_TINYXML_OLD +manaplus_CXXFLAGS += -DUSE_TINYXML_OLD +dyecmd_CXXFLAGS += -DUSE_TINYXML_OLD +endif endif if ENABLE_PORTABLE @@ -2048,6 +2052,9 @@ manaplustests_CXXFLAGS += -DENABLE_LIBXML endif if ENABLE_TINYXML2 manaplustests_CXXFLAGS += -DENABLE_TINYXML2 +if USE_TINYXML_OLD +manaplustests_CXXFLAGS += -DUSE_TINYXML_OLD +endif endif if USE_SDL2 manaplustests_CXXFLAGS += -DUSE_SDL2 diff --git a/src/utils/xml/tinyxml2.cpp b/src/utils/xml/tinyxml2.cpp index a7275b7f1..913e0e953 100644 --- a/src/utils/xml/tinyxml2.cpp +++ b/src/utils/xml/tinyxml2.cpp @@ -44,10 +44,17 @@ namespace XML { static void showErrorStatus(tinyxml2::XMLDocument &doc) { +#ifdef USE_TINYXML_OLD logger->log("xml error: %s, in lines: %s\n%s", doc.ErrorName(), doc.GetErrorStr1(), doc.GetErrorStr2()); +#else // USE_TINYXML_OLD + + logger->log("xml error: %s, in lines: %s", + doc.ErrorName(), + doc.ErrorStr()); +#endif // USE_TINYXML_OLD } Document::Document(const std::string &filename, -- cgit v1.2.3-60-g2f50