Skip to content

Commit

Permalink
BUILD: Make dependency on libxml2 optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ccawley2011 authored and DrMcCoy committed Jan 12, 2019
1 parent 823ae96 commit 0a7fb73
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 9 deletions.
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ option(ENABLE_FAAD "Enable building with AAC support" ON)
option(ENABLE_XVIDCORE "Enable building with H.263 support" ON)
option(ENABLE_VPX "Enable building with VP8/VP9 support" ON)
option(ENABLE_LZMA "Enable building with LZMA support" ON)
option(ENABLE_XML "Enable building with XML support" ON)


# -------------------------------------------------------------------------
Expand Down Expand Up @@ -342,9 +343,16 @@ if(ENABLE_LZMA)
endif()
endif()

find_package(LibXml2 REQUIRED)
include_directories(${LIBXML2_INCLUDE_DIR})
list(APPEND XOREOS_LIBRARIES ${LIBXML2_LIBRARIES})
if(ENABLE_XML)
find_package(LibXml2)
if(LIBXML2_FOUND)
add_definitions(-DENABLE_XML)
include_directories(${LIBXML2_INCLUDE_DIR})
list(APPEND XOREOS_LIBRARIES ${LIBXML2_LIBRARIES})
else()
set(ENABLE_XML OFF)
endif()
endif()

find_package(Iconv REQUIRED)
include_directories(${ICONV_INCLUDE_DIR})
Expand Down Expand Up @@ -558,3 +566,4 @@ message(STATUS " libfaad: ${ENABLE_FAAD}")
message(STATUS " xvidcore: ${ENABLE_XVIDCORE}")
message(STATUS " libvpx: ${ENABLE_VPX}")
message(STATUS " liblzma: ${ENABLE_LZMA}")
message(STATUS " libxml2: ${ENABLE_XML}")
18 changes: 15 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ AC_ARG_ENABLE([faad], [AS_HELP_STRING([--disable-faad], [Disable building with A
AC_ARG_ENABLE([xvidcore], [AS_HELP_STRING([--disable-xvidcore], [Disable building with H.263 support @<:@default=no@:>@])], [], [enable_xvidcore=yes])
AC_ARG_ENABLE([vpx], [AS_HELP_STRING([--disable-vpx], [Disabling building with VP8/VP9 support @<:@default=no@:>@])], [], [enable_vpx=yes])
AC_ARG_ENABLE([lzma], [AS_HELP_STRING([--disable-lzma], [Disable building with LZMA support @<:@default=no@:>@])], [], [enable_lzma=yes])
AC_ARG_ENABLE([xml], [AS_HELP_STRING([--disable-xml], [Disable building with XML support @<:@default=no@:>@])], [], [enable_xml=yes])

dnl General purpose libraries
AX_CHECK_ICONV( , AC_MSG_ERROR([No useable iconv() function found!]))
AX_CHECK_ZLIB(1, 2, 3, 0, , AC_MSG_ERROR([zlib(>= 1.2.3) is required and could not be found!]))
AX_CHECK_XML2(2, 8, 0, , AC_MSG_ERROR([libxml2(>= 2.8.0) is required and could not be found!]))
if test "x$enable_lzma" = "xyes"; then
AX_CHECK_LZMA(5, 0, 3, 2, , [enable_lzma=no])
fi
Expand All @@ -209,6 +209,17 @@ else
LZMA_CFLAGS=""
LZMA_LIBS=""
fi
if test "x$enable_xml" = "xyes"; then
AX_CHECK_XML2(2, 8, 0, , [enable_xml=no])
fi
if test "x$enable_xml" = "xyes"; then
AC_DEFINE([ENABLE_XML], 1, [Defined to 1 if we are using libxml2])
AM_CONDITIONAL(ENABLE_XML, true)
else
AM_CONDITIONAL(ENABLE_XML, false)
XML2_CFLAGS=""
XML2_LIBS=""
fi

dnl Use Wincrypt instead of BCrypt in Boost.Uuid
AC_ARG_WITH([boost-uuid-wincrypt], [AS_HELP_STRING([--with-boost-uuid-wincrypt], [Make Boost.Uuid use Wincrypt instead of BCrypt on Windows @<:@default=no@:>@])], [], [with_boost_uuid_wincrypt=no])
Expand Down Expand Up @@ -351,8 +362,8 @@ AX_ADD_ENGINE([kotor2], [KOTOR2], [Star Wars: Knights of the Old Republic II: Th
AX_ADD_ENGINE([jade], [JADE], [Jade Empire], [])
AX_ADD_ENGINE([witcher], [WITCHER], [The Witcher], [])
AX_ADD_ENGINE([sonic], [SONIC], [Sonic Chronicles: The Dark Brotherhood], [])
AX_ADD_ENGINE([dragonage], [DRAGONAGE], [Dragon Age: Origins], [libxml2])
AX_ADD_ENGINE([dragonage2], [DRAGONAGE2], [Dragon Age II], [libxml2])
AX_ADD_ENGINE([dragonage], [DRAGONAGE], [Dragon Age: Origins], [xml])
AX_ADD_ENGINE([dragonage2], [DRAGONAGE2], [Dragon Age II], [xml])

dnl Extra flags
case "$target" in
Expand Down Expand Up @@ -394,3 +405,4 @@ AC_MSG_NOTICE([ libfaad: $enable_faad])
AC_MSG_NOTICE([ xvidcore: $enable_xvidcore])
AC_MSG_NOTICE([ libvpx: $enable_vpx])
AC_MSG_NOTICE([ liblzma: $enable_lzma])
AC_MSG_NOTICE([ libxml2: $enable_xml])
6 changes: 6 additions & 0 deletions src/aurora/textureatlasfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
* A loader class for texture atlas XML files for Dragon Age: Origins and Dragon Age 2.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef ENABLE_XML
#include "src/common/ustring.h"
#include "src/common/readstream.h"
#include "src/common/xml.h"
Expand Down Expand Up @@ -109,3 +114,4 @@ void TextureAtlasFile::load(Common::SeekableReadStream &stream) {
}

} // End of namespace Aurora
#endif
6 changes: 6 additions & 0 deletions src/common/xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
* XML parsing helpers, using libxml2.
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef ENABLE_XML
#include <cstdarg>
#include <cstdio>

Expand Down Expand Up @@ -178,3 +183,4 @@ void XMLNode::load(_xmlNode &node, bool makeLower) {
}

} // End of namespace Common
#endif
17 changes: 14 additions & 3 deletions src/graphics/aurora/model_dragonage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
#include "src/common/readstream.h"
#include "src/common/encoding.h"
#include "src/common/filepath.h"
#ifdef ENABLE_XML
#include "src/common/xml.h"
#endif

#include "src/aurora/util.h"
#include "src/aurora/resman.h"
Expand All @@ -58,8 +60,10 @@ namespace Graphics {

namespace Aurora {

#ifdef ENABLE_XML
using Common::XMLParser;
using Common::XMLNode;
#endif

// .--- GFF4 helpers
static const uint32 kMMHID = MKTAG('M', 'M', 'H', ' ');
Expand Down Expand Up @@ -772,6 +776,7 @@ void ModelNode_DragonAge::readMAOGFF(Common::SeekableReadStream *maoStream, Mate
}
}

#ifdef ENABLE_XML
/** Read a MAO encoded in an XML file. */
void ModelNode_DragonAge::readMAOXML(Common::SeekableReadStream *maoStream, MaterialObject &material,
const Common::UString &fileName) {
Expand Down Expand Up @@ -821,6 +826,7 @@ void ModelNode_DragonAge::readMAOXML(Common::SeekableReadStream *maoStream, Mate

delete maoStream;
}
#endif

/** Read a material object MAO, which can be encoded in either XML or GFF. */
void ModelNode_DragonAge::readMAO(const Common::UString &materialName, MaterialObject &material) {
Expand All @@ -833,11 +839,16 @@ void ModelNode_DragonAge::readMAO(const Common::UString &materialName, MaterialO
const uint32 tag = ::Aurora::AuroraFile::readHeaderID(*maoStream);
maoStream->seek(0);

if (tag == kGFFID)
if (tag == kGFFID) {
readMAOGFF(maoStream, material);
else if (tag == kXMLID)
} else if (tag == kXMLID) {
#ifdef ENABLE_XML
readMAOXML(maoStream, material, TypeMan.setFileType(materialName, kFileTypeMAO));
else {
#else
delete maoStream;
throw Common::Exception("XML parsing disabled when building without libxml2");
#endif
} else {
delete maoStream;
throw Common::Exception("Invalid MAO type %s", Common::debugTag(tag).c_str());
}
Expand Down
6 changes: 6 additions & 0 deletions src/xoreos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
#include "src/common/threads.h"
#include "src/common/debugman.h"
#include "src/common/configman.h"
#ifdef ENABLE_XML
#include "src/common/xml.h"
#endif

#include "src/aurora/resman.h"
#include "src/aurora/2dareg.h"
Expand Down Expand Up @@ -285,8 +287,10 @@ static void init() {
// Init threading system
Common::initThreads();

#ifdef ENABLE_XML
// Init libxml2
Common::initXML();
#endif

// Init subsystems
GfxMan.init();
Expand All @@ -308,8 +312,10 @@ static void deinit() {
} catch (...) {
}

#ifdef ENABLE_XML
// Deinit libxml2
Common::deinitXML();
#endif

// Destroy global singletons
Graphics::Aurora::FontManager::destroy();
Expand Down
2 changes: 2 additions & 0 deletions tests/aurora/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ tests_aurora_test_ltrfile_SOURCES = tests/aurora/ltrfile.cpp
tests_aurora_test_ltrfile_LDADD = $(aurora_LIBS)
tests_aurora_test_ltrfile_CXXFLAGS = $(test_CXXFLAGS)

if ENABLE_XML
check_PROGRAMS += tests/aurora/test_textureatlasfile
tests_aurora_test_textureatlasfile_SOURCES = tests/aurora/textureatlasfile.cpp
tests_aurora_test_textureatlasfile_LDADD = $(aurora_LIBS)
tests_aurora_test_textureatlasfile_CXXFLAGS = $(test_CXXFLAGS)
endif

check_PROGRAMS += tests/aurora/test_actionscript
tests_aurora_test_actionscript_SOURCES = tests/aurora/actionscript.cpp
Expand Down
2 changes: 2 additions & 0 deletions tests/common/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ tests_common_test_lzma_LDADD = $(common_LIBS)
tests_common_test_lzma_CXXFLAGS = $(test_CXXFLAGS)
endif

if ENABLE_XML
check_PROGRAMS += tests/common/test_xml
tests_common_test_xml_SOURCES = tests/common/xml.cpp
tests_common_test_xml_LDADD = $(common_LIBS)
tests_common_test_xml_CXXFLAGS = $(test_CXXFLAGS)
endif

check_PROGRAMS += tests/common/test_streamtokenizer
tests_common_test_streamtokenizer_SOURCES = tests/common/streamtokenizer.cpp
Expand Down

0 comments on commit 0a7fb73

Please sign in to comment.